Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.libnetworkcache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
slapos.libnetworkcache
Commits
a2ee9fa6
Commit
a2ee9fa6
authored
Jul 03, 2013
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fake test server: more checks and print exceptions to stdout
parent
9658123b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
19 deletions
+18
-19
slapos/libnetworkcachetests.py
slapos/libnetworkcachetests.py
+18
-19
No files found.
slapos/libnetworkcachetests.py
View file @
a2ee9fa6
...
@@ -8,12 +8,12 @@ import os
...
@@ -8,12 +8,12 @@ import os
import
urllib2
import
urllib2
import
random
import
random
import
shutil
import
shutil
import
socket
import
ssl
import
ssl
import
subprocess
import
subprocess
import
tempfile
import
tempfile
import
threading
import
threading
import
time
import
time
import
traceback
import
unittest
import
unittest
import
slapos.libnetworkcache
import
slapos.libnetworkcache
import
slapos.signature
import
slapos.signature
...
@@ -28,6 +28,13 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
...
@@ -28,6 +28,13 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
BaseHTTPServer
.
BaseHTTPRequestHandler
.
__init__
(
BaseHTTPServer
.
BaseHTTPRequestHandler
.
__init__
(
self
,
request
,
address
,
server
)
self
,
request
,
address
,
server
)
def
handle
(
self
):
try
:
BaseHTTPServer
.
BaseHTTPRequestHandler
.
handle
(
self
)
except
Exception
:
traceback
.
print_exc
()
raise
def
do_KILL
(
self
):
def
do_KILL
(
self
):
raise
SystemExit
raise
SystemExit
...
@@ -47,26 +54,20 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
...
@@ -47,26 +54,20 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self
.
wfile
.
write
(
out
)
self
.
wfile
.
write
(
out
)
def
do_PUT
(
self
):
def
do_PUT
(
self
):
assert
'shadir'
in
self
.
path
assert
self
.
headers
.
getheader
(
'content-type'
)
==
'application/json'
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
tree
,
*
self
.
path
.
split
(
'/'
)))
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
tree
,
*
self
.
path
.
split
(
'/'
)))
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
path
)):
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
path
)):
os
.
makedirs
(
os
.
path
.
dirname
(
path
))
os
.
makedirs
(
os
.
path
.
dirname
(
path
))
data
=
self
.
rfile
.
read
(
int
(
self
.
headers
.
getheader
(
'content-length'
)))
data
=
self
.
rfile
.
read
(
int
(
self
.
headers
.
getheader
(
'content-length'
)))
cksum
=
hashlib
.
sha512
(
data
).
hexdigest
()
cksum
=
hashlib
.
sha512
(
data
).
hexdigest
()
if
'shadir'
in
path
:
d
=
json
.
loads
(
data
)
data
=
json
.
dumps
([
d
])
if
os
.
path
.
exists
(
path
):
if
os
.
path
.
exists
(
path
):
f
=
open
(
path
,
'r'
)
with
open
(
path
,
'rb'
)
as
f
:
try
:
json_data_list
=
json
.
loads
(
f
.
read
().
strip
())
file_data
=
f
.
read
()
finally
:
f
.
close
()
file_data
=
file_data
.
strip
()
json_data_list
=
json
.
loads
(
file_data
)
json_data_list
.
append
(
d
)
data
=
json
.
dumps
(
json_data_list
)
else
:
else
:
raise
ValueError
(
'shacache shall use POST'
)
json_data_list
=
[]
json_data_list
.
append
(
json
.
loads
(
data
))
data
=
json
.
dumps
(
json_data_list
)
open
(
path
,
'wb'
).
write
(
data
)
open
(
path
,
'wb'
).
write
(
data
)
self
.
send_response
(
201
)
self
.
send_response
(
201
)
...
@@ -77,14 +78,12 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
...
@@ -77,14 +78,12 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
return
return
def
do_POST
(
self
):
def
do_POST
(
self
):
assert
'shacache'
in
self
.
path
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
tree
,
*
self
.
path
.
split
(
'/'
)))
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
tree
,
*
self
.
path
.
split
(
'/'
)))
if
not
os
.
path
.
exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
os
.
makedirs
(
path
)
os
.
makedirs
(
path
)
data
=
self
.
rfile
.
read
(
int
(
self
.
headers
.
getheader
(
'content-length'
)))
data
=
self
.
rfile
.
read
(
int
(
self
.
headers
.
getheader
(
'content-length'
)))
cksum
=
hashlib
.
sha512
(
data
).
hexdigest
()
cksum
=
hashlib
.
sha512
(
data
).
hexdigest
()
if
'shadir'
in
path
:
raise
ValueError
(
'shadir shall use PUT'
)
else
:
path
=
os
.
path
.
join
(
path
,
cksum
)
path
=
os
.
path
.
join
(
path
,
cksum
)
open
(
path
,
'wb'
).
write
(
data
)
open
(
path
,
'wb'
).
write
(
data
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment