Support multiple plugins

This commit is contained in:
Jean-Paul Calderone 2019-06-14 17:54:35 -04:00
parent 646cd452b9
commit e2982c0129
4 changed files with 58 additions and 6 deletions

View File

@ -635,11 +635,11 @@ class _Client(node.Node, pollmixin.PollMixin):
"""
Get the names of storage plugins that are enabled in the configuration.
"""
return {
return set(
self.config.get_config(
"storage", "plugins", b""
).decode("ascii")
}
).decode("ascii").split(u",")
)
def _collect_storage_plugins(self, storage_plugin_names):
@ -668,7 +668,11 @@ class _Client(node.Node, pollmixin.PollMixin):
),
)
for plugin
in plugins
# The order is fairly arbitrary and it is not meant to convey
# anything but providing *some* stable ordering makes the data a
# little easier to deal with (mainly in tests and when manually
# inspecting it).
in sorted(plugins, key=lambda p: p.name)
)

View File

@ -8,4 +8,5 @@ from allmydata.test.storage_plugin import (
adoptedEndpointParser = AdoptedServerPort()
dummyStorage = DummyStorage()
dummyStoragev1 = DummyStorage(u"tahoe-lafs-dummy-v1")
dummyStoragev2 = DummyStorage(u"tahoe-lafs-dummy-v2")

View File

@ -33,8 +33,9 @@ class RIDummy(RemoteInterface):
@implementer(IFoolscapStoragePlugin)
@attr.s
class DummyStorage(object):
name = u"tahoe-lafs-dummy-v1"
name = attr.ib()
def get_storage_server(self, configuration, get_anonymous_storage_server):
return AnnounceableStorageServer(

View File

@ -1187,6 +1187,52 @@ introducer.furl = pb://abcde@nowhere/fake
)
def test_multiple_storage_plugin_announcements(self):
"""
The announcements from several enabled storage plugins are published when
storage is enabled.
"""
self.useFixture(UseTestPlugins())
config = config_from_string(
self.basedir,
u"tub.port",
self.get_config(
storage_enabled=True,
more_storage=b"plugins=tahoe-lafs-dummy-v1,tahoe-lafs-dummy-v2",
more_sections=(
b"[storageserver.plugins.tahoe-lafs-dummy-v1]\n"
b"some = thing-1\n"
b"[storageserver.plugins.tahoe-lafs-dummy-v2]\n"
b"some = thing-2\n"
),
),
)
def matches_dummy_announcement(v):
return MatchesStructure(
service_name=Equals("storage"),
ann=MatchesDict({
# Everyone gets a name and a fURL added to their announcement.
u"name": Equals(u"tahoe-lafs-dummy-v{}".format(v)),
u"storage-server-FURL": matches_furl(),
# The plugin can contribute things, too.
u"value": Equals(u"thing-{}".format(v)),
}),
signing_key=MatchesNodePublicKey(self.basedir),
)
self.assertThat(
client.create_client_from_config(config, introducer_factory=MemoryIntroducerClient),
succeeded(AfterPreprocessing(
get_published_announcements,
MatchesListwise([
matches_anonymous_storage_announcement(self.basedir),
matches_dummy_announcement(b"1"),
matches_dummy_announcement(b"2"),
]),
)),
)
def test_stable_storage_server_furl(self):
"""
The value for the ``storage-server-FURL`` item in the announcement for a