From 48a9bf745724c5c5333e46ad48f3ae6c3771c8fc Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 1 Feb 2022 10:25:13 -0500 Subject: [PATCH] Hook up more IStorageServer tests that can now pass with HTTP. --- src/allmydata/storage_client.py | 33 +++++++++++++++++++++-- src/allmydata/test/test_istorageserver.py | 2 -- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index ca977c9d9..e7dbb27a8 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -1042,7 +1042,7 @@ class _FakeRemoteReference(object): @attr.s class _HTTPBucketWriter(object): """ - Emulate a ``RIBucketWriter``. + Emulate a ``RIBucketWriter``, but use HTTP protocol underneath. """ client = attr.ib(type=StorageClientImmutables) storage_index = attr.ib(type=bytes) @@ -1069,6 +1069,25 @@ class _HTTPBucketWriter(object): return defer.succeed(None) + +@attr.s +class _HTTPBucketReader(object): + """ + Emulate a ``RIBucketReader``. + """ + client = attr.ib(type=StorageClientImmutables) + storage_index = attr.ib(type=bytes) + share_number = attr.ib(type=int) + + def read(self, offset, length): + return self.client.read_share_chunk( + self.storage_index, self.share_number, offset, length + ) + + def advise_corrupt_share(self, reason): + pass # TODO in later ticket + + # WORK IN PROGRESS, for now it doesn't actually implement whole thing. @implementer(IStorageServer) # type: ignore @attr.s @@ -1117,8 +1136,18 @@ class _HTTPStorageServer(object): }) ) + @defer.inlineCallbacks def get_buckets( self, storage_index, ): - pass + immutable_client = StorageClientImmutables(self._http_client) + share_numbers = yield immutable_client.list_shares( + storage_index + ) + defer.returnValue({ + share_num: _FakeRemoteReference(_HTTPBucketReader( + immutable_client, storage_index, share_num + )) + for share_num in share_numbers + }) diff --git a/src/allmydata/test/test_istorageserver.py b/src/allmydata/test/test_istorageserver.py index 96d4f687f..dc2aa0efb 100644 --- a/src/allmydata/test/test_istorageserver.py +++ b/src/allmydata/test/test_istorageserver.py @@ -1149,8 +1149,6 @@ class HTTPImmutableAPIsTests( "test_get_buckets_skips_unfinished_buckets", "test_matching_overlapping_writes", "test_non_matching_overlapping_writes", - "test_read_bucket_at_offset", - "test_written_shares_are_readable", "test_written_shares_are_allocated", }