]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Eliminate near-duplicate code in CLITestMixin.
authorDaira Hopwood <daira@jacaranda.org>
Mon, 13 Jul 2015 17:07:52 +0000 (18:07 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Mon, 20 Jul 2015 23:48:10 +0000 (00:48 +0100)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/test/test_cli.py
src/allmydata/test/test_cli_magic_folder.py

index 2bf4a086ed40213836469690f06f858f55b76a91..9cfaf6593f06cbe1a4cf687eed7e4eaaa67337f8 100644 (file)
@@ -48,28 +48,12 @@ def parse_options(basedir, command, args):
     return o
 
 class CLITestMixin(ReallyEqualMixin):
-    def do_cli_n(self, client_num, verb, *args, **kwargs):
-        """
-        do_cli_n is used to execute client CLI commands when there is more
-        than one client in the test grid... you can specify clients by number.
-        """
-        nodeargs = [
-            "--node-directory", self.get_clientdir(i=client_num),
-            ]
-        argv = nodeargs + [verb] + list(args)
-        stdin = kwargs.get("stdin", "")
-        stdout, stderr = StringIO(), StringIO()
-        d = threads.deferToThread(runner.runner, argv, run_by_human=False,
-                                  stdin=StringIO(stdin),
-                                  stdout=stdout, stderr=stderr)
-        def _done(rc):
-            return rc, stdout.getvalue(), stderr.getvalue()
-        d.addCallback(_done)
-        return d
-
     def do_cli(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(),
+            "--node-directory", self.get_clientdir(i=client_num),
             ]
         argv = nodeargs + [verb] + list(args)
         stdin = kwargs.get("stdin", "")
index c5dc368e67f24d5e88ce0114eaf23e125d3f789a..f6e9a16d4a020fcbbb010d536cd1c4e0d69ad97b 100644 (file)
@@ -17,7 +17,7 @@ from allmydata.frontends.magic_folder import MagicFolder
 class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
 
     def create_magic_folder(self, client_num):
-        d = self.do_cli_n(client_num, "magic-folder", "create", "magic")
+        d = self.do_cli("magic-folder", "create", "magic", client_num=client_num)
         def _done((rc,stdout,stderr)):
             self.failUnless(rc == 0)
             self.failUnless("Alias 'magic' created" in stdout)
@@ -29,7 +29,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
         return d
 
     def invite(self, client_num, nickname):
-        d = self.do_cli_n(client_num, "magic-folder", "invite", u"magic", nickname)
+        d = self.do_cli("magic-folder", "invite", u"magic", nickname, client_num=client_num)
         def _done((rc,stdout,stderr)):
             self.failUnless(rc == 0)
             return (rc,stdout,stderr)
@@ -38,7 +38,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
 
     def join(self, client_num, local_dir, invite_code):
         magic_readonly_cap, dmd_write_cap = invite_code.split(magic_folder_cli.INVITE_SEPERATOR)
-        d = self.do_cli_n(client_num, "magic-folder", "join", invite_code, local_dir)
+        d = self.do_cli("magic-folder", "join", invite_code, local_dir, client_num=client_num)
         def _done((rc,stdout,stderr)):
             self.failUnless(rc == 0)
             return (rc,stdout,stderr)
@@ -59,7 +59,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
         our upload directory.
         """
         collective_readonly_cap = fileutil.read(os.path.join(self.get_clientdir(i=client_num), "private/collective_dircap"))
-        d = self.do_cli_n(client_num, "ls", "--json", collective_readonly_cap)
+        d = self.do_cli("ls", "--json", collective_readonly_cap, client_num=client_num)
         def _done((rc,stdout,stderr)):
             self.failUnless(rc == 0)
             return (rc,stdout,stderr)