From: David Stainton Date: Wed, 24 Jun 2015 21:22:34 +0000 (-0700) Subject: Teach magic-folder tests to use CLI for creating magic folder config X-Git-Url: https://git.rkrishnan.org/specifications/%5B/%5D%20/flags/status?a=commitdiff_plain;h=a2ed2965e3ad65ac8cc6bc56f881f7938f303ae9;p=tahoe-lafs%2Ftahoe-lafs.git Teach magic-folder tests to use CLI for creating magic folder config --- diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index 4adfffae..4a7fc4ca 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -217,7 +217,7 @@ class MagicFolder(service.MultiService): "(this is normal for temporary objects)" % (path,)) self._stats_provider.count('magic_folder.objects_disappeared', 1) - d2 = defer.Succeed(None) + d2 = defer.succeed(None) if not self._db.check_file_db_exists(path): pass else: diff --git a/src/allmydata/scripts/magic_folder_cli.py b/src/allmydata/scripts/magic_folder_cli.py index a86e6439..b0cc8a23 100644 --- a/src/allmydata/scripts/magic_folder_cli.py +++ b/src/allmydata/scripts/magic_folder_cli.py @@ -8,6 +8,7 @@ from .common import BaseOptions, BasedirOptions, get_aliases from .cli import MakeDirectoryOptions, ListOptions, LnOptions import tahoe_ls, tahoe_mv from allmydata.util import fileutil +from allmydata.util.fileutil import abspath_expanduser_unicode INVITE_SEPERATOR = "~" @@ -155,7 +156,7 @@ def join(options): fileutil.write(dmd_cap_file, dmd_write_cap) fileutil.write(collective_readcap_file, magic_readonly_cap) - fileutil.write(os.path.join(options["node-directory"], "tahoe.cfg"), "[magic_folder]\nenabled = True\nlocal.directory = %s\n" % (options.local_dir,)) + fileutil.write(os.path.join(options["node-directory"], "tahoe.cfg"), "[magic_folder]\nenabled = True\nlocal.directory = %s\n" % (options.local_dir.encode('utf-8'),), mode="ab") return 0 class MagicFolderCommand(BaseOptions): diff --git a/src/allmydata/test/test_magic_folder.py b/src/allmydata/test/test_magic_folder.py index 9ee372dc..2eeb5290 100644 --- a/src/allmydata/test/test_magic_folder.py +++ b/src/allmydata/test/test_magic_folder.py @@ -1,5 +1,5 @@ -import os, sys, stat, time +import os, sys, stat, time, json, re from twisted.trial import unittest from twisted.internet import defer @@ -12,6 +12,7 @@ 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 import CLITestMixin from allmydata.frontends import magic_folder from allmydata.frontends.magic_folder import MagicFolder @@ -19,7 +20,7 @@ from allmydata import backupdb from allmydata.util.fileutil import abspath_expanduser_unicode -class MagicFolderTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, NonASCIIPathMixin): +class MagicFolderTestMixin(CLITestMixin, GridTestMixin, ShouldFailMixin, ReallyEqualMixin, NonASCIIPathMixin): """ These tests will be run both with a mock notifier, and (on platforms that support it) with the real INotify. @@ -42,6 +43,56 @@ class MagicFolderTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, Non self.failUnlessEqual(bdb.VERSION, 2) return bdb + def _diminish(self, write_cap): + d = self.do_cli("ls", "--json", write_cap) + def get_readonly_cap((rc,stdout,stderr)): + self.failUnless(rc == 0) + readonly_cap = json.loads(stdout)[1][u"ro_uri"] + return readonly_cap + d.addCallback(get_readonly_cap) + return d + + def _try_joined_config(self, result): + collective_readonly_cap = fileutil.read(os.path.join(self.get_clientdir(), "private/collective_dircap")) + d = self.do_cli("ls", "--json", collective_readonly_cap) + def _done((rc,stdout,stderr)): + self.failUnless(rc == 0) + return (rc,stdout,stderr) + d.addCallback(_done) + def test_joined_magic_folder((rc,stdout,stderr)): + d2 = self._diminish(self.upload_dircap) + def fail_unless_dmd_readonly_exists(readonly_cap): + s = re.search(readonly_cap, stdout) + self.failUnless(s is not None) + d2.addCallback(fail_unless_dmd_readonly_exists) + return d2 + d.addCallback(test_joined_magic_folder) + return d + + def _get_caps_from_files(self, result): + self.collective_dircap = fileutil.read(os.path.join(self.get_clientdir(), "private/collective_dircap")) + self.upload_dircap = fileutil.read(os.path.join(self.get_clientdir(), "private/magic_folder_dircap")) + self.failIf(self.collective_dircap is None or self.upload_dircap is None) + + 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 + 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 + + def _create_invite_join_magic_folder(self): + d = self.do_cli("magic-folder", "create", u"magic", u"Alice", self.local_dir) + def _done((rc,stdout,stderr)): + self.failUnless(rc == 0) + return (rc,stdout,stderr) + d.addCallback(_done) + d.addCallback(self._get_caps_from_files) + d.addCallback(self._try_joined_config) + d.addCallback(self._check_config) + return d + def _made_upload_dir(self, n): if self.dir_node == None: self.dir_node = n @@ -136,9 +187,7 @@ class MagicFolderTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, Non small_tree_dir = abspath_expanduser_unicode(small_tree_name, base=self.basedir) new_small_tree_dir = abspath_expanduser_unicode(small_tree_name, base=self.local_dir) - d = self.client.create_dirnode() - d.addCallback(self._made_upload_dir) - + d = self._create_invite_join_magic_folder() d.addCallback(self._create_magicfolder) def _check_move_empty_tree(res):