]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Work in progress. 2489.write_downloaded_file.1
authorDaira Hopwood <daira@jacaranda.org>
Wed, 2 Sep 2015 15:06:03 +0000 (16:06 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Wed, 2 Sep 2015 15:06:03 +0000 (16:06 +0100)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/client.py
src/allmydata/frontends/magic_folder.py
src/allmydata/test/test_cli.py
src/allmydata/test/test_cli_magic_folder.py
src/allmydata/test/test_magic_folder.py

index 77f37f00d8bade693ac98d0b6822c2fe1eb0b182..ec88c7f80724700135f05a13868c6f4a0c8611fd 100644 (file)
@@ -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.")
index c78a086304c1d5d49ce8a82709074c8753f4815e..6572e1d3b404b0ebe0a5a6b33dcd6162ba5200ba 100644 (file)
@@ -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):
index 9cfaf6593f06cbe1a4cf687eed7e4eaaa67337f8..cd6bd3c0df286a5abfd696bea3f754e349aae171 100644 (file)
@@ -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))
 
index 82960781bb7ee72a55a8188600f47aec3c90d69f..e319a41499a9a650b966f67051e2ec43b5abb788 100644 (file)
@@ -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"
index 39ecb8a39e36950c4f33097d56c9ce57fcb6d2d5..3dc7488fcf8ac68140e0e01fd7a4881260f43c71 100644 (file)
@@ -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