First end-to-end immutable upload then download test passes.

This commit is contained in:
Itamar Turner-Trauring 2022-01-17 14:20:40 -05:00
parent 25e2100219
commit d4ae7c89aa
3 changed files with 22 additions and 6 deletions

View File

@ -223,7 +223,7 @@ class ImmutableHTTPAPITests(AsyncTestCase):
# We can now read:
for offset, length in [(0, 100), (10, 19), (99, 0), (49, 200)]:
downloaded = yield im_client.read_share_chunk(
storage_index, 1, upload_secret, offset, length
storage_index, 1, offset, length
)
self.assertEqual(downloaded, expected_data[offset : offset + length])

View File

@ -252,12 +252,13 @@ class StorageClientImmutables(object):
headers=Headers(
{
# The range is inclusive.
"range": ["bytes={}-{}".format(offset, offset + length)]
"range": ["bytes={}-{}".format(offset, offset + length - 1)]
}
),
)
if response.code == 200:
returnValue(response.content.read())
body = yield response.content()
returnValue(body)
else:
raise ClientException(
response.code,

View File

@ -241,6 +241,7 @@ class HTTPServer(object):
# TODO if raises ConflictingWriteError, return HTTP CONFLICT code.
if finished:
bucket.close()
request.setResponseCode(http.CREATED)
else:
request.setResponseCode(http.OK)
@ -257,8 +258,22 @@ class HTTPServer(object):
)
def read_share_chunk(self, request, authorization, storage_index, share_number):
"""Read a chunk for an already uploaded immutable."""
# TODO read offset and length from Range header
# TODO basic checks on validity
# TODO lookup the share
storage_index = si_a2b(storage_index.encode("ascii"))
range_header = request.getHeader("range")
if range_header is None:
offset = 0
inclusive_end = None
else:
parts = range_header.split("=")[1].split("-")
offset = int(parts[0]) # TODO make sure valid
if len(parts) > 0:
inclusive_end = int(parts[1]) # TODO make sure valid
else:
inclusive_end = None
assert inclusive_end != None # TODO support this case
# TODO if not found, 404
# TODO otherwise, return data from that offset
bucket = self._storage_server.get_buckets(storage_index)[share_number]
return bucket.read(offset, inclusive_end - offset + 1)