2019-06-14 20:34:10 +00:00
|
|
|
"""
|
|
|
|
A storage server plugin the test suite can use to validate the
|
|
|
|
functionality.
|
|
|
|
"""
|
|
|
|
|
2019-07-24 19:37:24 +00:00
|
|
|
from json import (
|
|
|
|
dumps,
|
|
|
|
)
|
|
|
|
|
2019-06-14 20:34:10 +00:00
|
|
|
import attr
|
|
|
|
|
|
|
|
from zope.interface import (
|
|
|
|
implementer,
|
|
|
|
)
|
|
|
|
|
2019-06-17 18:23:08 +00:00
|
|
|
from twisted.internet.defer import (
|
|
|
|
succeed,
|
|
|
|
)
|
2019-11-19 17:56:26 +00:00
|
|
|
from twisted.web.resource import (
|
|
|
|
Resource,
|
|
|
|
)
|
2019-07-24 19:37:24 +00:00
|
|
|
from twisted.web.static import (
|
|
|
|
Data,
|
|
|
|
)
|
2019-06-14 20:34:10 +00:00
|
|
|
from foolscap.api import (
|
|
|
|
RemoteInterface,
|
|
|
|
)
|
|
|
|
|
|
|
|
from allmydata.interfaces import (
|
|
|
|
IFoolscapStoragePlugin,
|
2019-06-28 12:52:17 +00:00
|
|
|
IStorageServer,
|
2019-06-14 20:34:10 +00:00
|
|
|
)
|
|
|
|
from allmydata.client import (
|
|
|
|
AnnounceableStorageServer,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class RIDummy(RemoteInterface):
|
|
|
|
__remote_name__ = "RIDummy.tahoe.allmydata.com"
|
|
|
|
|
|
|
|
def just_some_method():
|
|
|
|
"""
|
|
|
|
Just some method so there is something callable on this object. We won't
|
|
|
|
pretend to actually offer any storage capabilities.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementer(IFoolscapStoragePlugin)
|
2019-06-14 21:54:35 +00:00
|
|
|
@attr.s
|
2019-06-14 20:34:10 +00:00
|
|
|
class DummyStorage(object):
|
2019-06-14 21:54:35 +00:00
|
|
|
name = attr.ib()
|
2019-06-14 20:34:10 +00:00
|
|
|
|
2019-08-19 15:21:03 +00:00
|
|
|
@property
|
|
|
|
def _client_section_name(self):
|
|
|
|
return u"storageclient.plugins.{}".format(self.name)
|
|
|
|
|
2019-06-14 20:34:10 +00:00
|
|
|
def get_storage_server(self, configuration, get_anonymous_storage_server):
|
2019-06-19 16:40:34 +00:00
|
|
|
if u"invalid" in configuration:
|
|
|
|
raise Exception("The plugin is unhappy.")
|
|
|
|
|
2019-06-17 18:23:08 +00:00
|
|
|
announcement = {u"value": configuration.get(u"some", u"default-value")}
|
|
|
|
storage_server = DummyStorageServer(get_anonymous_storage_server)
|
|
|
|
return succeed(
|
|
|
|
AnnounceableStorageServer(
|
|
|
|
announcement,
|
|
|
|
storage_server,
|
|
|
|
),
|
2019-06-14 20:34:10 +00:00
|
|
|
)
|
|
|
|
|
2019-07-02 19:46:17 +00:00
|
|
|
def get_storage_client(self, configuration, announcement, get_rref):
|
2019-08-19 19:11:13 +00:00
|
|
|
return DummyStorageClient(
|
|
|
|
get_rref,
|
|
|
|
dict(configuration.items(self._client_section_name, [])),
|
|
|
|
announcement,
|
|
|
|
)
|
2019-06-14 20:34:10 +00:00
|
|
|
|
2019-07-24 19:37:24 +00:00
|
|
|
def get_client_resource(self, configuration):
|
|
|
|
"""
|
|
|
|
:return: A static data resource that produces the given configuration when
|
|
|
|
rendered, as an aid to testing.
|
|
|
|
"""
|
2019-08-19 15:21:03 +00:00
|
|
|
items = configuration.items(self._client_section_name, [])
|
2019-11-19 17:56:26 +00:00
|
|
|
resource = Data(
|
2019-08-19 15:21:03 +00:00
|
|
|
dumps(dict(items)),
|
|
|
|
b"text/json",
|
|
|
|
)
|
2019-11-19 17:56:26 +00:00
|
|
|
# Give it some dynamic stuff too.
|
|
|
|
resource.putChild(b"counter", GetCounter())
|
|
|
|
return resource
|
|
|
|
|
|
|
|
|
|
|
|
class GetCounter(Resource):
|
2019-11-26 12:49:25 +00:00
|
|
|
"""
|
|
|
|
``GetCounter`` is a resource that returns a count of the number of times
|
|
|
|
it has rendered a response to a GET request.
|
|
|
|
|
|
|
|
:ivar int value: The number of ``GET`` requests rendered so far.
|
|
|
|
"""
|
2019-11-19 17:56:26 +00:00
|
|
|
value = 0
|
|
|
|
def render_GET(self, request):
|
|
|
|
self.value += 1
|
|
|
|
return dumps({"value": self.value})
|
2019-07-24 19:37:24 +00:00
|
|
|
|
2019-06-14 20:34:10 +00:00
|
|
|
|
|
|
|
@implementer(RIDummy)
|
|
|
|
@attr.s(cmp=True, hash=True)
|
|
|
|
class DummyStorageServer(object):
|
|
|
|
# TODO Requirement of some interface that instances be hashable
|
|
|
|
get_anonymous_storage_server = attr.ib(cmp=False)
|
|
|
|
|
|
|
|
def remote_just_some_method(self):
|
|
|
|
pass
|
2019-06-28 12:52:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
@implementer(IStorageServer)
|
|
|
|
@attr.s
|
|
|
|
class DummyStorageClient(object):
|
2019-07-03 16:08:58 +00:00
|
|
|
get_rref = attr.ib()
|
|
|
|
configuration = attr.ib()
|
|
|
|
announcement = attr.ib()
|