From: Daira Hopwood Date: Wed, 2 Sep 2015 15:06:03 +0000 (+0100) Subject: Work in progress. X-Git-Url: https://git.rkrishnan.org/reliability?a=commitdiff_plain;h=f5643636f473b66089dfb472ddbaafc7cf5b99a5;p=tahoe-lafs%2Ftahoe-lafs.git Work in progress. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 77f37f00..ec88c7f8 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -129,6 +129,7 @@ class Client(node.Node, pollmixin.PollMixin): } def __init__(self, basedir="."): + print "Client.__init__(%r)" % (basedir,) node.Node.__init__(self, basedir) self.connected_enough_d = defer.Deferred() self.started_timestamp = time.time() @@ -493,6 +494,7 @@ class Client(node.Node, pollmixin.PollMixin): s.setServiceParent(self) def init_magic_folder(self): + print "init_magic_folder" if self.get_config("drop_upload", "enabled", False, boolean=True): raise OldConfigOptionError("The [drop_upload] section must be renamed to [magic_folder].\n" "See docs/frontends/magic-folder.rst for more information.") diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index c78a0863..6572e1d3 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -95,7 +95,7 @@ class QueueMixin(HookMixin): self._local_path = to_filepath(local_path_u) self._db = db self._name = name - self._hooks = {'processed': None} + self._hooks = {'processed': None, 'started': None} if not self._local_path.exists(): raise AssertionError("The '[magic_folder] local.directory' parameter was %s " @@ -184,6 +184,7 @@ class Uploader(QueueMixin): def start_monitoring(self): d = self._notifier.startReading() self._count('dirs_monitored') + d.addBoth(self._call_hook, 'started') return d def stop(self): diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index 9cfaf659..cd6bd3c0 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -66,6 +66,21 @@ class CLITestMixin(ReallyEqualMixin): d.addCallback(_done) return d + def do_cli_synchronously(self, verb, *args, **kwargs): + # client_num is used to execute client CLI commands on a specific client. + client_num = kwargs.get("client_num", 0) + + nodeargs = [ + "--node-directory", self.get_clientdir(i=client_num), + ] + argv = nodeargs + [verb] + list(args) + stdin = kwargs.get("stdin", "") + stdout, stderr = StringIO(), StringIO() + rc = runner.runner(argv, run_by_human=False, + stdin=StringIO(stdin), + stdout=stdout, stderr=stderr) + return rc, stdout.getvalue(), stderr.getvalue() + def skip_if_cannot_represent_filename(self, u): precondition(isinstance(u, unicode)) diff --git a/src/allmydata/test/test_cli_magic_folder.py b/src/allmydata/test/test_cli_magic_folder.py index 82960781..e319a414 100644 --- a/src/allmydata/test/test_cli_magic_folder.py +++ b/src/allmydata/test/test_cli_magic_folder.py @@ -14,7 +14,7 @@ from allmydata.frontends.magic_folder import MagicFolder from allmydata import uri -class MagicFolderTestMixin(CLITestMixin, GridTestMixin): +class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin): def do_create_magic_folder(self, client_num): d = self.do_cli("magic-folder", "create", "magic:", client_num=client_num) @@ -77,21 +77,16 @@ class MagicFolderTestMixin(CLITestMixin, GridTestMixin): self.failIf(ret is None) def create_invite_join_magic_folder(self, nickname, local_dir): - d = self.do_cli("magic-folder", "create", u"magic:", nickname, local_dir) - def _done((rc,stdout,stderr)): - self.failUnless(rc == 0) - return (rc,stdout,stderr) - d.addCallback(_done) - def get_alice_caps(x): - self.collective_dircap, self.upload_dircap = self.get_caps_from_files(0) - self.collective_dirnode = self.client.create_node_from_uri(self.collective_dircap) - self.upload_dirnode = self.client.create_node_from_uri(self.upload_dircap) - d.addCallback(get_alice_caps) - d.addCallback(lambda x: self.check_joined_config(0, self.upload_dircap)) - d.addCallback(lambda x: self.check_config(0, local_dir)) - return d + rc, stdout, stderr = self.do_cli_synchronously("magic-folder", "create", u"magic:", nickname, local_dir) + self.failUnless(rc == 0) + self.collective_dircap, self.upload_dircap = self.get_caps_from_files(0) + self.collective_dirnode = self.client.create_node_from_uri(self.collective_dircap) + self.upload_dirnode = self.client.create_node_from_uri(self.upload_dircap) + self.check_joined_config(0, self.upload_dircap) + self.check_config(0, local_dir) def cleanup(self, res): + print "cleanup", res d = defer.succeed(None) if self.magicfolder is not None: d.addCallback(lambda ign: self.magicfolder.finish()) @@ -156,7 +151,7 @@ class MagicFolderTestMixin(CLITestMixin, GridTestMixin): return d -class CreateMagicFolder(MagicFolderTestMixin, unittest.TestCase): +class CreateMagicFolder(MagicFolderCLITestMixin, unittest.TestCase): def test_create_and_then_invite_join(self): self.basedir = "cli/MagicFolder/create-and-then-invite-join" diff --git a/src/allmydata/test/test_magic_folder.py b/src/allmydata/test/test_magic_folder.py index 39ecb8a3..3dc7488f 100644 --- a/src/allmydata/test/test_magic_folder.py +++ b/src/allmydata/test/test_magic_folder.py @@ -12,16 +12,15 @@ from allmydata.util.consumer import download_to_data from allmydata.test.no_network import GridTestMixin from allmydata.test.common_util import ReallyEqualMixin, NonASCIIPathMixin from allmydata.test.common import ShouldFailMixin -from allmydata.test.test_cli_magic_folder import MagicFolderTestMixin +from .test_cli_magic_folder import MagicFolderCLITestMixin from allmydata.frontends import magic_folder -from allmydata.frontends.magic_folder import MagicFolder -from allmydata.frontends.magic_folder import Downloader +from allmydata.frontends.magic_folder import MagicFolder, Downloader from allmydata import backupdb, magicpath from allmydata.util.fileutil import abspath_expanduser_unicode -class MagicFolderTestMixin(MagicFolderTestMixin, ShouldFailMixin, ReallyEqualMixin, NonASCIIPathMixin): +class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqualMixin, NonASCIIPathMixin): """ These tests will be run both with a mock notifier, and (on platforms that support it) with the real INotify. @@ -86,18 +85,19 @@ class MagicFolderTestMixin(MagicFolderTestMixin, ShouldFailMixin, ReallyEqualMix self.failUnless(r.was_uploaded()) def test_magicfolder_start_service(self): - self.set_up_grid() - self.local_dir = abspath_expanduser_unicode(self.unicode_or_fallback(u"l\u00F8cal_dir", u"local_dir"), base=self.basedir) self.mkdir_nonascii(self.local_dir) + def _create_invite_join(clientdir): + self.create_invite_join_magic_folder(u"Alice", self.local_dir) + return NoNetworkClient(clientdir) + self.set_up_grid(client_config_hooks={0: _create_invite_join}) + self.client = self.g.clients[0] self.stats_provider = self.client.stats_provider - d = self.create_invite_join_magic_folder(u"Alice", self.local_dir) - d.addCallback(self._create_magicfolder) - + d = self.client.magicfolder.set_hook('started') d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.dirs_monitored'), 1)) d.addBoth(self.cleanup) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.dirs_monitored'), 0)) @@ -187,6 +187,8 @@ class MagicFolderTestMixin(MagicFolderTestMixin, ShouldFailMixin, ReallyEqualMix a second time. This test is meant to test the database persistence along with the startup and shutdown code paths of the magic-folder service. """ + A = set(dir(self)) + print "A", A self.set_up_grid() self.local_dir = abspath_expanduser_unicode(u"test_persistence", base=self.basedir) self.mkdir_nonascii(self.local_dir) @@ -207,30 +209,51 @@ class MagicFolderTestMixin(MagicFolderTestMixin, ShouldFailMixin, ReallyEqualMix d.addCallback(create_test_file) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_succeeded'), 1)) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_queued'), 0)) + d.addCallback(self.cleanup) + def _print(res): + print res + d.addCallback(lambda ign: _print(self.s.services)) + d.addCallback(lambda ign: self.s.removeService(self.g)) + def _reset_s(res): + print "reset s" + self.s = None + d.addCallback(_reset_s) + d.addCallback(lambda ign: GridTestMixin.setUp(self)) def restart(ignore): - #print "restart" + print "restart" tahoe_config_file = os.path.join(self.get_clientdir(), "tahoe.cfg") tahoe_config = fileutil.read(tahoe_config_file) + print tahoe_config + self.failUnlessIn("[magic_folder]\nenabled = True", tahoe_config) d3 = defer.succeed(None) def write_config(client_node_dir): - #print "write_config" + print "write_config" fileutil.write(os.path.join(client_node_dir, "tahoe.cfg"), tahoe_config) def setup_stats(result): - #print "setup_stats" - self.client = None + print "setup_stats" + + del self.client_baseurls + del self.stats_provider + del self.g + del self.client + del self.client_webports + del self.magicfolder + C = set(dir(self)) + print "C", C + print "A - C", A - C + print "C - A", C - A self.set_up_grid(client_config_hooks={0: write_config}) self.client = self.g.clients[0] self.stats_provider = self.client.stats_provider - self.magicfolder = self.client.getServiceNamed("magic-folder") + #self.magicfolder = self.client.getServiceNamed("magic-folder") - d3.addBoth(self.cleanup) - d3.addCallback(setup_stats) + #d3.addCallback(setup_stats) #d3.addCallback(self._create_magicfolder) return d3 d.addCallback(restart) - d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_succeeded'), 0)) - d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_queued'), 0)) + #d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_succeeded'), 0)) + #d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_queued'), 0)) d.addBoth(self.cleanup) return d