Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.buildout
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
6
Merge Requests
6
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.buildout
Commits
2446ce69
Commit
2446ce69
authored
Jul 06, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement networkcache simulator.
parent
f9da19cb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
src/zc/buildout/testing.py
src/zc/buildout/testing.py
+46
-0
No files found.
src/zc/buildout/testing.py
View file @
2446ce69
...
...
@@ -17,6 +17,7 @@ $Id$
"""
import
BaseHTTPServer
import
SimpleHTTPServer
import
errno
import
logging
import
os
...
...
@@ -32,6 +33,7 @@ import textwrap
import
threading
import
time
import
urllib2
import
json
import
zc.buildout.buildout
import
zc.buildout.easy_install
...
...
@@ -347,6 +349,12 @@ def buildoutSetUp(test):
os.chdir(sample)
make_buildout()
def start_nc(path):
port, thread = _start_nc(path, name=path)
url = 'http://localhost:%s/' % port
register_teardown(lambda: stop_server(url, thread))
return url
def start_server(path):
port, thread = _start_server(path, name=path)
url = 'http://localhost:%s/' % port
...
...
@@ -416,6 +424,7 @@ def buildoutSetUp(test):
sdist = sdist,
bdist_egg = bdist_egg,
start_server = start_server,
start_nc = start_nc,
buildout = os.path.join(sample, 'bin', 'buildout'),
wait_until = wait_until,
make_py = make_py
...
...
@@ -511,11 +520,37 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
if self.__server.__log:
print '%s %s %s' % (self.command, code, self.path)
class NCHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
if '__stop__' in self.path:
raise SystemExit
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_PUT(self):
path = self.translate_path(self.path)
d = os.path.dirname(path)
if not os.path.exists(d):
os.makedirs(d)
data = self.rfile.read(int(self.headers.getheader('content-length')))
try:
d = json.loads(data)
except ValueError:
pass
else:
data = json.dumps([d])
open(path, 'wb').write(data)
self.send_response(201)
def _run(tree, port):
server_address = ('localhost', port)
httpd = Server(tree, server_address, Handler)
httpd.serve_forever()
def _run_nc(tree, port):
server_address = ('localhost', port)
httpd = Server(tree, server_address, NCHandler)
httpd.serve_forever()
def get_port():
for i in range(10):
port = random.randrange(20000, 30000)
...
...
@@ -529,6 +564,17 @@ def get_port():
s.close()
raise RuntimeError, "
Can
't find port"
def _start_nc(tree, name=''):
port = get_port()
thread = threading.Thread(target=_run_nc, args=(tree, port), name=name)
thread.setDaemon(True)
thread.start()
wait(port, up=True)
return port, thread
def start_nc(tree):
return _start_nc(tree)[0]
def _start_server(tree, name=''):
port = get_port()
thread = threading.Thread(target=_run, args=(tree, port), name=name)
...
...
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