From: Brian Warner Date: Fri, 13 Jul 2007 23:58:08 +0000 (-0700) Subject: fix dump-uri-extension X-Git-Url: https://git.rkrishnan.org/pf/content//%22%3C?a=commitdiff_plain;h=4d868e6649c2c5d838f36515f0030ee7120aa585;p=tahoe-lafs%2Ftahoe-lafs.git fix dump-uri-extension --- diff --git a/src/allmydata/scripts/debug.py b/src/allmydata/scripts/debug.py index 23e91a85..d6a53885 100644 --- a/src/allmydata/scripts/debug.py +++ b/src/allmydata/scripts/debug.py @@ -1,5 +1,7 @@ -import os, sys +# do not import any allmydata modules at this level. Do that from inside +# individual functions instead. +import os, sys, struct from twisted.python import usage from allmydata.scripts.common import BasedirMixin @@ -41,10 +43,18 @@ class DumpDirnodeOptions(BasedirMixin, usage.Options): raise usage.UsageError(" parameter is required") def dump_uri_extension(config, out=sys.stdout, err=sys.stderr): - from allmydata import uri + from allmydata import uri, storageserver filename = config['filename'] - unpacked = uri.unpack_extension_readable(open(filename,"rb").read()) + f = open(filename,"rb") + # use a ReadBucketProxy to parse the bucket and find the uri extension + bp = storageserver.ReadBucketProxy(None) + offsets = bp._parse_offsets(f.read(8*4)) + f.seek(offsets['uri_extension']) + length = struct.unpack(">L", f.read(4))[0] + data = f.read(length) + + unpacked = uri.unpack_extension_readable(data) keys1 = ("size", "num_segments", "segment_size", "needed_shares", "total_shares") keys2 = ("codec_name", "codec_params", "tail_codec_params") @@ -66,6 +76,7 @@ def dump_uri_extension(config, out=sys.stdout, err=sys.stderr): leftover = set(unpacked.keys()) - set(keys1 + keys2 + keys3) if leftover: print >>out + print >>out, "LEFTOVER:" for k in sorted(leftover): print >>out, "%s: %s" % (k, unpacked[k]) diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index d899aa7a..1fa99a33 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -551,16 +551,22 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase): def _test_runner(self, res): # exercise some of the diagnostic tools in runner.py - # find a uri_extension file + # find a share for (dirpath, dirnames, filenames) in os.walk(self.basedir): - if "uri_extension" in filenames: + if "storage" not in dirpath: + continue + if not filenames: + continue + pieces = dirpath.split(os.sep) + if pieces[-2] == "storage": + # we're sitting in .../storage/$SINDEX , and there are + # sharefiles here + filename = os.path.join(dirpath, filenames[0]) break else: self.fail("unable to find any uri_extension files in %s" % self.basedir) - log.msg("test_system.SystemTest._test_runner using %s" % dirpath) - - filename = os.path.join(dirpath, "uri_extension") + log.msg("test_system.SystemTest._test_runner using %s" % filename) out,err = StringIO(), StringIO() rc = runner.runner(["dump-uri-extension",