Sketch of lease renewal implementation.

This commit is contained in:
Itamar Turner-Trauring 2022-03-09 13:10:13 -05:00
parent 636ab017d4
commit aee0f7dc69
4 changed files with 62 additions and 8 deletions

View File

@ -310,9 +310,7 @@ class StorageClientImmutables(object):
body = yield response.content()
returnValue(body)
else:
raise ClientException(
response.code,
)
raise ClientException(response.code)
@inlineCallbacks
def list_shares(self, storage_index): # type: (bytes,) -> Deferred[Set[int]]
@ -330,6 +328,29 @@ class StorageClientImmutables(object):
body = yield _decode_cbor(response)
returnValue(set(body))
else:
raise ClientException(
response.code,
)
raise ClientException(response.code)
@inlineCallbacks
def add_or_renew_lease(
self, storage_index: bytes, renew_secret: bytes, cancel_secret: bytes
):
"""
Add or renew a lease.
If the renewal secret matches an existing lease, it is renewed.
Otherwise a new lease is added.
"""
url = self._client.relative_url(
"/v1/lease/{}".format(_encode_si(storage_index))
)
response = yield self._client.request(
"PUT",
url,
lease_renew_secret=renew_secret,
lease_cancel_secret=cancel_secret,
)
if response.code == http.NO_CONTENT:
return
else:
raise ClientException(response.code)

View File

@ -434,3 +434,27 @@ class HTTPServer(object):
ContentRange("bytes", offset, offset + len(data)).to_header(),
)
return data
@_authorized_route(
_app,
{Secrets.LEASE_RENEW, Secrets.LEASE_CANCEL},
"/v1/lease/<storage_index:storage_index>",
methods=["PUT"],
)
def add_or_renew_lease(self, request, authorization, storage_index):
"""Update the lease for an immutable share."""
# TODO 3879 write direct test for success case
# Checking of the renewal secret is done by the backend.
try:
self._storage_server.add_lease(
storage_index,
authorization[Secrets.LEASE_RENEW],
authorization[Secrets.LEASE_CANCEL],
)
except IndexError:
# TODO 3879 write test for this case
raise
request.setResponseCode(http.NO_CONTENT)
return b""

View File

@ -1160,3 +1160,14 @@ class _HTTPStorageServer(object):
))
for share_num in share_numbers
})
def add_lease(
self,
storage_index,
renew_secret,
cancel_secret,
):
immutable_client = StorageClientImmutables(self._http_client)
return immutable_client.add_or_renew_lease(
storage_index, renew_secret, cancel_secret
)

View File

@ -1151,8 +1151,6 @@ class HTTPImmutableAPIsTests(
# These will start passing in future PRs as HTTP protocol is implemented.
SKIP_TESTS = {
"test_add_lease_renewal",
"test_add_new_lease",
"test_advise_corrupt_share",
"test_bucket_advise_corrupt_share",
}