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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Ophélie Gagnard
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
Hide 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
import
urllib2
import
random
import
shutil
import
socket
import
ssl
import
subprocess
import
tempfile
import
threading
import
time
import
traceback
import
unittest
import
slapos.libnetworkcache
import
slapos.signature
...
...
@@ -28,6 +28,13 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
BaseHTTPServer
.
BaseHTTPRequestHandler
.
__init__
(
self
,
request
,
address
,
server
)
def
handle
(
self
):
try
:
BaseHTTPServer
.
BaseHTTPRequestHandler
.
handle
(
self
)
except
Exception
:
traceback
.
print_exc
()
raise
def
do_KILL
(
self
):
raise
SystemExit
...
...
@@ -47,26 +54,20 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self
.
wfile
.
write
(
out
)
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
(
'/'
)))
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
path
)):
os
.
makedirs
(
os
.
path
.
dirname
(
path
))
data
=
self
.
rfile
.
read
(
int
(
self
.
headers
.
getheader
(
'content-length'
)))
cksum
=
hashlib
.
sha512
(
data
).
hexdigest
()
if
'shadir'
in
path
:
d
=
json
.
loads
(
data
)
data
=
json
.
dumps
([
d
])
if
os
.
path
.
exists
(
path
):
f
=
open
(
path
,
'r'
)
try
:
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
)
if
os
.
path
.
exists
(
path
):
with
open
(
path
,
'rb'
)
as
f
:
json_data_list
=
json
.
loads
(
f
.
read
().
strip
())
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
)
self
.
send_response
(
201
)
...
...
@@ -77,15 +78,13 @@ class NCHandler(BaseHTTPServer.BaseHTTPRequestHandler):
return
def
do_POST
(
self
):
assert
'shacache'
in
self
.
path
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
tree
,
*
self
.
path
.
split
(
'/'
)))
if
not
os
.
path
.
exists
(
path
):
os
.
makedirs
(
path
)
data
=
self
.
rfile
.
read
(
int
(
self
.
headers
.
getheader
(
'content-length'
)))
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
)
self
.
send_response
(
201
)
...
...
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