summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2017-12-06 14:42:46 -0600
committerMonty Taylor <mordred@inaugust.com>2017-12-08 09:29:27 -0600
commitf0ce20703d2cb8dbf899b9768c3cbbd14ee60594 (patch)
tree458a1e8ce6abe1f9c26dfc44939df6ae6d6a4fe5
parent1cb33d4bc97d9ca58c8ff231225be13e82aa1905 (diff)
downloados-client-config-f0ce20703d2cb8dbf899b9768c3cbbd14ee60594.tar.gz
Make the get_service_type() overrides tolernat of no defaults
The service type overrides in get_service_type() fail if the API version keys are not present in the config dict, which happens when CloudConfig is created without reading defaults. Change-Id: I8d035cfd1afc1cad01ceac7cd643568e94897e27
-rw-r--r--os_client_config/cloud_config.py8
-rw-r--r--os_client_config/tests/test_cloud_config.py7
2 files changed, 12 insertions, 3 deletions
diff --git a/os_client_config/cloud_config.py b/os_client_config/cloud_config.py
index d1a6983..0d82ebf 100644
--- a/os_client_config/cloud_config.py
+++ b/os_client_config/cloud_config.py
@@ -167,12 +167,14 @@ class CloudConfig(object):
# What's even more amazing is that they did it AGAIN with cinder v3
# And then I learned that mistral copied it.
if service_type == 'volume':
- if self.get_api_version(service_type).startswith('2'):
+ vol_type = self.get_api_version(service_type)
+ if vol_type and vol_type.startswith('2'):
service_type = 'volumev2'
- elif self.get_api_version(service_type).startswith('3'):
+ elif vol_type and vol_type.startswith('3'):
service_type = 'volumev3'
elif service_type == 'workflow':
- if self.get_api_version(service_type).startswith('2'):
+ wk_type = self.get_api_version(service_type)
+ if wk_type and wk_type.startswith('2'):
service_type = 'workflowv2'
return self.config.get(key, service_type)
diff --git a/os_client_config/tests/test_cloud_config.py b/os_client_config/tests/test_cloud_config.py
index 8135526..86a71e2 100644
--- a/os_client_config/tests/test_cloud_config.py
+++ b/os_client_config/tests/test_cloud_config.py
@@ -167,6 +167,13 @@ class TestCloudConfig(base.TestCase):
cc.config['workflow_api_version'] = '2'
self.assertEqual('workflowv2', cc.get_service_type('workflow'))
+ def test_no_override(self):
+ """Test no override happens when defaults are not configured"""
+ cc = cloud_config.CloudConfig("test1", "region-al", fake_services_dict)
+ self.assertEqual('volume', cc.get_service_type('volume'))
+ self.assertEqual('workflow', cc.get_service_type('workflow'))
+ self.assertEqual('not-exist', cc.get_service_type('not-exist'))
+
def test_get_session_no_auth(self):
config_dict = defaults.get_defaults()
config_dict.update(fake_services_dict)