]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_system.mutable: add test coverage for the 'dump-share' debug command
authorBrian Warner <warner@allmydata.com>
Wed, 7 Nov 2007 02:10:49 +0000 (19:10 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 7 Nov 2007 02:10:49 +0000 (19:10 -0700)
src/allmydata/scripts/debug.py
src/allmydata/test/test_system.py

index 7f405f7111529d1c1877ce3abbe3cd60faf56927..d899b10c064586bc3ec83d8a42c8cc46fbedf022 100644 (file)
@@ -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
index f78601372cd140a910e290ac6dc8e710b537fabe..5c3be823096e2a242fea32bd67ec5209e1b06ede 100644 (file)
@@ -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):