diff --git a/src/allmydata/scripts/tahoe_check.py b/src/allmydata/scripts/tahoe_check.py index adb0ccc..5e87c08 100644 --- a/src/allmydata/scripts/tahoe_check.py +++ b/src/allmydata/scripts/tahoe_check.py @@ -77,19 +77,21 @@ def check(options): else: stdout.write(" repair failed\n") else: - stdout.write("Summary: %s\n" % quote_output(data["summary"], quotemarks=False)) + 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 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)) + if "summary" in data: + 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 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 diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index 0edcd78..2d5c752 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -2953,8 +2953,30 @@ 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((rc, out, err)): + self.failUnlessReallyEqual(err, "") + self.failUnlessReallyEqual(rc, 0) + data = simplejson.loads(out) + self.failUnlessReallyEqual(data["results"]["healthy"], True) + d.addCallback(_check_lit) + def _clobber_shares(ignored): # delete one, corrupt a second shares = self.find_uri_shares(self.uri) @@ -2984,6 +3006,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)):