2007-03-29 21:01:28 +00:00
|
|
|
#! /usr/bin/env python
|
2007-03-09 01:12:24 +00:00
|
|
|
|
2007-09-26 01:26:54 +00:00
|
|
|
import os, shutil, sys, urllib, time, stat
|
2007-07-17 01:08:55 +00:00
|
|
|
from cStringIO import StringIO
|
2007-03-12 23:28:37 +00:00
|
|
|
from twisted.internet import defer, reactor, protocol, error
|
2007-05-25 00:34:42 +00:00
|
|
|
from twisted.application import service, internet
|
2007-09-19 03:35:27 +00:00
|
|
|
from twisted.web import client as tw_client
|
2007-04-30 16:57:52 +00:00
|
|
|
from allmydata import client, introducer_and_vdrive
|
2007-07-17 01:08:55 +00:00
|
|
|
from allmydata.scripts import create_node
|
2007-09-16 03:53:06 +00:00
|
|
|
from allmydata.util import testutil, fileutil
|
2007-05-30 00:39:39 +00:00
|
|
|
import foolscap
|
|
|
|
from foolscap import eventual
|
2007-03-12 23:28:37 +00:00
|
|
|
from twisted.python import log
|
|
|
|
|
2007-09-19 03:35:27 +00:00
|
|
|
class StallableHTTPGetterDiscarder(tw_client.HTTPPageGetter):
|
|
|
|
full_speed_ahead = False
|
|
|
|
_bytes_so_far = 0
|
|
|
|
stalled = None
|
|
|
|
def handleResponsePart(self, data):
|
|
|
|
self._bytes_so_far += len(data)
|
|
|
|
if not self.factory.do_stall:
|
|
|
|
return
|
|
|
|
if self.full_speed_ahead:
|
|
|
|
return
|
|
|
|
if self._bytes_so_far > 1e6+100:
|
|
|
|
if not self.stalled:
|
|
|
|
print "STALLING"
|
|
|
|
self.transport.pauseProducing()
|
|
|
|
self.stalled = reactor.callLater(10.0, self._resume_speed)
|
|
|
|
def _resume_speed(self):
|
|
|
|
print "RESUME SPEED"
|
|
|
|
self.stalled = None
|
|
|
|
self.full_speed_ahead = True
|
|
|
|
self.transport.resumeProducing()
|
|
|
|
def handleResponseEnd(self):
|
|
|
|
if self.stalled:
|
|
|
|
print "CANCEL"
|
|
|
|
self.stalled.cancel()
|
|
|
|
self.stalled = None
|
|
|
|
return tw_client.HTTPPageGetter.handleResponseEnd(self)
|
|
|
|
|
|
|
|
class StallableDiscardingHTTPClientFactory(tw_client.HTTPClientFactory):
|
|
|
|
protocol = StallableHTTPGetterDiscarder
|
|
|
|
|
|
|
|
def discardPage(url, stall=False, *args, **kwargs):
|
|
|
|
"""Start fetching the URL, but stall our pipe after the first 1MB.
|
|
|
|
Wait 10 seconds, then resume downloading (and discarding) everything.
|
|
|
|
"""
|
|
|
|
# adapted from twisted.web.client.getPage . We can't just wrap or
|
|
|
|
# subclass because it provides no way to override the HTTPClientFactory
|
|
|
|
# that it creates.
|
|
|
|
scheme, host, port, path = tw_client._parse(url)
|
|
|
|
factory = StallableDiscardingHTTPClientFactory(url, *args, **kwargs)
|
|
|
|
factory.do_stall = stall
|
|
|
|
assert scheme == 'http'
|
|
|
|
reactor.connectTCP(host, port, factory)
|
|
|
|
return factory.deferred
|
|
|
|
|
2007-05-30 00:39:39 +00:00
|
|
|
class SystemFramework(testutil.PollMixin):
|
2007-03-12 23:28:37 +00:00
|
|
|
numnodes = 5
|
|
|
|
|
2007-07-17 01:08:55 +00:00
|
|
|
def __init__(self, basedir, mode):
|
2007-03-12 23:28:37 +00:00
|
|
|
self.basedir = basedir = os.path.abspath(basedir)
|
|
|
|
if not basedir.startswith(os.path.abspath(".")):
|
|
|
|
raise AssertionError("safety issue: basedir must be a subdir")
|
2007-09-16 03:53:06 +00:00
|
|
|
self.testdir = testdir = os.path.join(basedir, "test")
|
|
|
|
if os.path.exists(testdir):
|
|
|
|
shutil.rmtree(testdir)
|
|
|
|
fileutil.make_dirs(testdir)
|
2007-03-12 23:28:37 +00:00
|
|
|
self.sparent = service.MultiService()
|
|
|
|
self.sparent.startService()
|
2007-05-30 00:39:39 +00:00
|
|
|
self.proc = None
|
|
|
|
self.tub = foolscap.Tub()
|
|
|
|
self.tub.setServiceParent(self.sparent)
|
2007-07-17 01:08:55 +00:00
|
|
|
self.mode = mode
|
2007-09-15 18:47:29 +00:00
|
|
|
self.failed = False
|
2007-03-12 23:28:37 +00:00
|
|
|
|
|
|
|
def run(self):
|
2007-09-26 01:26:54 +00:00
|
|
|
framelog = os.path.join(self.basedir, "driver.log")
|
|
|
|
log.startLogging(open(framelog, "a"), setStdout=False)
|
|
|
|
log.msg("CHECK_MEMORY(mode=%s) STARTING" % self.mode)
|
2007-09-16 03:53:06 +00:00
|
|
|
#logfile = open(os.path.join(self.testdir, "log"), "w")
|
2007-05-30 00:39:39 +00:00
|
|
|
#flo = log.FileLogObserver(logfile)
|
|
|
|
#log.startLoggingWithObserver(flo.emit, setStdout=False)
|
|
|
|
d = eventual.fireEventually()
|
|
|
|
d.addCallback(lambda res: self.setUp())
|
2007-09-20 19:36:27 +00:00
|
|
|
d.addCallback(lambda res: self.record_initial_memusage())
|
|
|
|
d.addCallback(lambda res: self.make_nodes())
|
|
|
|
d.addCallback(lambda res: self.wait_for_client_connected())
|
2007-05-30 00:39:39 +00:00
|
|
|
d.addCallback(lambda res: self.do_test())
|
|
|
|
d.addBoth(self.tearDown)
|
|
|
|
def _err(err):
|
2007-09-15 18:47:29 +00:00
|
|
|
self.failed = err
|
2007-05-30 00:39:39 +00:00
|
|
|
log.err(err)
|
|
|
|
print err
|
|
|
|
d.addErrback(_err)
|
2007-09-15 18:47:29 +00:00
|
|
|
def _done(res):
|
|
|
|
reactor.stop()
|
|
|
|
return res
|
|
|
|
d.addBoth(_done)
|
2007-03-12 23:28:37 +00:00
|
|
|
reactor.run()
|
2007-09-15 18:47:29 +00:00
|
|
|
if self.failed:
|
2007-09-26 01:26:54 +00:00
|
|
|
# raiseException doesn't work for CopiedFailures
|
2007-09-15 18:47:29 +00:00
|
|
|
self.failed.raiseException()
|
2007-03-12 23:28:37 +00:00
|
|
|
|
2007-05-30 00:39:39 +00:00
|
|
|
def setUp(self):
|
2007-07-17 01:08:55 +00:00
|
|
|
#print "STARTING"
|
|
|
|
self.stats = {}
|
2007-09-16 03:53:06 +00:00
|
|
|
self.statsfile = open(os.path.join(self.basedir, "stats.out"), "a")
|
2007-04-30 16:57:52 +00:00
|
|
|
d = self.make_introducer_and_vdrive()
|
2007-03-12 23:28:37 +00:00
|
|
|
def _more(res):
|
2007-05-30 00:39:39 +00:00
|
|
|
return self.start_client()
|
2007-03-12 23:28:37 +00:00
|
|
|
d.addCallback(_more)
|
2007-05-30 00:39:39 +00:00
|
|
|
def _record_control_furl(control_furl):
|
|
|
|
self.control_furl = control_furl
|
2007-07-17 01:08:55 +00:00
|
|
|
#print "OBTAINING '%s'" % (control_furl,)
|
2007-05-30 00:39:39 +00:00
|
|
|
return self.tub.getReference(self.control_furl)
|
|
|
|
d.addCallback(_record_control_furl)
|
|
|
|
def _record_control(control_rref):
|
|
|
|
self.control_rref = control_rref
|
|
|
|
d.addCallback(_record_control)
|
|
|
|
def _ready(res):
|
2007-07-17 01:08:55 +00:00
|
|
|
#print "CLIENT READY"
|
|
|
|
pass
|
2007-05-30 00:39:39 +00:00
|
|
|
d.addCallback(_ready)
|
2007-03-12 23:28:37 +00:00
|
|
|
return d
|
|
|
|
|
2007-09-20 19:36:27 +00:00
|
|
|
def record_initial_memusage(self):
|
|
|
|
print
|
|
|
|
print "Client started (no connections yet)"
|
|
|
|
d = self._print_usage()
|
|
|
|
d.addCallback(self.stash_stats, "init")
|
|
|
|
return d
|
|
|
|
|
|
|
|
def wait_for_client_connected(self):
|
|
|
|
print
|
|
|
|
print "Client connecting to other nodes.."
|
|
|
|
return self.control_rref.callRemote("wait_for_client_connections",
|
|
|
|
self.numnodes+1)
|
|
|
|
|
2007-05-30 00:39:39 +00:00
|
|
|
def tearDown(self, passthrough):
|
2007-03-12 23:28:37 +00:00
|
|
|
# the client node will shut down in a few seconds
|
2007-05-30 00:39:39 +00:00
|
|
|
#os.remove(os.path.join(self.clientdir, "suicide_prevention_hotline"))
|
2007-03-12 23:28:37 +00:00
|
|
|
log.msg("shutting down SystemTest services")
|
2007-09-26 01:47:48 +00:00
|
|
|
if os.path.exists(self.keepalive_file):
|
|
|
|
age = time.time() - os.stat(self.keepalive_file)[stat.ST_MTIME]
|
|
|
|
log.msg("keepalive file at shutdown was %ds old" % age)
|
2007-05-30 00:39:39 +00:00
|
|
|
d = defer.succeed(None)
|
|
|
|
if self.proc:
|
|
|
|
d.addCallback(lambda res: self.kill_client())
|
|
|
|
d.addCallback(lambda res: self.sparent.stopService())
|
|
|
|
d.addCallback(lambda res: eventual.flushEventualQueue())
|
2007-07-17 01:08:55 +00:00
|
|
|
def _close_statsfile(res):
|
|
|
|
self.statsfile.close()
|
|
|
|
d.addCallback(_close_statsfile)
|
2007-05-30 00:39:39 +00:00
|
|
|
d.addCallback(lambda res: passthrough)
|
2007-03-12 23:28:37 +00:00
|
|
|
return d
|
|
|
|
|
|
|
|
def add_service(self, s):
|
|
|
|
s.setServiceParent(self.sparent)
|
|
|
|
return s
|
|
|
|
|
2007-04-30 16:57:52 +00:00
|
|
|
def make_introducer_and_vdrive(self):
|
2007-09-16 03:53:06 +00:00
|
|
|
iv_basedir = os.path.join(self.testdir, "introducer_and_vdrive")
|
2007-05-25 00:34:42 +00:00
|
|
|
os.mkdir(iv_basedir)
|
|
|
|
iv = introducer_and_vdrive.IntroducerAndVdrive(basedir=iv_basedir)
|
|
|
|
self.introducer_and_vdrive = self.add_service(iv)
|
2007-04-30 16:57:52 +00:00
|
|
|
d = self.introducer_and_vdrive.when_tub_ready()
|
2007-09-20 19:36:27 +00:00
|
|
|
def _introducer_ready(res):
|
|
|
|
q = self.introducer_and_vdrive
|
|
|
|
self.introducer_furl = q.urls["introducer"]
|
|
|
|
self.vdrive_furl = q.urls["vdrive"]
|
|
|
|
d.addCallback(_introducer_ready)
|
2007-03-12 23:28:37 +00:00
|
|
|
return d
|
|
|
|
|
|
|
|
def make_nodes(self):
|
|
|
|
self.nodes = []
|
|
|
|
for i in range(self.numnodes):
|
2007-09-16 03:53:06 +00:00
|
|
|
nodedir = os.path.join(self.testdir, "node%d" % i)
|
2007-03-12 23:28:37 +00:00
|
|
|
os.mkdir(nodedir)
|
2007-03-27 23:12:11 +00:00
|
|
|
f = open(os.path.join(nodedir, "introducer.furl"), "w")
|
2007-04-30 16:57:52 +00:00
|
|
|
f.write(self.introducer_furl)
|
2007-03-27 23:12:11 +00:00
|
|
|
f.close()
|
|
|
|
f = open(os.path.join(nodedir, "vdrive.furl"), "w")
|
2007-07-17 02:34:52 +00:00
|
|
|
f.write(self.vdrive_furl)
|
2007-03-27 23:12:11 +00:00
|
|
|
f.close()
|
2007-09-19 19:59:32 +00:00
|
|
|
# the only tests for which we want the internal nodes to actually
|
|
|
|
# retain shares are the ones where somebody's going to download
|
|
|
|
# them.
|
|
|
|
if self.mode in ("download", "download-GET", "download-GET-slow"):
|
|
|
|
# retain shares
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# for these tests, we tell the storage servers to pretend to
|
|
|
|
# accept shares, but really just throw them out, since we're
|
|
|
|
# only testing upload and not download.
|
2007-07-17 01:08:55 +00:00
|
|
|
f = open(os.path.join(nodedir, "debug_no_storage"), "w")
|
|
|
|
f.write("no_storage\n")
|
|
|
|
f.close()
|
2007-09-19 19:59:32 +00:00
|
|
|
if self.mode in ("receive",):
|
|
|
|
# for this mode, the client-under-test gets all the shares,
|
|
|
|
# so our internal nodes can refuse requests
|
|
|
|
f = open(os.path.join(nodedir, "sizelimit"), "w")
|
|
|
|
f.write("0\n")
|
|
|
|
f.close()
|
2007-03-12 23:28:37 +00:00
|
|
|
c = self.add_service(client.Client(basedir=nodedir))
|
|
|
|
self.nodes.append(c)
|
|
|
|
# the peers will start running, eventually they will connect to each
|
2007-04-30 16:57:52 +00:00
|
|
|
# other and the introducer_and_vdrive
|
2007-03-12 23:28:37 +00:00
|
|
|
|
2007-03-23 05:22:00 +00:00
|
|
|
def touch_keepalive(self):
|
2007-09-26 01:26:54 +00:00
|
|
|
if os.path.exists(self.keepalive_file):
|
|
|
|
age = time.time() - os.stat(self.keepalive_file)[stat.ST_MTIME]
|
|
|
|
log.msg("touching keepalive file, was %ds old" % age)
|
2007-03-23 05:22:00 +00:00
|
|
|
f = open(self.keepalive_file, "w")
|
2007-05-25 00:34:42 +00:00
|
|
|
f.write("""\
|
|
|
|
If the node notices this file at startup, it will poll every 5 seconds and
|
|
|
|
terminate if the file is more than 10 seconds old, or if it has been deleted.
|
|
|
|
If the test harness has an internal failure and neglects to kill off the node
|
|
|
|
itself, this helps to avoid leaving processes lying around. The contents of
|
|
|
|
this file are ignored.
|
|
|
|
""")
|
2007-03-23 05:22:00 +00:00
|
|
|
f.close()
|
|
|
|
|
2007-03-12 23:28:37 +00:00
|
|
|
def start_client(self):
|
2007-05-30 00:39:39 +00:00
|
|
|
# this returns a Deferred that fires with the client's control.furl
|
2007-03-12 23:28:37 +00:00
|
|
|
log.msg("MAKING CLIENT")
|
2007-09-16 03:53:06 +00:00
|
|
|
clientdir = self.clientdir = os.path.join(self.testdir, "client")
|
2007-07-17 01:08:55 +00:00
|
|
|
quiet = StringIO()
|
|
|
|
create_node.create_client(clientdir, {}, out=quiet)
|
2007-03-12 23:28:37 +00:00
|
|
|
log.msg("DONE MAKING CLIENT")
|
2007-03-27 23:12:11 +00:00
|
|
|
f = open(os.path.join(clientdir, "introducer.furl"), "w")
|
2007-04-30 16:57:52 +00:00
|
|
|
f.write(self.introducer_furl + "\n")
|
2007-03-12 23:28:37 +00:00
|
|
|
f.close()
|
2007-05-25 00:34:42 +00:00
|
|
|
f = open(os.path.join(clientdir, "vdrive.furl"), "w")
|
2007-07-17 02:34:52 +00:00
|
|
|
f.write(self.vdrive_furl + "\n")
|
2007-05-25 00:34:42 +00:00
|
|
|
f.close()
|
2007-07-17 03:17:51 +00:00
|
|
|
f = open(os.path.join(clientdir, "webport"), "w")
|
|
|
|
# TODO: ideally we would set webport=0 and then ask the node what
|
|
|
|
# port it picked. But at the moment it is not convenient to do this,
|
|
|
|
# so we just pick a relatively unique one.
|
|
|
|
webport = max(os.getpid(), 2000)
|
|
|
|
f.write("tcp:%d:interface=127.0.0.1\n" % webport)
|
|
|
|
f.close()
|
|
|
|
self.webish_url = "http://localhost:%d" % webport
|
2007-09-19 19:59:32 +00:00
|
|
|
if self.mode in ("upload-self", "receive"):
|
|
|
|
# accept and store shares, to trigger the memory consumption bugs
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# don't accept any shares
|
|
|
|
f = open(os.path.join(clientdir, "sizelimit"), "w")
|
|
|
|
f.write("0\n")
|
2007-07-17 01:08:55 +00:00
|
|
|
f.close()
|
2007-09-19 19:59:32 +00:00
|
|
|
## also, if we do receive any shares, throw them away
|
|
|
|
#f = open(os.path.join(clientdir, "debug_no_storage"), "w")
|
|
|
|
#f.write("no_storage\n")
|
|
|
|
#f.close()
|
2007-09-19 11:14:48 +00:00
|
|
|
if self.mode == "upload-self":
|
2007-08-10 01:30:24 +00:00
|
|
|
f = open(os.path.join(clientdir, "push_to_ourselves"), "w")
|
|
|
|
f.write("push_to_ourselves\n")
|
|
|
|
f.close()
|
2007-05-25 00:34:42 +00:00
|
|
|
self.keepalive_file = os.path.join(clientdir,
|
|
|
|
"suicide_prevention_hotline")
|
2007-03-23 05:22:00 +00:00
|
|
|
# now start updating the mtime.
|
2007-05-25 00:34:42 +00:00
|
|
|
self.touch_keepalive()
|
2007-09-21 02:35:31 +00:00
|
|
|
ts = internet.TimerService(1.0, self.touch_keepalive)
|
2007-05-25 00:34:42 +00:00
|
|
|
ts.setServiceParent(self.sparent)
|
2007-03-12 23:28:37 +00:00
|
|
|
|
|
|
|
pp = ClientWatcher()
|
2007-05-30 00:39:39 +00:00
|
|
|
self.proc_done = pp.d = defer.Deferred()
|
2007-09-15 19:34:05 +00:00
|
|
|
logfile = os.path.join(self.basedir, "client.log")
|
2007-09-16 03:53:06 +00:00
|
|
|
cmd = ["twistd", "-n", "-y", "client.tac", "-l", logfile]
|
2007-03-12 23:28:37 +00:00
|
|
|
env = os.environ.copy()
|
|
|
|
self.proc = reactor.spawnProcess(pp, cmd[0], cmd, env, path=clientdir)
|
|
|
|
log.msg("CLIENT STARTED")
|
|
|
|
|
2007-05-30 00:39:39 +00:00
|
|
|
# now we wait for the client to get started. we're looking for the
|
|
|
|
# control.furl file to appear.
|
|
|
|
furl_file = os.path.join(clientdir, "control.furl")
|
|
|
|
def _check():
|
2007-09-15 18:47:29 +00:00
|
|
|
if pp.ended and pp.ended.value.status != 0:
|
|
|
|
# the twistd process ends normally (with rc=0) if the child
|
|
|
|
# is successfully launched. It ends abnormally (with rc!=0)
|
|
|
|
# if the child cannot be launched.
|
2007-09-15 03:16:57 +00:00
|
|
|
raise RuntimeError("process ended while waiting for startup")
|
2007-05-30 00:39:39 +00:00
|
|
|
return os.path.exists(furl_file)
|
|
|
|
d = self.poll(_check, 0.1)
|
|
|
|
# once it exists, wait a moment before we read from it, just in case
|
|
|
|
# it hasn't finished writing the whole thing. Ideally control.furl
|
|
|
|
# would be created in some atomic fashion, or made non-readable until
|
|
|
|
# it's ready, but I can't think of an easy way to do that, and I
|
|
|
|
# think the chances that we'll observe a half-write are pretty low.
|
|
|
|
def _stall(res):
|
|
|
|
d2 = defer.Deferred()
|
|
|
|
reactor.callLater(0.1, d2.callback, None)
|
|
|
|
return d2
|
|
|
|
d.addCallback(_stall)
|
|
|
|
def _read(res):
|
|
|
|
f = open(furl_file, "r")
|
|
|
|
furl = f.read()
|
|
|
|
return furl.strip()
|
|
|
|
d.addCallback(_read)
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
2007-03-12 23:28:37 +00:00
|
|
|
def kill_client(self):
|
2007-05-30 00:39:39 +00:00
|
|
|
# returns a Deferred that fires when the process exits. This may only
|
|
|
|
# be called once.
|
2007-03-12 23:28:37 +00:00
|
|
|
try:
|
2007-09-16 03:53:06 +00:00
|
|
|
self.proc.signalProcess("INT")
|
2007-03-12 23:28:37 +00:00
|
|
|
except error.ProcessExitedAlready:
|
|
|
|
pass
|
2007-05-30 00:39:39 +00:00
|
|
|
return self.proc_done
|
|
|
|
|
|
|
|
|
|
|
|
def create_data(self, name, size):
|
2007-09-16 03:53:06 +00:00
|
|
|
filename = os.path.join(self.testdir, name + ".data")
|
2007-05-30 00:39:39 +00:00
|
|
|
f = open(filename, "wb")
|
|
|
|
block = "a" * 8192
|
|
|
|
while size > 0:
|
|
|
|
l = min(size, 8192)
|
|
|
|
f.write(block[:l])
|
|
|
|
size -= l
|
|
|
|
return filename
|
|
|
|
|
2007-07-17 01:08:55 +00:00
|
|
|
def stash_stats(self, stats, name):
|
|
|
|
self.statsfile.write("%s %s: %d\n" % (self.mode, name, stats['VmPeak']))
|
2007-09-16 03:53:06 +00:00
|
|
|
self.statsfile.flush()
|
2007-07-17 01:08:55 +00:00
|
|
|
self.stats[name] = stats['VmPeak']
|
|
|
|
|
2007-07-17 03:17:51 +00:00
|
|
|
def POST(self, urlpath, **fields):
|
|
|
|
url = self.webish_url + urlpath
|
|
|
|
sepbase = "boogabooga"
|
|
|
|
sep = "--" + sepbase
|
|
|
|
form = []
|
|
|
|
form.append(sep)
|
|
|
|
form.append('Content-Disposition: form-data; name="_charset"')
|
|
|
|
form.append('')
|
|
|
|
form.append('UTF-8')
|
|
|
|
form.append(sep)
|
|
|
|
for name, value in fields.iteritems():
|
|
|
|
if isinstance(value, tuple):
|
|
|
|
filename, value = value
|
|
|
|
form.append('Content-Disposition: form-data; name="%s"; '
|
|
|
|
'filename="%s"' % (name, filename))
|
|
|
|
else:
|
|
|
|
form.append('Content-Disposition: form-data; name="%s"' % name)
|
|
|
|
form.append('')
|
|
|
|
form.append(value)
|
|
|
|
form.append(sep)
|
|
|
|
form[-1] += "--"
|
|
|
|
body = "\r\n".join(form) + "\r\n"
|
|
|
|
headers = {"content-type": "multipart/form-data; boundary=%s" % sepbase,
|
|
|
|
}
|
2007-09-19 03:35:27 +00:00
|
|
|
return tw_client.getPage(url, method="POST", postdata=body,
|
|
|
|
headers=headers, followRedirect=False)
|
2007-07-17 03:17:51 +00:00
|
|
|
|
2007-09-19 03:35:27 +00:00
|
|
|
def GET_discard(self, urlpath, stall):
|
2007-09-19 01:56:05 +00:00
|
|
|
url = self.webish_url + urlpath + "?filename=dummy-get.out"
|
2007-09-19 03:35:27 +00:00
|
|
|
return discardPage(url, stall)
|
2007-09-19 01:56:05 +00:00
|
|
|
|
|
|
|
def _print_usage(self, res=None):
|
|
|
|
d = self.control_rref.callRemote("get_memory_usage")
|
|
|
|
def _print(stats):
|
|
|
|
print "VmSize: %9d VmPeak: %9d" % (stats["VmSize"],
|
|
|
|
stats["VmPeak"])
|
|
|
|
return stats
|
|
|
|
d.addCallback(_print)
|
|
|
|
return d
|
|
|
|
|
|
|
|
def _do_upload(self, res, size, files, uris):
|
|
|
|
name = '%d' % size
|
|
|
|
print
|
|
|
|
print "uploading %s" % name
|
|
|
|
if self.mode in ("upload", "upload-self"):
|
|
|
|
files[name] = self.create_data(name, size)
|
|
|
|
d = self.control_rref.callRemote("upload_from_file_to_uri",
|
|
|
|
files[name])
|
|
|
|
def _done(uri):
|
|
|
|
os.remove(files[name])
|
|
|
|
del files[name]
|
|
|
|
return uri
|
|
|
|
d.addCallback(_done)
|
|
|
|
elif self.mode == "upload-POST":
|
|
|
|
data = "a" * size
|
|
|
|
url = "/vdrive/global"
|
|
|
|
d = self.POST(url, t="upload", file=("%d.data" % size, data))
|
2007-09-20 22:33:58 +00:00
|
|
|
elif self.mode in ("receive",
|
|
|
|
"download", "download-GET", "download-GET-slow"):
|
|
|
|
# mode=receive: upload the data from a local peer, so that the
|
2007-09-19 19:59:32 +00:00
|
|
|
# client-under-test receives and stores the shares
|
2007-09-20 22:33:58 +00:00
|
|
|
#
|
|
|
|
# mode=download*: upload the data from a local peer, then have
|
|
|
|
# the client-under-test download it.
|
|
|
|
#
|
|
|
|
# we need to wait until the uploading node has connected to all
|
|
|
|
# peers, since the wait_for_client_connections() above doesn't
|
|
|
|
# pay attention to our self.nodes[] and their connections.
|
2007-09-19 19:59:32 +00:00
|
|
|
files[name] = self.create_data(name, size)
|
|
|
|
u = self.nodes[0].getServiceNamed("uploader")
|
2007-09-20 22:33:58 +00:00
|
|
|
d = self.nodes[0].debug_wait_for_client_connections(self.numnodes+1)
|
|
|
|
d.addCallback(lambda res: u.upload_filename(files[name]))
|
2007-09-19 01:56:05 +00:00
|
|
|
else:
|
|
|
|
raise RuntimeError("unknown mode=%s" % self.mode)
|
|
|
|
def _complete(uri):
|
|
|
|
uris[name] = uri
|
|
|
|
print "uploaded %s" % name
|
|
|
|
d.addCallback(_complete)
|
|
|
|
return d
|
|
|
|
|
|
|
|
def _do_download(self, res, size, uris):
|
2007-09-19 03:35:27 +00:00
|
|
|
if self.mode not in ("download", "download-GET", "download-GET-slow"):
|
2007-09-19 01:56:05 +00:00
|
|
|
return
|
|
|
|
name = '%d' % size
|
2007-09-19 03:35:27 +00:00
|
|
|
print "downloading %s" % name
|
2007-09-19 01:56:05 +00:00
|
|
|
uri = uris[name]
|
2007-09-19 03:35:27 +00:00
|
|
|
|
2007-09-19 01:56:05 +00:00
|
|
|
if self.mode == "download":
|
|
|
|
d = self.control_rref.callRemote("download_from_uri_to_file",
|
|
|
|
uri, "dummy.out")
|
2007-09-19 03:35:27 +00:00
|
|
|
elif self.mode == "download-GET":
|
|
|
|
url = "/uri/%s" % uri
|
|
|
|
d = self.GET_discard(urllib.quote(url), stall=False)
|
|
|
|
elif self.mode == "download-GET-slow":
|
2007-09-19 01:56:05 +00:00
|
|
|
url = "/uri/%s" % uri
|
2007-09-19 03:35:27 +00:00
|
|
|
d = self.GET_discard(urllib.quote(url), stall=True)
|
2007-09-19 01:56:05 +00:00
|
|
|
|
2007-09-19 03:35:27 +00:00
|
|
|
def _complete(res):
|
|
|
|
print "downloaded %s" % name
|
|
|
|
return res
|
|
|
|
d.addCallback(_complete)
|
2007-09-19 01:56:05 +00:00
|
|
|
return d
|
|
|
|
|
2007-05-30 00:39:39 +00:00
|
|
|
def do_test(self):
|
2007-07-17 01:08:55 +00:00
|
|
|
#print "CLIENT STARTED"
|
|
|
|
#print "FURL", self.control_furl
|
|
|
|
#print "RREF", self.control_rref
|
|
|
|
#print
|
2007-05-30 00:39:39 +00:00
|
|
|
kB = 1000; MB = 1000*1000
|
|
|
|
files = {}
|
|
|
|
uris = {}
|
2007-09-19 01:56:05 +00:00
|
|
|
|
|
|
|
d = self._print_usage()
|
2007-07-17 03:17:51 +00:00
|
|
|
d.addCallback(self.stash_stats, "0B")
|
2007-05-30 00:39:39 +00:00
|
|
|
|
|
|
|
for i in range(10):
|
2007-09-19 01:56:05 +00:00
|
|
|
d.addCallback(self._do_upload, 10*kB+i, files, uris)
|
|
|
|
d.addCallback(self._do_download, 10*kB+i, uris)
|
|
|
|
d.addCallback(self._print_usage)
|
2007-07-17 01:08:55 +00:00
|
|
|
d.addCallback(self.stash_stats, "10kB")
|
2007-05-30 00:39:39 +00:00
|
|
|
|
2007-07-17 01:08:55 +00:00
|
|
|
for i in range(3):
|
2007-09-19 01:56:05 +00:00
|
|
|
d.addCallback(self._do_upload, 10*MB+i, files, uris)
|
|
|
|
d.addCallback(self._do_download, 10*MB+i, uris)
|
|
|
|
d.addCallback(self._print_usage)
|
2007-07-17 01:08:55 +00:00
|
|
|
d.addCallback(self.stash_stats, "10MB")
|
|
|
|
|
2007-09-19 01:56:05 +00:00
|
|
|
for i in range(1):
|
|
|
|
d.addCallback(self._do_upload, 50*MB+i, files, uris)
|
|
|
|
d.addCallback(self._do_download, 50*MB+i, uris)
|
|
|
|
d.addCallback(self._print_usage)
|
2007-08-09 08:32:52 +00:00
|
|
|
d.addCallback(self.stash_stats, "50MB")
|
2007-05-30 00:39:39 +00:00
|
|
|
|
2007-08-15 19:55:11 +00:00
|
|
|
#for i in range(1):
|
2007-09-19 01:56:05 +00:00
|
|
|
# d.addCallback(self._do_upload, 100*MB+i, files, uris)
|
|
|
|
# d.addCallback(self._do_download, 100*MB+i, uris)
|
|
|
|
# d.addCallback(self._print_usage)
|
2007-08-15 19:55:11 +00:00
|
|
|
#d.addCallback(self.stash_stats, "100MB")
|
2007-08-09 18:30:33 +00:00
|
|
|
|
2007-05-30 00:39:39 +00:00
|
|
|
#d.addCallback(self.stall)
|
|
|
|
def _done(res):
|
|
|
|
print "FINISHING"
|
|
|
|
d.addCallback(_done)
|
|
|
|
return d
|
|
|
|
|
|
|
|
def stall(self, res):
|
|
|
|
d = defer.Deferred()
|
|
|
|
reactor.callLater(5, d.callback, None)
|
|
|
|
return d
|
2007-03-12 23:28:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ClientWatcher(protocol.ProcessProtocol):
|
2007-09-15 03:16:57 +00:00
|
|
|
ended = False
|
2007-03-12 23:28:37 +00:00
|
|
|
def outReceived(self, data):
|
|
|
|
print "OUT:", data
|
|
|
|
def errReceived(self, data):
|
|
|
|
print "ERR:", data
|
2007-05-30 00:39:39 +00:00
|
|
|
def processEnded(self, reason):
|
2007-09-15 18:47:29 +00:00
|
|
|
self.ended = reason
|
2007-05-30 00:39:39 +00:00
|
|
|
self.d.callback(None)
|
2007-03-12 23:28:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2007-07-17 01:08:55 +00:00
|
|
|
mode = "upload"
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
mode = sys.argv[1]
|
2007-09-16 03:53:06 +00:00
|
|
|
# put the logfile and stats.out in _test_memory/ . These stick around.
|
|
|
|
# put the nodes and other files in _test_memory/test/ . These are
|
|
|
|
# removed each time we run.
|
2007-07-17 01:08:55 +00:00
|
|
|
sf = SystemFramework("_test_memory", mode)
|
2007-03-12 23:28:37 +00:00
|
|
|
sf.run()
|
|
|
|
|