From 1cfe58a52dfae9682cb01aee8e8f077e919796be Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 31 Aug 2020 13:17:52 -0400 Subject: [PATCH] All of test_storage passes on Python 3. --- src/allmydata/storage/immutable.py | 8 ++++++-- src/allmydata/storage/server.py | 11 ++++++++--- src/allmydata/test/test_storage.py | 8 ++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/allmydata/storage/immutable.py b/src/allmydata/storage/immutable.py index 32ba1a739..8d83ec1b3 100644 --- a/src/allmydata/storage/immutable.py +++ b/src/allmydata/storage/immutable.py @@ -1,3 +1,5 @@ +from future.utils import bytes_to_native_str + import os, stat, struct, time from foolscap.api import Referenceable @@ -298,7 +300,9 @@ class BucketReader(Referenceable): def __repr__(self): return "<%s %s %s>" % (self.__class__.__name__, - base32.b2a(self.storage_index[:8])[:12], + bytes_to_native_str( + base32.b2a(self.storage_index[:8])[:12] + ), self.shnum) def remote_read(self, offset, length): @@ -309,7 +313,7 @@ class BucketReader(Referenceable): return data def remote_advise_corrupt_share(self, reason): - return self.ss.remote_advise_corrupt_share("immutable", + return self.ss.remote_advise_corrupt_share(b"immutable", self.storage_index, self.shnum, reason) diff --git a/src/allmydata/storage/server.py b/src/allmydata/storage/server.py index 387225b01..ad8001a60 100644 --- a/src/allmydata/storage/server.py +++ b/src/allmydata/storage/server.py @@ -1,3 +1,4 @@ +from future.utils import bytes_to_native_str import os, re, struct, time import weakref import six @@ -676,6 +677,10 @@ class StorageServer(service.MultiService, Referenceable): def remote_advise_corrupt_share(self, share_type, storage_index, shnum, reason): + # This is a remote API, I believe, so this has to be bytes for legacy + # protocol backwards compatibility reasons. + assert isinstance(share_type, bytes) + assert isinstance(reason, bytes) fileutil.make_dirs(self.corruption_advisory_dir) now = time_format.iso_utc(sep="T") si_s = si_b2a(storage_index) @@ -684,11 +689,11 @@ class StorageServer(service.MultiService, Referenceable): "%s--%s-%d" % (now, si_s, shnum)).replace(":","") with open(fn, "w") as f: f.write("report: Share Corruption\n") - f.write("type: %s\n" % share_type) - f.write("storage_index: %s\n" % si_s) + f.write("type: %s\n" % bytes_to_native_str(share_type)) + f.write("storage_index: %s\n" % bytes_to_native_str(si_s)) f.write("share_number: %d\n" % shnum) f.write("\n") - f.write(reason) + f.write(bytes_to_native_str(reason)) f.write("\n") log.msg(format=("client claims corruption in (%(share_type)s) " + "%(si)s-%(shnum)d: %(reason)s"), diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 3fc4fd11f..5c8faabc3 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -1,4 +1,4 @@ -from future.utils import native_str, PY3 +from future.utils import native_str, PY3, bytes_to_native_str import time import os.path @@ -731,7 +731,7 @@ class Server(unittest.TestCase): si0_s = base32.b2a(b"si0") ss.remote_advise_corrupt_share(b"immutable", b"si0", 0, - "This share smells funny.\n") + b"This share smells funny.\n") reportdir = os.path.join(workdir, "corruption-advisories") reports = os.listdir(reportdir) self.failUnlessEqual(len(reports), 1) @@ -755,11 +755,11 @@ class Server(unittest.TestCase): b = ss.remote_get_buckets(b"si1") self.failUnlessEqual(set(b.keys()), set([1])) - b[1].remote_advise_corrupt_share("This share tastes like dust.\n") + b[1].remote_advise_corrupt_share(b"This share tastes like dust.\n") reports = os.listdir(reportdir) self.failUnlessEqual(len(reports), 2) - report_si1 = [r for r in reports if si1_s in r][0] + report_si1 = [r for r in reports if bytes_to_native_str(si1_s) in r][0] f = open(os.path.join(reportdir, report_si1), "rb") report = f.read() f.close()