Return empty dict instead of None for lack of file

We return None for the file content for non-existent files as a
fallback. This is normally fine, but in the case of a person having
_only_ a secure.conf file, this means that the dictionary merge fails.

Change-Id: I61cc0a8c709ea3510428fc3dfce63dc254c07c83
This commit is contained in:
Monty Taylor 2016-01-04 12:56:28 -06:00
parent a9e139088e
commit 7e54967635
2 changed files with 8 additions and 1 deletions

View File

@ -315,7 +315,7 @@ class OpenStackConfig(object):
return path, json.load(f)
else:
return path, yaml.safe_load(f)
return (None, None)
return (None, {})
def _normalize_keys(self, config):
new_config = {}

View File

@ -171,6 +171,13 @@ class TestConfig(base.TestCase):
self.assertEqual('user', cc.auth['username'])
self.assertEqual('testpass', cc.auth['password'])
def test_only_secure_yaml(self):
c = config.OpenStackConfig(config_files=['nonexistent'],
vendor_files=['nonexistent'],
secure_files=[self.secure_yaml])
cc = c.get_one_cloud(cloud='_test_cloud_no_vendor')
self.assertEqual('testpass', cc.auth['password'])
def test_get_cloud_names(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
secure_files=[self.no_yaml])