]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
tahoe_check.py: tolerate missing fields in check results for LIT files/dirs. fixes...
authorDavid-Sarah Hopwood <david-sarah@jacaranda.org>
Thu, 3 Jan 2013 22:16:20 +0000 (22:16 +0000)
committerDavid-Sarah Hopwood <david-sarah@jacaranda.org>
Thu, 3 Jan 2013 22:16:20 +0000 (22:16 +0000)
Also test this case and improve some existing tests of 'tahoe check'.

Signed-off-by: David-Sarah Hopwood <david-sarah@jacaranda.org>
src/allmydata/scripts/tahoe_check.py
src/allmydata/test/test_cli.py

index adb0ccc4d9878c9bfd391fbde5e7acf65307e189..23064359d9b16987721157a0a59b1e46be82ab63 100644 (file)
@@ -77,19 +77,26 @@ def check(options):
             else:
                 stdout.write(" repair failed\n")
     else:
-        stdout.write("Summary: %s\n" % quote_output(data["summary"], quotemarks=False))
+        # LIT files and directories do not have a "summary" field.
+        summary = data.get("summary", "Healthy (LIT)")
+        stdout.write("Summary: %s\n" % quote_output(summary, quotemarks=False))
         cr = data["results"]
         stdout.write(" storage index: %s\n" % quote_output(data["storage-index"], quotemarks=False))
-        stdout.write(" good-shares: %r (encoding is %r-of-%r)\n"
-                     % (cr["count-shares-good"],
-                        cr["count-shares-needed"],
-                        cr["count-shares-expected"]))
-        stdout.write(" wrong-shares: %r\n" % cr["count-wrong-shares"])
-        corrupt = cr["list-corrupt-shares"]
+
+        if all([field in cr for field in ("count-shares-good", "count-shares-needed",
+                                          "count-shares-expected", "count-wrong-shares")]):
+            stdout.write(" good-shares: %r (encoding is %r-of-%r)\n"
+                         % (cr["count-shares-good"],
+                            cr["count-shares-needed"],
+                            cr["count-shares-expected"]))
+            stdout.write(" wrong-shares: %r\n" % cr["count-wrong-shares"])
+
+        corrupt = cr.get("list-corrupt-shares", [])
         if corrupt:
             stdout.write(" corrupt shares:\n")
             for (serverid, storage_index, sharenum) in corrupt:
                 stdout.write("  %s\n" % _quote_serverid_index_share(serverid, storage_index, sharenum))
+
     return 0
 
 
@@ -138,6 +145,8 @@ class DeepCheckOutput(LineOnlyReceiver):
             path = d["path"]
             if not path:
                 path = ["<root>"]
+
+            # LIT files and directories do not have a "summary" field.
             summary = cr.get("summary", "Healthy (LIT)")
             print >>stdout, "%s: %s" % (quote_path(path), quote_output(summary, quotemarks=False))
 
index 0edcd78a4f110f071c5fe805b1f315817b1d7596..b6a592e9dddd4db0142b5044bc14d103967b149a 100644 (file)
@@ -2953,8 +2953,41 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
             self.failUnlessReallyEqual(rc, 0)
             data = simplejson.loads(out)
             self.failUnlessReallyEqual(to_str(data["summary"]), "Healthy")
+            self.failUnlessReallyEqual(data["results"]["healthy"], True)
         d.addCallback(_check2)
 
+        d.addCallback(lambda ign: c0.upload(upload.Data("literal", convergence="")))
+        def _stash_lit_uri(n):
+            self.lit_uri = n.get_uri()
+        d.addCallback(_stash_lit_uri)
+
+        d.addCallback(lambda ign: self.do_cli("check", self.lit_uri))
+        def _check_lit((rc, out, err)):
+            self.failUnlessReallyEqual(err, "")
+            self.failUnlessReallyEqual(rc, 0)
+            lines = out.splitlines()
+            self.failUnless("Summary: Healthy (LIT)" in lines, out)
+        d.addCallback(_check_lit)
+
+        d.addCallback(lambda ign: self.do_cli("check", "--raw", self.lit_uri))
+        def _check_lit_raw((rc, out, err)):
+            self.failUnlessReallyEqual(err, "")
+            self.failUnlessReallyEqual(rc, 0)
+            data = simplejson.loads(out)
+            self.failUnlessReallyEqual(data["results"]["healthy"], True)
+        d.addCallback(_check_lit_raw)
+
+        d.addCallback(lambda ign: c0.create_immutable_dirnode({}, convergence=""))
+        def _stash_lit_dir_uri(n):
+            self.lit_dir_uri = n.get_uri()
+        d.addCallback(_stash_lit_dir_uri)
+
+        d.addCallback(lambda ign: self.do_cli("check", self.lit_dir_uri))
+        d.addCallback(_check_lit)
+
+        d.addCallback(lambda ign: self.do_cli("check", "--raw", self.lit_uri))
+        d.addCallback(_check_lit_raw)
+
         def _clobber_shares(ignored):
             # delete one, corrupt a second
             shares = self.find_uri_shares(self.uri)
@@ -2984,6 +3017,18 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
             self.failUnless(self._corrupt_share_line in lines, out)
         d.addCallback(_check3)
 
+        d.addCallback(lambda ign: self.do_cli("check", "--verify", "--raw", self.uri))
+        def _check3_raw((rc, out, err)):
+            self.failUnlessReallyEqual(err, "")
+            self.failUnlessReallyEqual(rc, 0)
+            data = simplejson.loads(out)
+            self.failUnlessReallyEqual(data["results"]["healthy"], False)
+            self.failUnlessIn("Unhealthy: 8 shares (enc 3-of-10)", data["summary"])
+            self.failUnlessReallyEqual(data["results"]["count-shares-good"], 8)
+            self.failUnlessReallyEqual(data["results"]["count-corrupt-shares"], 1)
+            self.failUnlessIn("list-corrupt-shares", data["results"])
+        d.addCallback(_check3_raw)
+
         d.addCallback(lambda ign:
                       self.do_cli("check", "--verify", "--repair", self.uri))
         def _check4((rc, out, err)):