From: Brian Warner Date: Mon, 12 Oct 2009 22:45:06 +0000 (-0700) Subject: replace Client.create_empty_dirnode() with create_dirnode(), in anticipation X-Git-Tag: trac-4100~24 X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/index.php?a=commitdiff_plain;h=3ee740628ab32aae0694928a6bc3db3c8116f93b;p=tahoe-lafs%2Ftahoe-lafs.git replace Client.create_empty_dirnode() with create_dirnode(), in anticipation of adding initial_children= argument. Includes stubbed-out initial_children= support. --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 65db3540..f4e16df7 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -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) diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index a0295cca..e582ee20 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -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. """ diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index 94e64d2e..468f0fe7 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -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() diff --git a/src/allmydata/test/test_deepcheck.py b/src/allmydata/test/test_deepcheck.py index 8b2af124..e1cb3871 100644 --- a/src/allmydata/test/test_deepcheck.py +++ b/src/allmydata/test/test_deepcheck.py @@ -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 diff --git a/src/allmydata/test/test_dirnode.py b/src/allmydata/test/test_dirnode.py index d1bf2073..fcd53702 100644 --- a/src/allmydata/test/test_dirnode.py +++ b/src/allmydata/test/test_dirnode.py @@ -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 diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index b3126fef..166a72f7 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -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) diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 76c57b82..f829abaf 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -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) + "/" diff --git a/src/allmydata/web/unlinked.py b/src/allmydata/web/unlinked.py index d3ef96f6..cc316f74 100644 --- a/src/allmydata/web/unlinked.py +++ b/src/allmydata/web/unlinked.py @@ -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):