A little closer to passing.

This commit is contained in:
Itamar Turner-Trauring 2020-10-12 13:50:32 -04:00
parent dcdce83883
commit 57cda41daa
5 changed files with 28 additions and 19 deletions

View File

@ -781,7 +781,7 @@ class _Client(node.Node, pollmixin.PollMixin):
vk_string = ed25519.string_from_verifying_key(self._node_public_key)
vk_bytes = remove_prefix(vk_string, ed25519.PUBLIC_KEY_PREFIX)
seed = base32.b2a(vk_bytes)
self.config.write_config_file("permutation-seed", seed+"\n")
self.config.write_config_file("permutation-seed", seed+b"\n", mode="wb")
return seed.strip()
def get_anonymous_storage_server(self):
@ -806,7 +806,7 @@ class _Client(node.Node, pollmixin.PollMixin):
config_storedir = self.get_config(
"storage", "storage_dir", self.STOREDIR,
).decode('utf-8')
)
storedir = self.config.get_config_path(config_storedir)
data = self.config.get_config("storage", "reserved_space", None)
@ -1021,7 +1021,7 @@ class _Client(node.Node, pollmixin.PollMixin):
c = ControlServer()
c.setServiceParent(self)
control_url = self.control_tub.registerReference(c)
self.config.write_private_config("control.furl", control_url + b"\n")
self.config.write_private_config("control.furl", (control_url + "\n").encode("utf-8"))
def init_helper(self):
self.helper = Helper(self.config.get_config_path("helper"),

View File

@ -549,8 +549,11 @@ def _convert_tub_port(s):
:returns: a proper Twisted endpoint string like (`tcp:X`) is `s`
is a bare number, or returns `s` as-is
"""
if re.search(r'^\d+$', s):
return "tcp:{}".format(int(s))
us = s
if isinstance(s, bytes):
us = s.decode("utf-8")
if re.search(r'^\d+$', us):
return "tcp:{}".format(int(us))
return s

View File

@ -109,24 +109,24 @@ class StorageClientConfig(object):
:param _Config config: The loaded Tahoe-LAFS node configuration.
"""
ps = config.get_config("client", "peers.preferred", b"").split(b",")
preferred_peers = tuple([p.strip() for p in ps if p != b""])
ps = config.get_config("client", "peers.preferred", "").split(",")
preferred_peers = tuple([p.strip() for p in ps if p != ""])
enabled_storage_plugins = (
name.strip()
for name
in config.get_config(
b"client",
b"storage.plugins",
b"",
).decode("utf-8").split(u",")
"client",
"storage.plugins",
"",
).split(",")
if name.strip()
)
storage_plugins = {}
for plugin_name in enabled_storage_plugins:
try:
plugin_config = config.items(b"storageclient.plugins." + plugin_name)
plugin_config = config.items("storageclient.plugins." + plugin_name)
except NoSectionError:
plugin_config = []
storage_plugins[plugin_name] = dict(plugin_config)
@ -264,6 +264,7 @@ class StorageFarmBroker(service.MultiService):
# these two are used in unit tests
def test_add_rref(self, serverid, rref, ann):
assert isinstance(serverid, bytes)
s = self._make_storage_server(
serverid.decode("ascii"),
{"ann": ann.copy()},
@ -273,6 +274,7 @@ class StorageFarmBroker(service.MultiService):
self.servers[serverid] = s
def test_add_server(self, server_id, s):
assert isinstance(server_id, bytes)
s.on_status_changed(lambda _: self._got_connection())
self.servers[server_id] = s
@ -313,6 +315,7 @@ class StorageFarmBroker(service.MultiService):
{u"ann": ann},
)
server_id = s.get_serverid()
assert isinstance(server_id, bytes)
old = self.servers.get(server_id)
if old:
if old.get_announcement() == ann:
@ -335,6 +338,7 @@ class StorageFarmBroker(service.MultiService):
# almost always be the case for normal runtime).
# now we forget about them and start using the new one
s.setServiceParent(self)
assert isinstance(server_id, bytes)
self.servers[server_id] = s
s.start_connecting(self._trigger_connections)
# the descriptor will manage their own Reconnector, and each time we
@ -373,11 +377,13 @@ class StorageFarmBroker(service.MultiService):
return frozenset(self.servers.values())
def get_nickname_for_serverid(self, serverid):
assert isinstance(serverid, bytes)
if serverid in self.servers:
return self.servers[serverid].get_nickname()
return None
def get_stub_server(self, serverid):
assert isinstance(serverid, bytes)
if serverid in self.servers:
return self.servers[serverid]
# some time before 1.12, we changed "serverid" to be "key_s" (the
@ -504,7 +510,7 @@ class _FoolscapStorage(object):
if isinstance(seed, unicode):
seed = seed.encode("utf-8")
ps = base32.a2b(seed)
elif re.search(r'^v0-[0-9a-zA-Z]{52}$', server_id):
elif re.search(br'^v0-[0-9a-zA-Z]{52}$', server_id):
ps = base32.a2b(server_id[3:])
else:
log.msg("unable to parse serverid '%(server_id)s as pubkey, "

View File

@ -243,7 +243,7 @@ class UseNode(object):
[storageclient.plugins.{storage_plugin}]
{config}
""".format(
storage_plugin=self.storage_plugin,
storage_plugin=self.storage_plugin.decode("ascii"),
config=format_config_items(self.plugin_config),
)
@ -259,8 +259,8 @@ introducer.furl = {furl}
storage.plugins = {storage_plugin}
{plugin_config_section}
""".format(
furl=self.introducer_furl,
storage_plugin=self.storage_plugin,
furl=self.introducer_furl.decode("ascii"),
storage_plugin=self.storage_plugin.decode("ascii"),
node_config=format_config_items(self.node_config),
plugin_config_section=plugin_config_section,
)

View File

@ -280,7 +280,7 @@ class PluginMatchedAnnouncement(SyncTestCase):
configuration is matched and the plugin's storage client is used.
"""
plugin_config = {
b"abc": b"xyz",
"abc": "xyz",
}
plugin_name = b"tahoe-lafs-dummy-v1"
yield self.make_node(
@ -293,7 +293,7 @@ class PluginMatchedAnnouncement(SyncTestCase):
u"service-name": u"storage",
u"storage-options": [{
# and this announcement is for a plugin with a matching name
u"name": plugin_name,
u"name": plugin_name.decode("ascii"),
u"storage-server-FURL": SOME_FURL.decode("ascii"),
}],
}
@ -344,7 +344,7 @@ class PluginMatchedAnnouncement(SyncTestCase):
u"service-name": u"storage",
u"storage-options": [{
# and this announcement is for a plugin with a matching name
u"name": plugin_name,
u"name": plugin_name.decode("ascii"),
u"storage-server-FURL": SOME_FURL.decode("ascii"),
}],
}