From: David Stainton Date: Wed, 24 Jun 2015 23:45:01 +0000 (-0700) Subject: Fix magic-folder Persistence test X-Git-Url: https://git.rkrishnan.org/specifications/install.html?a=commitdiff_plain;h=ae9c492b79472fe71a30ee15dece87e29d18b7c1;p=tahoe-lafs%2Ftahoe-lafs.git Fix magic-folder Persistence test here we teach this test to create invite join a magic-folder using the CLI... and then we go on to fix various bugs. --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 86ae9ac2..1175882c 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -499,6 +499,9 @@ class Client(node.Node, pollmixin.PollMixin): if self.get_config("magic_folder", "enabled", False, boolean=True): upload_dircap = self.get_or_create_private_config("magic_folder_dircap") + upload_dircap is not None + # XXX correcto? + #local_dir_config = self.get_config("magic_folder", "local.directory").decode("utf-8") local_dir_config = self.get_config("magic_folder", "local.directory").decode("utf-8") local_dir = abspath_expanduser_unicode(local_dir_config, base=self.basedir) @@ -510,6 +513,7 @@ class Client(node.Node, pollmixin.PollMixin): collective_dircap_path = os.path.join(self.basedir, "private", "collective_dircap") collective_dircap_path = abspath_expanduser_unicode(collective_dircap_path) collective_dircap = fileutil.read(collective_dircap_path).strip() + assert collective_dircap is not None s = magic_folder.MagicFolder(self, upload_dircap, collective_dircap, local_dir, dbfile) s.setServiceParent(self) diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index 4a7fc4ca..85cdd04f 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -105,7 +105,7 @@ class MagicFolder(service.MultiService): r = self._db.check_file(childpath) filecap = r.was_uploaded() if filecap is False: - return True + return False def _scan(self, localpath): if not os.path.isdir(localpath): @@ -136,7 +136,7 @@ class MagicFolder(service.MultiService): self._scan(childpath) elif isfile: is_uploaded = self._db_file_is_uploaded(childpath) - if not is_uploaded: + if not is_uploaded: self._append_to_deque(childpath) else: self.warn("WARNING: cannot backup special file %s" % quote_local_unicode_path(childpath)) @@ -192,7 +192,6 @@ class MagicFolder(service.MultiService): return self._upload_dirnode.add_file(name, u, overwrite=True) def _add_dir(name): - print "MEOWMEOW!" self._notifier.watch(to_filepath(path), mask=self.mask, callbacks=[self._notify], recursive=True) u = Data("", self._convergence) name += "@_" diff --git a/src/allmydata/test/test_magic_folder.py b/src/allmydata/test/test_magic_folder.py index 2eeb5290..406c865b 100644 --- a/src/allmydata/test/test_magic_folder.py +++ b/src/allmydata/test/test_magic_folder.py @@ -76,8 +76,7 @@ class MagicFolderTestMixin(CLITestMixin, GridTestMixin, ShouldFailMixin, ReallyE def _check_config(self, result): client_config = fileutil.read(os.path.join(self.get_clientdir(), "tahoe.cfg")) - print "CLIENT CONFIG", client_config - # XXX utf-8 + # XXX utf-8? ret = re.search("\[magic_folder\]\nenabled = True\nlocal.directory = %s" % (self.local_dir.encode('utf-8'),), client_config) self.failIf(ret is None) return result @@ -191,7 +190,6 @@ class MagicFolderTestMixin(CLITestMixin, GridTestMixin, ShouldFailMixin, ReallyE d.addCallback(self._create_magicfolder) def _check_move_empty_tree(res): - print "MEOW 0" self.mkdir_nonascii(empty_tree_dir) d2 = defer.Deferred() self.magicfolder.set_processed_callback(d2.callback, ignore_count=0) @@ -205,14 +203,12 @@ class MagicFolderTestMixin(CLITestMixin, GridTestMixin, ShouldFailMixin, ReallyE d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.directories_created'), 1)) def _check_move_small_tree(res): - print "MEOW 1" self.mkdir_nonascii(small_tree_dir) fileutil.write(abspath_expanduser_unicode(u"what", base=small_tree_dir), "say when") d2 = defer.Deferred() self.magicfolder.set_processed_callback(d2.callback, ignore_count=1) os.rename(small_tree_dir, new_small_tree_dir) self.notify(to_filepath(new_small_tree_dir), self.inotify.IN_MOVED_TO) - print "end of MEOW 1" return d2 d.addCallback(_check_move_small_tree) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.objects_succeeded'), 3)) @@ -221,7 +217,6 @@ class MagicFolderTestMixin(CLITestMixin, GridTestMixin, ShouldFailMixin, ReallyE d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.directories_created'), 2)) def _check_moved_tree_is_watched(res): - print "MEOW 2" d2 = defer.Deferred() self.magicfolder.set_processed_callback(d2.callback, ignore_count=0) fileutil.write(abspath_expanduser_unicode(u"another", base=new_small_tree_dir), "file") @@ -266,29 +261,33 @@ class MagicFolderTestMixin(CLITestMixin, GridTestMixin, ShouldFailMixin, ReallyE self.client = self.g.clients[0] self.stats_provider = self.client.stats_provider - d = self.client.create_dirnode() - d.addCallback(self._made_upload_dir) + d = self._create_invite_join_magic_folder() d.addCallback(self._create_magicfolder) - def create_file(val): + def create_test_file(result): d2 = defer.Deferred() - self.magicfolder.set_processed_callback(d2.callback) + self.magicfolder.set_processed_callback(d2.callback, ignore_count=0) test_file = abspath_expanduser_unicode(u"what", base=self.local_dir) fileutil.write(test_file, "meow") self.notify(to_filepath(test_file), self.inotify.IN_CLOSE_WRITE) return d2 - d.addCallback(create_file) + d.addCallback(create_test_file) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.objects_succeeded'), 1)) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.objects_queued'), 0)) - d.addCallback(self._cleanup) def _restart(ign): - self.set_up_grid() + tahoe_config_file = os.path.join(self.get_clientdir(), "tahoe.cfg") + tahoe_config = fileutil.read(tahoe_config_file) + def write_config(client_node_dir): + fileutil.write(os.path.join(client_node_dir, "tahoe.cfg"), tahoe_config) + self.set_up_grid(client_config_hooks={0: write_config}) self.client = self.g.clients[0] self.stats_provider = self.client.stats_provider + d.addCallback(self._create_magicfolder) + d.addCallback(lambda x: time.sleep(1)) + + d.addCallback(self._cleanup) d.addCallback(_restart) - d.addCallback(self._create_magicfolder) - d.addCallback(lambda ign: time.sleep(3)) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.objects_succeeded'), 0)) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.objects_queued'), 0)) d.addBoth(self._cleanup)