Stop calling get_all_types when service-type is None

If service_type=None makes it all the way here, there is really no need
to call get_all_types.

Story: 2003314
Change-Id: I04a4857a4ba131cc9aa05831ddc0c2d3d67903fd
This commit is contained in:
Monty Taylor 2018-08-06 11:05:00 -05:00
parent 48bda1cbc3
commit 23ace6b1b9
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 17 additions and 0 deletions

View File

@ -229,6 +229,9 @@ class CloudRegion(object):
If none of that works, it returns the value in ``default``.
'''
if service_type is None:
return self.config.get(key)
for st in self._service_type_manager.get_all_types(service_type):
value = self.config.get(_make_key(key, st))
if value is not None:

View File

@ -85,6 +85,20 @@ class TestCloudRegion(base.TestCase):
cc2 = cloud_region.CloudRegion("test1", "region-al", {})
self.assertNotEqual(cc1, cc2)
def test_get_config(self):
cc = cloud_region.CloudRegion("test1", "region-al", fake_services_dict)
self.assertIsNone(cc._get_config('nothing', None))
# This is what is happening behind the scenes in get_default_interface.
self.assertEqual(
fake_services_dict['interface'],
cc._get_config('interface', None))
# The same call as above, but from one step up the stack
self.assertEqual(
fake_services_dict['interface'],
cc.get_interface())
# Which finally is what is called to populate the below
self.assertEqual('public', self.cloud.default_interface)
def test_verify(self):
config_dict = copy.deepcopy(fake_config_dict)
config_dict['cacert'] = None