From: Brian Warner Date: Wed, 7 Nov 2007 02:10:49 +0000 (-0700) Subject: test_system.mutable: add test coverage for the 'dump-share' debug command X-Git-Url: https://git.rkrishnan.org/architecture.txt?a=commitdiff_plain;h=ddf4d23bef6a2d846bb655423709204fcfa012fa;p=tahoe-lafs%2Ftahoe-lafs.git test_system.mutable: add test coverage for the 'dump-share' debug command --- diff --git a/src/allmydata/scripts/debug.py b/src/allmydata/scripts/debug.py index 7f405f71..d899b10c 100644 --- a/src/allmydata/scripts/debug.py +++ b/src/allmydata/scripts/debug.py @@ -139,19 +139,20 @@ def dump_mutable_share(config, out, err): f.close() print >>out - print >>out, "write_enabler: %s" % idlib.b2a(WE) - print >>out, "WE for nodeid: %s" % idlib.nodeid_b2a(nodeid) - print >>out, "num_extra_leases: %d" % num_extra_leases - print >>out, "data_length: %d" % data_length + print >>out, "Mutable slot found:" + print >>out, " write_enabler: %s" % idlib.b2a(WE) + print >>out, " WE for nodeid: %s" % idlib.nodeid_b2a(nodeid) + print >>out, " num_extra_leases: %d" % num_extra_leases + print >>out, " data_length: %d" % data_length if leases: for (leasenum, (oid,et,rs,cs,anid)) in leases: - print >>out, "Lease #%d:" % leasenum - print >>out, " ownerid: %d" % oid + print >>out, " Lease #%d:" % leasenum + print >>out, " ownerid: %d" % oid when = format_expiration_time(et) - print >>out, " expires in %s" % when - print >>out, " renew_secret: %s" % idlib.b2a(rs) - print >>out, " cancel_secret: %s" % idlib.b2a(cs) - print >>out, " secrets are for nodeid: %s" % idlib.nodeid_b2a(anid) + print >>out, " expires in %s" % when + print >>out, " renew_secret: %s" % idlib.b2a(rs) + print >>out, " cancel_secret: %s" % idlib.b2a(cs) + print >>out, " secrets are for nodeid: %s" % idlib.nodeid_b2a(anid) else: print >>out, "No leases." print >>out diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index f7860137..5c3be823 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -8,7 +8,7 @@ from twisted.internet import threads # CLI tests use deferToThread from twisted.application import service from allmydata import client, uri, download, upload from allmydata.introducer_and_vdrive import IntroducerAndVdrive -from allmydata.util import fileutil, testutil, deferredutil +from allmydata.util import fileutil, testutil, deferredutil, idlib from allmydata.scripts import runner from allmydata.interfaces import IDirectoryNode, IFileNode, IFileURI from allmydata.dirnode import NotMutableError @@ -257,6 +257,43 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase): return d1 d.addCallback(_create_mutable) + def _test_debug(res): + # find a share. It is important to run this while there is only + # one slot in the grid. + for (dirpath, dirnames, filenames) in os.walk(self.basedir): + if "storage" not in dirpath: + continue + if not filenames: + continue + pieces = dirpath.split(os.sep) + if pieces[-3] == "storage" and pieces[-2] == "shares": + # we're sitting in .../storage/shares/$SINDEX , and there + # are sharefiles here + assert pieces[-4].startswith("client") + client_num = int(pieces[-4][-1]) + filename = os.path.join(dirpath, filenames[0]) + break + else: + self.fail("unable to find any share files in %s" + % self.basedir) + log.msg("test_system.SystemTest.test_mutable._test_debug using %s" + % filename) + log.msg(" for clients[%d]" % client_num) + + out,err = StringIO(), StringIO() + rc = runner.runner(["dump-share", + filename], + stdout=out, stderr=err) + output = out.getvalue() + self.failUnlessEqual(rc, 0) + self.failUnless("Mutable slot found:\n" in output) + peerid = idlib.nodeid_b2a(self.clients[client_num].nodeid) + self.failUnless(" WE for nodeid: %s\n" % peerid in output) + self.failUnless(" num_extra_leases: 0\n" in output) + self.failUnless(" data_length: 381\n" in output) + self.failUnless(" secrets are for nodeid: %s\n" % peerid in output) + d.addCallback(_test_debug) + return d def flip_bit(self, good):