summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-05-27 08:14:47 -0400
committerMonty Taylor <mordred@inaugust.com>2015-05-27 12:11:07 -0400
commitf3eb3d47bc51c5c4dbf8a609c27e99cf9abaca53 (patch)
tree2118fd5a333f64b6705261022d2fcace5c9e2dab
parenta5dd46af2ede29580450ffad46ad1888cca4a9ac (diff)
downloados-client-config-f3eb3d47bc51c5c4dbf8a609c27e99cf9abaca53.tar.gz
Normalize all keys down to _ instead of -
It's really common to use the config dict in a **kwargs context. Therefore, normalize every key with a - to use _ instead. Testing for this is done by changing one of the base region_name args to be region-name. Change-Id: Ibd834f7a70cf2285619b5499492858b21635ba57
-rw-r--r--os_client_config/config.py16
-rw-r--r--os_client_config/tests/base.py2
2 files changed, 14 insertions, 4 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py
index 813d0a1..c5b6d9b 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -161,7 +161,17 @@ class OpenStackConfig(object):
for path in filelist:
if os.path.exists(path):
with open(path, 'r') as f:
- return yaml.safe_load(f)
+ return self._normalize_keys(yaml.safe_load(f))
+
+ def _normalize_keys(self, config):
+ new_config = {}
+ for key, value in config.items():
+ key = key.replace('-', '_')
+ if isinstance(value, dict):
+ new_config[key] = self._normalize_keys(value)
+ else:
+ new_config[key] = value
+ return new_config
def get_cache_max_age(self):
return self._cache_max_age
@@ -207,8 +217,8 @@ class OpenStackConfig(object):
profile_name = our_cloud.get('profile', our_cloud.get('cloud', None))
if profile_name:
vendor_file = self._load_vendor_file()
- if vendor_file and profile_name in vendor_file['public-clouds']:
- _auth_update(cloud, vendor_file['public-clouds'][profile_name])
+ if vendor_file and profile_name in vendor_file['public_clouds']:
+ _auth_update(cloud, vendor_file['public_clouds'][profile_name])
else:
try:
_auth_update(cloud, vendors.CLOUD_DEFAULTS[profile_name])
diff --git a/os_client_config/tests/base.py b/os_client_config/tests/base.py
index b6834bf..81b4995 100644
--- a/os_client_config/tests/base.py
+++ b/os_client_config/tests/base.py
@@ -54,7 +54,7 @@ USER_CONF = {
'password': 'testpass',
'project_name': 'testproject',
},
- 'region_name': 'test-region',
+ 'region-name': 'test-region',
},
},
'cache': {'max_age': 1},