2014-09-03 01:22:59 +00:00
|
|
|
import os, shutil, sys, urllib, time, stat, urlparse
|
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
|
2008-07-16 20:14:39 +00:00
|
|
|
from allmydata import client, introducer
|
|
|
|
from allmydata.immutable import upload
|
2007-07-17 01:08:55 +00:00
|
|
|
from allmydata.scripts import create_node
|
2008-10-29 04:15:48 +00:00
|
|
|
from allmydata.util import fileutil, pollmixin
|
2010-07-22 00:14:18 +00:00
|
|
|
from allmydata.util.fileutil import abspath_expanduser_unicode
|
|
|
|
from allmydata.util.encodingutil import get_filesystem_encoding
|
2009-05-22 00:38:23 +00:00
|
|
|
from foolscap.api import Tub, fireEventually, flushEventualQueue
|
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.
|
2014-09-03 01:22:59 +00:00
|
|
|
scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
|
|
|
|
assert scheme == 'http'
|
|
|
|
host, port = netloc, 80
|
|
|
|
if ":" in host:
|
|
|
|
host, port = host.split(":")
|
|
|
|
port = int(port)
|
2007-09-19 03:35:27 +00:00
|
|
|
factory = StallableDiscardingHTTPClientFactory(url, *args, **kwargs)
|
|
|
|
factory.do_stall = stall
|
|
|
|
reactor.connectTCP(host, port, factory)
|
|
|
|
return factory.deferred
|
|
|
|
|
2009-02-23 00:28:55 +00:00
|
|
|
class ChildDidNotStartError(Exception):
|
|
|
|
pass
|
|
|
|
|
2008-10-29 04:15:48 +00:00
|
|
|
class SystemFramework(pollmixin.PollMixin):
|
2010-06-08 01:35:28 +00:00
|
|
|
numnodes = 7
|
2007-03-12 23:28:37 +00:00
|
|
|
|
2007-07-17 01:08:55 +00:00
|
|
|
def __init__(self, basedir, mode):
|
2010-07-22 00:14:18 +00:00
|
|
|
self.basedir = basedir = abspath_expanduser_unicode(unicode(basedir))
|
|
|
|
if not (basedir + os.path.sep).startswith(abspath_expanduser_unicode(u".") + os.path.sep):
|
2007-03-12 23:28:37 +00:00
|
|
|
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
|
2009-05-22 00:38:23 +00:00
|
|
|
self.tub = Tub()
|
2009-05-22 00:46:32 +00:00
|
|
|
self.tub.setOption("expose-remote-exception-types", False)
|
2007-05-30 00:39:39 +00:00
|
|
|
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-10-11 09:20:20 +00:00
|
|
|
self.keepalive_file = None
|
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)
|
2009-05-22 00:38:23 +00:00
|
|
|
d = fireEventually()
|
2007-05-30 00:39:39 +00:00
|
|
|
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-12-03 21:52:42 +00:00
|
|
|
d = self.make_introducer()
|
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
|
2014-08-17 14:36:57 +00:00
|
|
|
#os.remove(os.path.join(self.clientdir, client.Client.EXIT_TRIGGER_FILE))
|
2007-03-12 23:28:37 +00:00
|
|
|
log.msg("shutting down SystemTest services")
|
2007-10-11 09:20:20 +00:00
|
|
|
if self.keepalive_file and os.path.exists(self.keepalive_file):
|
2007-09-26 01:47:48 +00:00
|
|
|
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())
|
2009-05-22 00:38:23 +00:00
|
|
|
d.addCallback(lambda res: 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-12-03 21:52:42 +00:00
|
|
|
def make_introducer(self):
|
|
|
|
iv_basedir = os.path.join(self.testdir, "introducer")
|
2007-05-25 00:34:42 +00:00
|
|
|
os.mkdir(iv_basedir)
|
2007-12-03 21:52:42 +00:00
|
|
|
iv = introducer.IntroducerNode(basedir=iv_basedir)
|
|
|
|
self.introducer = self.add_service(iv)
|
|
|
|
d = self.introducer.when_tub_ready()
|
2007-09-20 19:36:27 +00:00
|
|
|
def _introducer_ready(res):
|
2007-12-03 21:52:42 +00:00
|
|
|
q = self.introducer
|
|
|
|
self.introducer_furl = q.introducer_url
|
2007-09-20 19:36:27 +00:00
|
|
|
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)
|
2011-08-25 20:11:16 +00:00
|
|
|
f = open(os.path.join(nodedir, "tahoe.cfg"), "w")
|
|
|
|
f.write("[client]\n"
|
|
|
|
"introducer.furl = %s\n"
|
|
|
|
"shares.happy = 1\n"
|
|
|
|
"[storage]\n"
|
|
|
|
% (self.introducer_furl,))
|
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.
|
2011-08-25 20:11:16 +00:00
|
|
|
f.write("debug_discard = true\n")
|
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
|
2011-08-25 20:11:16 +00:00
|
|
|
f.write("readonly = true\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-12-03 21:52:42 +00:00
|
|
|
# other and the introducer
|
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")
|
2010-07-22 00:14:18 +00:00
|
|
|
# self.testdir is an absolute Unicode path
|
|
|
|
clientdir = self.clientdir = os.path.join(self.testdir, u"client")
|
|
|
|
clientdir_str = clientdir.encode(get_filesystem_encoding())
|
2007-07-17 01:08:55 +00:00
|
|
|
quiet = StringIO()
|
2011-08-25 20:11:16 +00:00
|
|
|
create_node.create_node({'basedir': clientdir}, out=quiet)
|
2007-03-12 23:28:37 +00:00
|
|
|
log.msg("DONE MAKING CLIENT")
|
2011-08-25 20:11:16 +00:00
|
|
|
# now replace tahoe.cfg
|
2008-05-08 23:49:27 +00:00
|
|
|
# set webport=0 and then ask the node what port it picked.
|
2011-08-25 20:11:16 +00:00
|
|
|
f = open(os.path.join(clientdir, "tahoe.cfg"), "w")
|
|
|
|
f.write("[node]\n"
|
|
|
|
"web.port = tcp:0:interface=127.0.0.1\n"
|
|
|
|
"[client]\n"
|
|
|
|
"introducer.furl = %s\n"
|
|
|
|
"shares.happy = 1\n"
|
|
|
|
"[storage]\n"
|
|
|
|
% (self.introducer_furl,))
|
2008-05-08 23:49:27 +00:00
|
|
|
|
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
|
2011-08-25 20:11:16 +00:00
|
|
|
f.write("readonly = true\n")
|
2007-09-19 19:59:32 +00:00
|
|
|
## also, if we do receive any shares, throw them away
|
2011-08-25 20:11:16 +00:00
|
|
|
#f.write("debug_discard = true")
|
2007-09-19 11:14:48 +00:00
|
|
|
if self.mode == "upload-self":
|
2008-02-05 21:16:01 +00:00
|
|
|
pass
|
2011-08-25 20:11:16 +00:00
|
|
|
f.close()
|
2007-05-25 00:34:42 +00:00
|
|
|
self.keepalive_file = os.path.join(clientdir,
|
2014-08-17 14:36:57 +00:00
|
|
|
client.Client.EXIT_TRIGGER_FILE)
|
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-10-11 09:48:06 +00:00
|
|
|
cmd = ["twistd", "-n", "-y", "tahoe-client.tac", "-l", logfile]
|
2007-03-12 23:28:37 +00:00
|
|
|
env = os.environ.copy()
|
2010-07-22 00:14:18 +00:00
|
|
|
self.proc = reactor.spawnProcess(pp, cmd[0], cmd, env, path=clientdir_str)
|
2007-03-12 23:28:37 +00:00
|
|
|
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.
|
2007-12-17 23:39:54 +00:00
|
|
|
furl_file = os.path.join(clientdir, "private", "control.furl")
|
2008-05-08 23:49:27 +00:00
|
|
|
url_file = os.path.join(clientdir, "node.url")
|
2007-05-30 00:39:39 +00:00
|
|
|
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.
|
2009-02-23 00:28:55 +00:00
|
|
|
raise ChildDidNotStartError("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):
|
2008-05-08 23:49:27 +00:00
|
|
|
# read the node's URL
|
|
|
|
self.webish_url = open(url_file, "r").read().strip()
|
2008-05-09 01:01:31 +00:00
|
|
|
if self.webish_url[-1] == "/":
|
|
|
|
# trim trailing slash, since the rest of the code wants it gone
|
|
|
|
self.webish_url = self.webish_url[:-1]
|
2007-05-30 00:39:39 +00:00
|
|
|
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"):
|
2015-04-21 20:04:47 +00:00
|
|
|
d = self.control_rref.callRemote("upload_random_data_from_file",
|
|
|
|
size,
|
2011-08-25 20:11:16 +00:00
|
|
|
convergence="check-memory")
|
2007-09-19 01:56:05 +00:00
|
|
|
elif self.mode == "upload-POST":
|
|
|
|
data = "a" * size
|
2007-12-07 00:28:23 +00:00
|
|
|
url = "/uri"
|
2007-09-19 01:56:05 +00:00
|
|
|
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)
|
2011-08-25 20:11:16 +00:00
|
|
|
d.addCallback(lambda res:
|
|
|
|
u.upload(upload.FileName(files[name],
|
|
|
|
convergence="check-memory")))
|
2012-05-22 15:50:36 +00:00
|
|
|
d.addCallback(lambda results: results.get_uri())
|
2007-09-19 01:56:05 +00:00
|
|
|
else:
|
2009-02-23 00:28:55 +00:00
|
|
|
raise ValueError("unknown mode=%s" % self.mode)
|
2007-09-19 01:56:05 +00:00
|
|
|
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":
|
2015-04-21 20:04:47 +00:00
|
|
|
d = self.control_rref.callRemote("download_to_tempfile_and_delete",
|
|
|
|
uri)
|
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]
|
2015-03-20 01:59:16 +00:00
|
|
|
if sys.maxint == 2147483647:
|
|
|
|
bits = "32"
|
|
|
|
elif sys.maxint == 9223372036854775807:
|
|
|
|
bits = "64"
|
|
|
|
else:
|
|
|
|
bits = "?"
|
|
|
|
print "%s-bit system (sys.maxint=%d)" % (bits, sys.maxint)
|
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()
|
|
|
|
|