replace Client.create_empty_dirnode() with create_dirnode(), in anticipation

of adding initial_children= argument.

Includes stubbed-out initial_children= support.
This commit is contained in:
Brian Warner 2009-10-12 15:45:06 -07:00
parent 576c47d61e
commit 3ee740628a
8 changed files with 44 additions and 36 deletions

View 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)

View 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.
"""

View 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()

View 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

View 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

View 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)

View 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) + "/"

View 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):