From f0ce20703d2cb8dbf899b9768c3cbbd14ee60594 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 6 Dec 2017 14:42:46 -0600 Subject: 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 --- os_client_config/cloud_config.py | 8 +++++--- os_client_config/tests/test_cloud_config.py | 7 +++++++ 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) -- cgit v1.2.1