]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
storage.py: improve test coverage even more
authorBrian Warner <warner@lothar.com>
Wed, 31 Oct 2007 08:44:01 +0000 (01:44 -0700)
committerBrian Warner <warner@lothar.com>
Wed, 31 Oct 2007 08:44:01 +0000 (01:44 -0700)
src/allmydata/storage.py
src/allmydata/test/test_storage.py

index c634e4cbfd21cc6b6b52f3ce06426c6e78689be6..f8caa72fa3861b712bf32ebcf0f954ea7eefe44a 100644 (file)
@@ -23,7 +23,7 @@ class DataTooLargeError(Exception):
 # storage/shares/$STORAGEINDEX/$SHARENUM
 
 # $SHARENUM matches this regex:
-NUM_RE=re.compile("[0-9]*")
+NUM_RE=re.compile("^[0-9]+$")
 
 # each share file (in storage/shares/$SI/$SHNUM) contains lease information
 # and share data. The share data is accessed by RIBucketWriter.write and
@@ -772,7 +772,7 @@ class StorageServer(service.MultiService, Referenceable):
                 os.unlink(filename)
                 total_space_freed += filelen
         if not remaining_files:
-            os.rmdir(storagedir)
+            fileutil.rm_dir(storagedir)
         self.consumed -= total_space_freed
         if not found_buckets:
             raise IndexError("no such lease to cancel")
index 1cbc87bdbbc56205cf7839d8af4822c9dc238eb4..bc2258ae281a07c80271fd4548f4be078fbb1153 100644 (file)
@@ -7,7 +7,7 @@ from foolscap import Referenceable
 import time, os.path, stat
 import itertools
 from allmydata import interfaces
-from allmydata.util import fileutil, hashutil
+from allmydata.util import fileutil, hashutil, idlib
 from allmydata.storage import BucketWriter, BucketReader, \
      WriteBucketProxy, ReadBucketProxy, StorageServer
 from allmydata.interfaces import BadWriteEnablerError
@@ -699,6 +699,14 @@ class MutableServer(unittest.TestCase):
                                             [(0, data),],
                                             new_length=None)
 
+        # create a random non-numeric file in the bucket directory, to
+        # exercise the code that's supposed to ignore those.
+        bucket_dir = os.path.join(self.workdir("test_leases"),
+                                  "shares", idlib.b2a("si1"))
+        f = open(os.path.join(bucket_dir, "ignore_me.txt"), "w")
+        f.write("you ought to be ignoring me\n")
+        f.close()
+
         # re-allocate the slots and use the same secrets, that should update
         # the lease
         shares2 = self.allocate(ss, "si1", "we1", secret, set([0,1,2]), 100)
@@ -731,6 +739,18 @@ class MutableServer(unittest.TestCase):
         ss.remote_renew_lease("si1", self.renew_secret(secret+3))
         ss.remote_renew_lease("si1", self.renew_secret(secret+4))
 
+        # renewing with a bogus token should prompt an error message
+
+        # TODO: examine the exception thus raised, make sure the old nodeid
+        # is present, to provide for share migration
+        self.failUnlessRaises(IndexError,
+                              ss.remote_renew_lease, "si1",
+                              self.renew_secret(secret+20))
+        # same for cancelling
+        self.failUnlessRaises(IndexError,
+                              ss.remote_cancel_lease, "si1",
+                              self.cancel_secret(secret+20))
+
         # now cancel them all
         ss.remote_cancel_lease("si1", self.cancel_secret(secret))
         ss.remote_cancel_lease("si1", self.cancel_secret(secret+1))