from allmydata.util import idlib, log
from allmydata.util.assertutil import precondition
from allmydata.storage.lease import LeaseInfo
-from allmydata.storage.common import DataTooLargeError
+from allmydata.storage.common import UnknownMutableContainerVersionError, \
+ DataTooLargeError
# the MutableShareFile is like the ShareFile, but used for mutable data. It
# has a different layout. See docs/mutable.txt for more details.
write_enabler_nodeid, write_enabler,
data_length, extra_least_offset) = \
struct.unpack(">32s20s32sQQ", data)
- assert magic == self.MAGIC
+ if magic != self.MAGIC:
+ msg = "sharefile %s had magic '%r' but we wanted '%r'" % \
+ (filename, magic, self.MAGIC)
+ raise UnknownMutableContainerVersionError(msg)
self.parent = parent # for logging
def log(self, *args, **kwargs):
from allmydata.storage.server import StorageServer
from allmydata.storage.mutable import MutableShareFile
from allmydata.storage.immutable import BucketWriter, BucketReader
-from allmydata.storage.common import DataTooLargeError, storage_index_to_dir
+from allmydata.storage.common import DataTooLargeError, storage_index_to_dir, \
+ UnknownMutableContainerVersionError
from allmydata.storage.lease import LeaseInfo
from allmydata.storage.crawler import BucketCountingCrawler
from allmydata.storage.expirer import LeaseCheckingCrawler
self.failUnless(isinstance(readv_data, dict))
self.failUnlessEqual(len(readv_data), 0)
+ def test_bad_magic(self):
+ ss = self.create("test_bad_magic")
+ self.allocate(ss, "si1", "we1", self._lease_secret.next(), set([0]), 10)
+ fn = os.path.join(ss.sharedir, storage_index_to_dir("si1"), "0")
+ f = open(fn, "rb+")
+ f.seek(0)
+ f.write("BAD MAGIC")
+ f.close()
+ read = ss.remote_slot_readv
+ e = self.failUnlessRaises(UnknownMutableContainerVersionError,
+ read, "si1", [0], [(0,10)])
+ self.failUnless(" had magic " in str(e), e)
+ self.failUnless(" but we wanted " in str(e), e)
+
def test_container_size(self):
ss = self.create("test_container_size")
self.allocate(ss, "si1", "we1", self._lease_secret.next(),