fix dump-uri-extension

This commit is contained in:
Brian Warner 2007-07-13 16:58:08 -07:00
parent 35117d77a0
commit 4d868e6649
2 changed files with 25 additions and 8 deletions

View File

@ -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("<uri> 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])

View File

@ -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",