mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 07:06:41 +00:00
Introduce UnknownContainerVersionError
base w/ structured args
This commit is contained in:
parent
0459b712b0
commit
274dc6e837
@ -16,11 +16,16 @@ from allmydata.util import base32
|
||||
# Backwards compatibility.
|
||||
from allmydata.interfaces import DataTooLargeError # noqa: F401
|
||||
|
||||
class UnknownMutableContainerVersionError(Exception):
|
||||
pass
|
||||
class UnknownImmutableContainerVersionError(Exception):
|
||||
class UnknownContainerVersionError(Exception):
|
||||
def __init__(self, filename, version):
|
||||
self.filename = filename
|
||||
self.version = version
|
||||
|
||||
class UnknownMutableContainerVersionError(UnknownContainerVersionError):
|
||||
pass
|
||||
|
||||
class UnknownImmutableContainerVersionError(UnknownContainerVersionError):
|
||||
pass
|
||||
|
||||
def si_b2a(storageindex):
|
||||
return base32.b2a(storageindex)
|
||||
|
@ -174,9 +174,7 @@ class ShareFile(object):
|
||||
filesize = os.path.getsize(self.home)
|
||||
(version, unused, num_leases) = struct.unpack(">LLL", f.read(0xc))
|
||||
if version != 1:
|
||||
msg = "sharefile %s had version %d but we wanted 1" % \
|
||||
(filename, version)
|
||||
raise UnknownImmutableContainerVersionError(msg)
|
||||
raise UnknownImmutableContainerVersionError(filename, version)
|
||||
self._num_leases = num_leases
|
||||
self._lease_offset = filesize - (num_leases * self.LEASE_SIZE)
|
||||
self._data_offset = 0xc
|
||||
|
@ -95,9 +95,7 @@ class MutableShareFile(object):
|
||||
data_length, extra_least_offset) = \
|
||||
struct.unpack(">32s20s32sQQ", data)
|
||||
if not self.is_valid_header(data):
|
||||
msg = "sharefile %s had magic '%r' but we wanted '%r'" % \
|
||||
(filename, magic, self.MAGIC)
|
||||
raise UnknownMutableContainerVersionError(msg)
|
||||
raise UnknownMutableContainerVersionError(filename, magic)
|
||||
self.parent = parent # for logging
|
||||
|
||||
def log(self, *args, **kwargs):
|
||||
|
@ -646,7 +646,8 @@ class Server(unittest.TestCase):
|
||||
|
||||
e = self.failUnlessRaises(UnknownImmutableContainerVersionError,
|
||||
ss.remote_get_buckets, b"si1")
|
||||
self.failUnlessIn(" had version 0 but we wanted 1", str(e))
|
||||
self.assertEqual(e.filename, fn)
|
||||
self.assertEqual(e.version, 0)
|
||||
|
||||
def test_disconnect(self):
|
||||
# simulate a disconnection
|
||||
@ -1127,8 +1128,8 @@ class MutableServer(unittest.TestCase):
|
||||
read = ss.remote_slot_readv
|
||||
e = self.failUnlessRaises(UnknownMutableContainerVersionError,
|
||||
read, b"si1", [0], [(0,10)])
|
||||
self.failUnlessIn(" had magic ", str(e))
|
||||
self.failUnlessIn(" but we wanted ", str(e))
|
||||
self.assertEqual(e.filename, fn)
|
||||
self.assertTrue(e.version.startswith(b"BAD MAGIC"))
|
||||
|
||||
def test_container_size(self):
|
||||
ss = self.create("test_container_size")
|
||||
|
Loading…
Reference in New Issue
Block a user