test_upload: rewrite in terms of no-network GridTestMixin, improve no_network.py...
authorBrian Warner <warner@lothar.com>
Tue, 17 Feb 2009 00:44:57 +0000 (17:44 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 17 Feb 2009 00:44:57 +0000 (17:44 -0700)
src/allmydata/test/no_network.py
src/allmydata/test/test_upload.py

index ef701dd4517a1da2d14170e90cc3efac029b0d6d..dbc361fc3b5355aa1bd571d8b57bf757d92d280d 100644 (file)
@@ -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):
index 8ed01e2c7603f2623b7f275d732d018523fde0fb..d1c7531c2cb79616c215eb309ca0e72f659df7f1 100644 (file)
@@ -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)