From 948e6b34dda89d4d2539ec1ef1d03e28fb663d0e Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 31 Oct 2007 01:44:01 -0700 Subject: [PATCH] storage.py: improve test coverage even more --- src/allmydata/storage.py | 4 ++-- src/allmydata/test/test_storage.py | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/allmydata/storage.py b/src/allmydata/storage.py index c634e4cb..f8caa72f 100644 --- a/src/allmydata/storage.py +++ b/src/allmydata/storage.py @@ -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") diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 1cbc87bd..bc2258ae 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -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)) -- 2.45.2