mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-20 09:46:18 +00:00
windows yaml.safe_load returns None on unreadable files..
This commit is contained in:
parent
7d34f8f1a1
commit
1ad2174df9
@ -1,7 +1,7 @@
|
||||
import os, stat, time, weakref
|
||||
from base64 import urlsafe_b64encode
|
||||
from functools import partial
|
||||
from errno import ENOENT
|
||||
from errno import ENOENT, EPERM
|
||||
|
||||
from zope.interface import implementer
|
||||
from twisted.internet import reactor, defer
|
||||
@ -297,7 +297,11 @@ def create_introducer_clients(config, main_tub):
|
||||
with introducers_filepath.open() as f:
|
||||
introducers_yaml = yamlutil.safe_load(f)
|
||||
if introducers_yaml is None:
|
||||
introducers_yaml = {}
|
||||
raise EnvironmentError(
|
||||
EPERM,
|
||||
"Can't read '{}'".format(introducers_yaml_filename),
|
||||
introducers_yaml_filename,
|
||||
)
|
||||
introducers = introducers_yaml.get("introducers", {})
|
||||
log.msg(
|
||||
"found {} introducers in private/introducers.yaml".format(
|
||||
|
@ -59,13 +59,18 @@ class Node(testutil.SignalMixin, testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
|
||||
def test_introducer_clients_unloadable(self):
|
||||
"""
|
||||
If introducers.yaml exists but we can't read it for some reason
|
||||
we'll ignore it.
|
||||
Error if introducers.yaml exists but we can't read it
|
||||
"""
|
||||
basedir = "introducer.IntroducerNode.test_introducer_clients_unloadable"
|
||||
basedir = u"introducer.IntroducerNode.test_introducer_clients_unloadable"
|
||||
os.mkdir(basedir)
|
||||
os.mkdir(os.path.join(basedir, u"private"))
|
||||
yaml_fname = os.path.join(basedir, u"private", u"introducers.yaml")
|
||||
with open(yaml_fname, 'w') as f:
|
||||
f.write(u'---\n')
|
||||
os.chmod(yaml_fname, 0o000)
|
||||
self.addCleanup(lambda: os.chmod(yaml_fname, 0o700))
|
||||
# just mocking the yaml failure, as "yamlutil.safe_load" only
|
||||
# returns None on some platforms
|
||||
# returns None on some platforms for unreadable files
|
||||
|
||||
with patch("allmydata.client.yamlutil") as p:
|
||||
p.safe_load = Mock(return_value=None)
|
||||
@ -73,8 +78,8 @@ class Node(testutil.SignalMixin, testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
fake_tub = Mock()
|
||||
config = read_config(basedir, "portnum")
|
||||
|
||||
ic = create_introducer_clients(config, fake_tub)
|
||||
self.assertEqual([], ic)
|
||||
with self.assertRaises(EnvironmentError) as ctx:
|
||||
create_introducer_clients(config, fake_tub)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_furl(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user