]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
fix dump-uri-extension
authorBrian Warner <warner@lothar.com>
Fri, 13 Jul 2007 23:58:08 +0000 (16:58 -0700)
committerBrian Warner <warner@lothar.com>
Fri, 13 Jul 2007 23:58:08 +0000 (16:58 -0700)
src/allmydata/scripts/debug.py
src/allmydata/test/test_system.py

index 23e91a85da11c48646542f0f180d83d4aecc61a2..d6a5388502053d183b449d5a439c1d2a867d6dfc 100644 (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])
 
index d899aa7af6fd9d36b2da6b13b95095c0206417b2..1fa99a335ae2ba4f22dd8ec0371e4c2436ec49b5 100644 (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",