mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 14:52:26 +00:00
Make HTTP and Foolscap match in another edge case.
This commit is contained in:
parent
8190eea489
commit
8b0ddf406e
@ -45,6 +45,7 @@ from zope.interface import (
|
||||
Interface,
|
||||
implementer,
|
||||
)
|
||||
from twisted.python.failure import Failure
|
||||
from twisted.web import http
|
||||
from twisted.internet.task import LoopingCall
|
||||
from twisted.internet import defer, reactor
|
||||
@ -1233,6 +1234,16 @@ class _HTTPBucketWriter(object):
|
||||
return self.finished
|
||||
|
||||
|
||||
def _ignore_404(failure: Failure) -> Union[Failure, None]:
|
||||
"""
|
||||
Useful for advise_corrupt_share(), since it swallows unknown share numbers
|
||||
in Foolscap.
|
||||
"""
|
||||
if failure.check(HTTPClientException) and failure.value.code == http.NOT_FOUND:
|
||||
return None
|
||||
else:
|
||||
return failure
|
||||
|
||||
|
||||
@attr.s(hash=True)
|
||||
class _HTTPBucketReader(object):
|
||||
@ -1252,7 +1263,7 @@ class _HTTPBucketReader(object):
|
||||
return self.client.advise_corrupt_share(
|
||||
self.storage_index, self.share_number,
|
||||
str(reason, "utf-8", errors="backslashreplace")
|
||||
)
|
||||
).addErrback(_ignore_404)
|
||||
|
||||
|
||||
# WORK IN PROGRESS, for now it doesn't actually implement whole thing.
|
||||
@ -1352,7 +1363,7 @@ class _HTTPStorageServer(object):
|
||||
raise ValueError("Unknown share type")
|
||||
return client.advise_corrupt_share(
|
||||
storage_index, shnum, str(reason, "utf-8", errors="backslashreplace")
|
||||
)
|
||||
).addErrback(_ignore_404)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def slot_readv(self, storage_index, shares, readv):
|
||||
|
@ -440,6 +440,17 @@ class IStorageServerImmutableAPIsTestsMixin(object):
|
||||
b"immutable", storage_index, 0, b"ono"
|
||||
)
|
||||
|
||||
@inlineCallbacks
|
||||
def test_advise_corrupt_share_unknown_share_number(self):
|
||||
"""
|
||||
Calling ``advise_corrupt_share()`` on an immutable share, with an
|
||||
unknown share number, does not result in error.
|
||||
"""
|
||||
storage_index, _, _ = yield self.create_share()
|
||||
yield self.storage_client.advise_corrupt_share(
|
||||
b"immutable", storage_index, 999, b"ono"
|
||||
)
|
||||
|
||||
@inlineCallbacks
|
||||
def test_allocate_buckets_creates_lease(self):
|
||||
"""
|
||||
@ -909,6 +920,19 @@ class IStorageServerMutableAPIsTestsMixin(object):
|
||||
b"mutable", storage_index, 0, b"ono"
|
||||
)
|
||||
|
||||
@inlineCallbacks
|
||||
def test_advise_corrupt_share_unknown_share_number(self):
|
||||
"""
|
||||
Calling ``advise_corrupt_share()`` on a mutable share with an unknown
|
||||
share number does not result in error (other behavior is opaque at this
|
||||
level of abstraction).
|
||||
"""
|
||||
secrets, storage_index = yield self.create_slot()
|
||||
|
||||
yield self.storage_client.advise_corrupt_share(
|
||||
b"mutable", storage_index, 999, b"ono"
|
||||
)
|
||||
|
||||
@inlineCallbacks
|
||||
def test_STARAW_create_lease(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user