From: Brian Warner Date: Tue, 17 Feb 2009 00:44:57 +0000 (-0700) Subject: test_upload: rewrite in terms of no-network GridTestMixin, improve no_network.py... X-Git-Tag: allmydata-tahoe-1.4.0~208 X-Git-Url: https://git.rkrishnan.org/vdrive/%22file:/frontends/using.html?a=commitdiff_plain;h=040cb39613b40505be80e66b223ae8b17b0ddf25;p=tahoe-lafs%2Ftahoe-lafs.git test_upload: rewrite in terms of no-network GridTestMixin, improve no_network.py as necessary --- diff --git a/src/allmydata/test/no_network.py b/src/allmydata/test/no_network.py index ef701dd4..dbc361fc 100644 --- a/src/allmydata/test/no_network.py +++ b/src/allmydata/test/no_network.py @@ -131,7 +131,8 @@ class NoNetworkClient(Client): class NoNetworkGrid(service.MultiService): - def __init__(self, basedir, num_clients=1, num_servers=10): + def __init__(self, basedir, num_clients=1, num_servers=10, + client_config_hooks={}): service.MultiService.__init__(self) self.basedir = basedir fileutil.make_dirs(basedir) @@ -160,7 +161,13 @@ class NoNetworkGrid(service.MultiService): f.write("[storage]\n") f.write("enabled = false\n") f.close() - c = NoNetworkClient(clientdir) + c = None + if i in client_config_hooks: + # this hook can either modify tahoe.cfg, or return an + # entirely new Client instance + c = client_config_hooks[i](clientdir) + if not c: + c = NoNetworkClient(clientdir) c.nodeid = clientid c.short_nodeid = b32encode(clientid).lower()[:8] c._servers = self.all_servers # can be updated later @@ -187,9 +194,10 @@ class GridTestMixin: def tearDown(self): return self.s.stopService() - def set_up_grid(self): + def set_up_grid(self, client_config_hooks={}): # self.basedir must be set - self.g = NoNetworkGrid(self.basedir) + self.g = NoNetworkGrid(self.basedir, + client_config_hooks=client_config_hooks) self.g.setServiceParent(self.s) def get_clientdir(self, i=0): diff --git a/src/allmydata/test/test_upload.py b/src/allmydata/test/test_upload.py index 8ed01e2c..d1c7531c 100644 --- a/src/allmydata/test/test_upload.py +++ b/src/allmydata/test/test_upload.py @@ -13,7 +13,7 @@ from allmydata.immutable import upload from allmydata.interfaces import IFileURI, FileTooLargeError, NotEnoughSharesError from allmydata.util.assertutil import precondition from allmydata.util.deferredutil import DeferredListShouldSucceed -from common import SystemTestMixin +from no_network import GridTestMixin from common_util import ShouldFailMixin MiB = 1024*1024 @@ -593,14 +593,17 @@ class StorageIndex(unittest.TestCase): d.addCallback(_done) return d -class EncodingParameters(SystemTestMixin, unittest.TestCase): +class EncodingParameters(GridTestMixin, unittest.TestCase): def test_configure_parameters(self): self.basedir = self.mktemp() + hooks = {0: self._set_up_nodes_extra_config} + self.set_up_grid(client_config_hooks=hooks) + c0 = self.g.clients[0] + DATA = "data" * 100 u = upload.Data(DATA, convergence="") - d = self.set_up_nodes() - d.addCallback(lambda res: self.clients[0].upload(u)) - d.addCallback(lambda ur: self.clients[0].create_node_from_uri(ur.uri)) + d = c0.upload(u) + d.addCallback(lambda ur: c0.create_node_from_uri(ur.uri)) m = monitor.Monitor() d.addCallback(lambda fn: fn.check(m)) def _check(cr): @@ -610,14 +613,18 @@ class EncodingParameters(SystemTestMixin, unittest.TestCase): d.addCallback(_check) return d - def _set_up_nodes_extra_config(self): - f = open(os.path.join(self.getdir("client0"), "tahoe.cfg"), "wt") + def _set_up_nodes_extra_config(self, clientdir): + cfgfn = os.path.join(clientdir, "tahoe.cfg") + oldcfg = open(cfgfn, "r").read() + f = open(cfgfn, "wt") + f.write(oldcfg) f.write("\n") f.write("[client]\n") f.write("shares.needed = 7\n") f.write("shares.total = 12\n") f.write("\n") f.close() + return None # TODO: # upload with exactly 75 peers (shares_of_happiness)