forked from ungleich-public/cdist
Merge pull request #382 from acatton/fix-dir-in-default
Cdist fails silently when there's a directory in __type/parameter/default
This commit is contained in:
commit
f2b1c24ec3
6 changed files with 15 additions and 4 deletions
|
@ -204,11 +204,13 @@ class CdistType(object):
|
||||||
try:
|
try:
|
||||||
defaults_dir = os.path.join(self.absolute_path, "parameter", "default")
|
defaults_dir = os.path.join(self.absolute_path, "parameter", "default")
|
||||||
for name in os.listdir(defaults_dir):
|
for name in os.listdir(defaults_dir):
|
||||||
with open(os.path.join(defaults_dir, name)) as fd:
|
try:
|
||||||
defaults[name] = fd.read().strip()
|
with open(os.path.join(defaults_dir, name)) as fd:
|
||||||
|
defaults[name] = fd.read().strip()
|
||||||
|
except EnvironmentError:
|
||||||
|
pass # Swallow errors raised by open() or read()
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
# error ignored
|
pass # Swallow error raised by os.listdir()
|
||||||
pass
|
|
||||||
finally:
|
finally:
|
||||||
self.__parameter_defaults = defaults
|
self.__parameter_defaults = defaults
|
||||||
return self.__parameter_defaults
|
return self.__parameter_defaults
|
||||||
|
|
|
@ -153,3 +153,10 @@ class TypeTestCase(test.CdistTestCase):
|
||||||
self.assertFalse('optional2' in cdist_type.parameter_defaults)
|
self.assertFalse('optional2' in cdist_type.parameter_defaults)
|
||||||
self.assertEqual(cdist_type.parameter_defaults['optional1'], 'value1')
|
self.assertEqual(cdist_type.parameter_defaults['optional1'], 'value1')
|
||||||
|
|
||||||
|
def test_directory_in_default(self):
|
||||||
|
base_path = fixtures
|
||||||
|
cdist_type = core.CdistType(base_path, '__directory_in_default')
|
||||||
|
self.assertEqual(
|
||||||
|
list(sorted(cdist_type.parameter_defaults.keys())),
|
||||||
|
['bar', 'foo']
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
foo
|
||||||
|
bar
|
Loading…
Reference in a new issue