Ticket #1758: 1758-approach-b.diff

File 1758-approach-b.diff, 4.5 KB (added by davidsarah, at 2013-01-02T03:22:13Z)

Make 'tahoe check' tolerate lack of certain fields

  • src/allmydata/scripts/tahoe_check.py

    diff --git a/src/allmydata/scripts/tahoe_check.py b/src/allmydata/scripts/tahoe_check.py
    index adb0ccc..5e87c08 100644
    a b def check(options): 
    7777            else:
    7878                stdout.write(" repair failed\n")
    7979    else:
    80         stdout.write("Summary: %s\n" % quote_output(data["summary"], quotemarks=False))
     80        summary = data.get("summary", "Healthy (LIT)")
     81        stdout.write("Summary: %s\n" % quote_output(summary, quotemarks=False))
    8182        cr = data["results"]
    8283        stdout.write(" storage index: %s\n" % quote_output(data["storage-index"], quotemarks=False))
    83         stdout.write(" good-shares: %r (encoding is %r-of-%r)\n"
    84                      % (cr["count-shares-good"],
    85                         cr["count-shares-needed"],
    86                         cr["count-shares-expected"]))
    87         stdout.write(" wrong-shares: %r\n" % cr["count-wrong-shares"])
    88         corrupt = cr["list-corrupt-shares"]
    89         if corrupt:
    90             stdout.write(" corrupt shares:\n")
    91             for (serverid, storage_index, sharenum) in corrupt:
    92                 stdout.write("  %s\n" % _quote_serverid_index_share(serverid, storage_index, sharenum))
     84        if "summary" in data:
     85            stdout.write(" good-shares: %r (encoding is %r-of-%r)\n"
     86                         % (cr["count-shares-good"],
     87                            cr["count-shares-needed"],
     88                            cr["count-shares-expected"]))
     89            stdout.write(" wrong-shares: %r\n" % cr["count-wrong-shares"])
     90            corrupt = cr["list-corrupt-shares"]
     91            if corrupt:
     92                stdout.write(" corrupt shares:\n")
     93                for (serverid, storage_index, sharenum) in corrupt:
     94                    stdout.write("  %s\n" % _quote_serverid_index_share(serverid, storage_index, sharenum))
    9395    return 0
    9496
    9597
  • src/allmydata/test/test_cli.py

    diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py
    index 0edcd78..2d5c752 100644
    a b class Check(GridTestMixin, CLITestMixin, unittest.TestCase): 
    29532953            self.failUnlessReallyEqual(rc, 0)
    29542954            data = simplejson.loads(out)
    29552955            self.failUnlessReallyEqual(to_str(data["summary"]), "Healthy")
     2956            self.failUnlessReallyEqual(data["results"]["healthy"], True)
    29562957        d.addCallback(_check2)
    29572958
     2959        d.addCallback(lambda ign: c0.upload(upload.Data("literal", convergence="")))
     2960        def _stash_lit_uri(n):
     2961            self.lit_uri = n.get_uri()
     2962        d.addCallback(_stash_lit_uri)
     2963
     2964        d.addCallback(lambda ign: self.do_cli("check", self.lit_uri))
     2965        def _check_lit((rc, out, err)):
     2966            self.failUnlessReallyEqual(err, "")
     2967            self.failUnlessReallyEqual(rc, 0)
     2968            lines = out.splitlines()
     2969            self.failUnless("Summary: Healthy (LIT)" in lines, out)
     2970        d.addCallback(_check_lit)
     2971
     2972        d.addCallback(lambda ign: self.do_cli("check", "--raw", self.lit_uri))
     2973        def _check_lit((rc, out, err)):
     2974            self.failUnlessReallyEqual(err, "")
     2975            self.failUnlessReallyEqual(rc, 0)
     2976            data = simplejson.loads(out)
     2977            self.failUnlessReallyEqual(data["results"]["healthy"], True)
     2978        d.addCallback(_check_lit)
     2979
    29582980        def _clobber_shares(ignored):
    29592981            # delete one, corrupt a second
    29602982            shares = self.find_uri_shares(self.uri)
    class Check(GridTestMixin, CLITestMixin, unittest.TestCase): 
    29843006            self.failUnless(self._corrupt_share_line in lines, out)
    29853007        d.addCallback(_check3)
    29863008
     3009        d.addCallback(lambda ign: self.do_cli("check", "--verify", "--raw", self.uri))
     3010        def _check3_raw((rc, out, err)):
     3011            self.failUnlessReallyEqual(err, "")
     3012            self.failUnlessReallyEqual(rc, 0)
     3013            data = simplejson.loads(out)
     3014            self.failUnlessReallyEqual(data["results"]["healthy"], False)
     3015            self.failUnlessIn("Unhealthy: 8 shares (enc 3-of-10)", data["summary"])
     3016            self.failUnlessReallyEqual(data["results"]["count-shares-good"], 8)
     3017            self.failUnlessReallyEqual(data["results"]["count-corrupt-shares"], 1)
     3018            self.failUnlessIn("list-corrupt-shares", data["results"])
     3019        d.addCallback(_check3_raw)
     3020
    29873021        d.addCallback(lambda ign:
    29883022                      self.do_cli("check", "--verify", "--repair", self.uri))
    29893023        def _check4((rc, out, err)):