]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
replace Client.create_empty_dirnode() with create_dirnode(), in anticipation
authorBrian Warner <warner@lothar.com>
Mon, 12 Oct 2009 22:45:06 +0000 (15:45 -0700)
committerBrian Warner <warner@lothar.com>
Mon, 12 Oct 2009 22:45:06 +0000 (15:45 -0700)
of adding initial_children= argument.

Includes stubbed-out initial_children= support.

src/allmydata/client.py
src/allmydata/interfaces.py
src/allmydata/test/test_cli.py
src/allmydata/test/test_deepcheck.py
src/allmydata/test/test_dirnode.py
src/allmydata/test/test_system.py
src/allmydata/test/test_web.py
src/allmydata/web/unlinked.py

index 65db35406b2b658e297d96232d609ef60fd5e56d..f4e16df7aa87944692442b31d025e646ea15ab29 100644 (file)
@@ -457,8 +457,12 @@ class Client(node.Node, pollmixin.PollMixin):
         # this returns synchronously.
         return self.nodemaker.create_from_cap(writecap, readcap)
 
-    def create_empty_dirnode(self):
-        return self.nodemaker.create_new_mutable_directory()
+    def create_dirnode(self, initial_children={}):
+        d = self.nodemaker.create_new_mutable_directory()
+        assert not initial_children, "not ready yet: %s" % (initial_children,)
+        if initial_children:
+            d.addCallback(lambda n: n.set_children(initial_children))
+        return d
 
     def create_mutable_file(self, contents="", keysize=None):
         return self.nodemaker.create_mutable_file(contents, keysize)
index a0295cca46be98703570d4924ba81474693d287e..e582ee20358d692f2930d4ff8467eb410b748348 100644 (file)
@@ -2003,8 +2003,12 @@ class IClient(Interface):
                  file.
         """
 
-    def create_empty_dirnode():
-        """Create a new dirnode, empty and unattached.
+    def create_dirnode(initial_children={}):
+        """Create a new unattached dirnode, possibly with initial children.
+
+        @param initial_children: dict with keys that are unicode child names,
+        and values that are (child_writecap, child_readcap, metadata) tuples.
+
         @return: a Deferred that fires with the new IDirectoryNode instance.
         """
 
index 94e64d2e5d73ce137197709cd1e4665192f0bb50..468f0fe7d16b34d5a75aa4e6bd52e779e87a5906 100644 (file)
@@ -748,7 +748,7 @@ class List(GridTestMixin, CLITestMixin, unittest.TestCase):
         self.basedir = "cli/List/list"
         self.set_up_grid()
         c0 = self.g.clients[0]
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _stash_root_and_create_file(n):
             self.rootnode = n
             self.rooturi = n.get_uri()
@@ -1317,7 +1317,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
         self.uris = {}
         self.fileurls = {}
         DATA = "data" * 100
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _stash_root_and_create_file(n):
             self.rootnode = n
             self.rooturi = n.get_uri()
@@ -1549,7 +1549,7 @@ class Stats(GridTestMixin, CLITestMixin, unittest.TestCase):
         self.set_up_grid()
         c0 = self.g.clients[0]
         self.fileurls = {}
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _stash_root(n):
             self.rootnode = n
             self.rooturi = n.get_uri()
index 8b2af1242657ec78a540108122478e647ddb8f87..e1cb38717273bfc527f24f3d5e7b0d2ea6e2a2fd 100644 (file)
@@ -214,7 +214,7 @@ class DeepCheckWebGood(DeepCheckBase, unittest.TestCase):
         #   small2
         #   loop -> root
         c0 = self.g.clients[0]
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _created_root(n):
             self.root = n
             self.root_uri = n.get_uri()
@@ -868,7 +868,7 @@ class DeepCheckWebBad(DeepCheckBase, unittest.TestCase):
         self.nodes = {}
 
         c0 = self.g.clients[0]
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _created_root(n):
             self.root = n
             self.root_uri = n.get_uri()
@@ -881,7 +881,7 @@ class DeepCheckWebBad(DeepCheckBase, unittest.TestCase):
         d.addCallback(self.create_mangled, "large-missing-shares")
         d.addCallback(self.create_mangled, "large-corrupt-shares")
         d.addCallback(self.create_mangled, "large-unrecoverable")
-        d.addCallback(lambda ignored: c0.create_empty_dirnode())
+        d.addCallback(lambda ignored: c0.create_dirnode())
         d.addCallback(self._stash_node, "broken")
         large1 = upload.Data("Lots of data\n" * 1000 + "large1" + "\n", None)
         d.addCallback(lambda ignored:
@@ -1175,7 +1175,7 @@ class Large(DeepCheckBase, unittest.TestCase):
 
         COUNT = 400
         c0 = self.g.clients[0]
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         self.stash = {}
         def _created_root(n):
             self.root = n
index d1bf20732e46eef7d5833473acba7dd5b319f793..fcd53702b632173daf0f4fc67d364884a826c7ce 100644 (file)
@@ -28,7 +28,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
         self.basedir = "dirnode/Dirnode/test_basic"
         self.set_up_grid()
         c = self.g.clients[0]
-        d = c.create_empty_dirnode()
+        d = c.create_dirnode()
         def _done(res):
             self.failUnless(isinstance(res, dirnode.DirectoryNode))
             rep = str(res)
@@ -40,7 +40,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
         self.basedir = "dirnode/Dirnode/test_check"
         self.set_up_grid()
         c = self.g.clients[0]
-        d = c.create_empty_dirnode()
+        d = c.create_dirnode()
         d.addCallback(lambda dn: dn.check(Monitor()))
         def _done(res):
             self.failUnless(res.is_healthy())
@@ -55,7 +55,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
         #  root/subdir/link -> root
         #  root/rodir
         c = self.g.clients[0]
-        d = c.create_empty_dirnode()
+        d = c.create_dirnode()
         def _created_root(rootnode):
             self._rootnode = rootnode
             return rootnode.create_empty_directory(u"subdir")
@@ -64,7 +64,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
             self._subdir = subdir
             d = subdir.add_file(u"file1", upload.Data("data"*100, None))
             d.addCallback(lambda res: subdir.set_node(u"link", self._rootnode))
-            d.addCallback(lambda res: c.create_empty_dirnode())
+            d.addCallback(lambda res: c.create_dirnode())
             d.addCallback(lambda dn:
                           self._rootnode.set_uri(u"rodir",
                                                  dn.get_readonly_uri()))
@@ -157,7 +157,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
         filenode = nm.create_from_cap(filecap)
         uploadable = upload.Data("some data", convergence="some convergence string")
 
-        d = c.create_empty_dirnode()
+        d = c.create_dirnode()
         def _created(rw_dn):
             d2 = rw_dn.set_uri(u"child", filecap)
             d2.addCallback(lambda res: rw_dn)
@@ -210,7 +210,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
         self.expected_verifycaps = set()
         self.expected_storage_indexes = set()
 
-        d = c.create_empty_dirnode()
+        d = c.create_dirnode()
         def _then(n):
             # /
             self.rootnode = n
@@ -409,7 +409,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
             # set_node + metadata
             # it should be possible to add a child without any metadata
             d.addCallback(lambda res: n.set_node(u"d2", n, {}))
-            d.addCallback(lambda res: c.create_empty_dirnode())
+            d.addCallback(lambda res: c.create_dirnode())
             d.addCallback(lambda n2:
                           self.shouldFail(ExistingChildError, "set_node-no",
                                           "child 'd2' already exists",
@@ -908,7 +908,7 @@ class Deleter(GridTestMixin, unittest.TestCase):
         self.basedir = self.mktemp()
         self.set_up_grid()
         c0 = self.g.clients[0]
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         small = upload.Data("Small enough for a LIT", None)
         def _created_dir(dn):
             self.root = dn
@@ -944,7 +944,7 @@ class Adder(GridTestMixin, unittest.TestCase, testutil.ShouldFailMixin):
         c = self.g.clients[0]
         fileuri = make_chk_file_uri(1234)
         filenode = c.nodemaker.create_from_cap(fileuri)
-        d = c.create_empty_dirnode()
+        d = c.create_dirnode()
 
         def _create_directory_tree(root_node):
             # Build
index b3126fef62af87e0bf774e4887d704d66d436163..166a72f7a23e73eba7a025b7fa08207fcc69a2af 100644 (file)
@@ -683,7 +683,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
             return d1
         d.addCallback(_check_empty_file)
 
-        d.addCallback(lambda res: self.clients[0].create_empty_dirnode())
+        d.addCallback(lambda res: self.clients[0].create_dirnode())
         def _created_dirnode(dnode):
             log.msg("_created_dirnode(%s)" % (dnode,))
             d1 = dnode.list()
@@ -710,7 +710,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
         d.addCallback(check_kg_poolsize, 0)
         d.addCallback(lambda junk: self.clients[3].create_mutable_file('hello, world'))
         d.addCallback(check_kg_poolsize, -1)
-        d.addCallback(lambda junk: self.clients[3].create_empty_dirnode())
+        d.addCallback(lambda junk: self.clients[3].create_dirnode())
         d.addCallback(check_kg_poolsize, -2)
         # use_helper induces use of clients[3], which is the using-key_gen client
         d.addCallback(lambda junk: self.POST("uri", use_helper=True, t="mkdir", name='george'))
@@ -820,7 +820,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
     def _do_publish1(self, res):
         ut = upload.Data(self.data, convergence=None)
         c0 = self.clients[0]
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _made_root(new_dirnode):
             self._root_directory_uri = new_dirnode.get_uri()
             return c0.create_node_from_uri(self._root_directory_uri)
@@ -852,7 +852,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
     def _do_publish_private(self, res):
         self.smalldata = "sssh, very secret stuff"
         ut = upload.Data(self.smalldata, convergence=None)
-        d = self.clients[0].create_empty_dirnode()
+        d = self.clients[0].create_dirnode()
         d.addCallback(self.log, "GOT private directory")
         def _got_new_dir(privnode):
             rootnode = self.clients[0].create_node_from_uri(self._root_directory_uri)
index 76c57b82dcbbf6f2c87de9c58b803d59b911242a..f829abaf2d9da6aba164d06ce23985aa91229616 100644 (file)
@@ -121,7 +121,7 @@ class WebMixin(object):
         self.webish_port = port = self.ws.listener._port.getHost().port
         self.webish_url = "http://localhost:%d" % port
 
-        l = [ self.s.create_empty_dirnode() for x in range(6) ]
+        l = [ self.s.create_dirnode() for x in range(6) ]
         d = defer.DeferredList(l)
         def _then(res):
             self.public_root = res[0][1]
@@ -2247,7 +2247,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, unittest.TestCase):
         return d
 
     def test_PUT_DIRURL_uri(self):
-        d = self.s.create_empty_dirnode()
+        d = self.s.create_dirnode()
         def _made_dir(dn):
             new_uri = dn.get_uri()
             # replace /foo with a new (empty) directory
@@ -2263,7 +2263,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, unittest.TestCase):
         return d
 
     def test_PUT_DIRURL_uri_noreplace(self):
-        d = self.s.create_empty_dirnode()
+        d = self.s.create_dirnode()
         def _made_dir(dn):
             new_uri = dn.get_uri()
             # replace /foo with a new (empty) directory, but ask that
@@ -2815,7 +2815,7 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin):
                                                            safe="")
         future_node = UnknownNode(future_writecap, future_readcap)
 
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _stash_root_and_create_file(n):
             self.rootnode = n
             self.rooturl = "uri/" + urllib.quote(n.get_uri()) + "/"
@@ -2875,7 +2875,7 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin):
         self.uris = {}
         self.fileurls = {}
         DATA = "data" * 100
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _stash_root_and_create_file(n):
             self.rootnode = n
             self.fileurls["root"] = "uri/" + urllib.quote(n.get_uri()) + "/"
@@ -3048,7 +3048,7 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin):
         self.uris = {}
         self.fileurls = {}
         DATA = "data" * 100
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _stash_root_and_create_file(n):
             self.rootnode = n
             self.fileurls["root"] = "uri/" + urllib.quote(n.get_uri()) + "/"
@@ -3255,7 +3255,7 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin):
         self.uris = {}
         self.fileurls = {}
         DATA = "data" * 100
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _stash_root_and_create_file(n):
             self.rootnode = n
             self.uris["root"] = n.get_uri()
@@ -3322,7 +3322,7 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin):
         c0 = self.g.clients[0]
         self.fileurls = {}
         DATA = "data" * 100
-        d = c0.create_empty_dirnode()
+        d = c0.create_dirnode()
         def _stash_root(n):
             self.fileurls["root"] = "uri/" + urllib.quote(n.get_uri()) + "/"
             self.fileurls["imaginary"] = self.fileurls["root"] + "imaginary"
@@ -3338,14 +3338,14 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin):
             baduri = u.to_string()
             self.fileurls["0shares"] = "uri/" + urllib.quote(baduri)
         d.addCallback(_stash_bad)
-        d.addCallback(lambda ign: c0.create_empty_dirnode())
+        d.addCallback(lambda ign: c0.create_dirnode())
         def _mangle_dirnode_1share(n):
             u = n.get_uri()
             url = self.fileurls["dir-1share"] = "uri/" + urllib.quote(u) + "/"
             self.fileurls["dir-1share-json"] = url + "?t=json"
             self.delete_shares_numbered(u, range(1,10))
         d.addCallback(_mangle_dirnode_1share)
-        d.addCallback(lambda ign: c0.create_empty_dirnode())
+        d.addCallback(lambda ign: c0.create_dirnode())
         def _mangle_dirnode_0share(n):
             u = n.get_uri()
             url = self.fileurls["dir-0share"] = "uri/" + urllib.quote(u) + "/"
index d3ef96f67148db175ab77d89c325c238e7d14593..cc316f742d18dbbf2b75f34d4547ca18a2a6d8c7 100644 (file)
@@ -25,7 +25,7 @@ def PUTUnlinkedSSK(req, client):
 
 def PUTUnlinkedCreateDirectory(req, client):
     # "PUT /uri?t=mkdir", to create an unlinked directory.
-    d = client.create_empty_dirnode()
+    d = client.create_dirnode()
     d.addCallback(lambda dirnode: dirnode.get_uri())
     # XXX add redirect_to_result
     return d
@@ -90,7 +90,7 @@ def POSTUnlinkedSSK(req, client):
 
 def POSTUnlinkedCreateDirectory(req, client):
     # "POST /uri?t=mkdir", to create an unlinked directory.
-    d = client.create_empty_dirnode()
+    d = client.create_dirnode()
     redirect = get_arg(req, "redirect_to_result", "false")
     if boolean_of_arg(redirect):
         def _then_redir(res):