From 7e5496763522475bb07a377359d69454f1942e1b Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Mon, 4 Jan 2016 12:56:28 -0600 Subject: [PATCH] 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 --- os_client_config/config.py | 2 +- os_client_config/tests/test_config.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/os_client_config/config.py b/os_client_config/config.py index d490006..d366307 100644 --- a/os_client_config/config.py +++ b/os_client_config/config.py @@ -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 = {} diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py index 4440ac8..dce436a 100644 --- a/os_client_config/tests/test_config.py +++ b/os_client_config/tests/test_config.py @@ -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])