diff options
author | Monty Taylor <mordred@inaugust.com> | 2015-03-03 16:09:00 -0500 |
---|---|---|
committer | Dean Troyer <dtroyer@gmail.com> | 2015-03-04 23:37:04 -0600 |
commit | 3b5a20ea037c8e01f5da2f98e9e47082cefad89e (patch) | |
tree | 3db5606051d97c074f6216ed5804f484633bd719 | |
parent | df91dcf111a7aeecad948481fc102bedd3fad05d (diff) | |
download | os-client-config-3b5a20ea037c8e01f5da2f98e9e47082cefad89e.tar.gz |
Handle project_name/tenant_name in the auth dict
We were doing backwards compat for project/tenant in a way that didn't
notice anything in the auth dict - which is there project/tenant info
goes. Ooops.
Change-Id: I141c1d99f31f381898bf993c4e7fcab1078f40c6
-rw-r--r-- | os_client_config/config.py | 26 | ||||
-rw-r--r-- | os_client_config/tests/test_config.py | 22 |
2 files changed, 37 insertions, 11 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py index ecf463a..3565fa6 100644 --- a/os_client_config/config.py +++ b/os_client_config/config.py @@ -164,6 +164,9 @@ class OpenStackConfig(object): # Can't find the requested vendor config, go about business pass + if 'auth' not in cloud: + cloud['auth'] = dict() + _auth_update(cloud, our_cloud) if 'cloud' in cloud: del cloud['cloud'] @@ -171,10 +174,31 @@ class OpenStackConfig(object): return self._fix_backwards_madness(cloud) def _fix_backwards_madness(self, cloud): + cloud = self._fix_backwards_project(cloud) + cloud = self._fix_backwards_auth_plugin(cloud) + return cloud + + def _fix_backwards_project(self, cloud): # Do the lists backwards so that project_name is the ultimate winner mappings = { 'project_name': ('tenant_id', 'project_id', 'tenant_name', 'project_name'), + } + for target_key, possible_values in mappings.items(): + target = None + for key in possible_values: + if key in cloud: + target = cloud[key] + del cloud[key] + if key in cloud['auth']: + target = cloud['auth'][key] + del cloud['auth'][key] + cloud['auth'][target_key] = target + return cloud + + def _fix_backwards_auth_plugin(self, cloud): + # Do the lists backwards so that auth_type is the ultimate winner + mappings = { 'auth_type': ('auth_plugin', 'auth_type'), } for target_key, possible_values in mappings.items(): @@ -299,8 +323,6 @@ class OpenStackConfig(object): args['region_name'] = self._get_region(cloud) config = self._get_base_cloud_config(cloud) - if 'auth' not in config: - config['auth'] = dict() # Can't just do update, because None values take over for (key, val) in iter(args.items()): diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py index b19899a..5ef3048 100644 --- a/os_client_config/tests/test_config.py +++ b/os_client_config/tests/test_config.py @@ -64,19 +64,23 @@ def _write_yaml(obj): class TestConfig(testtools.TestCase): - def test_get_one_cloud(self): - c = config.OpenStackConfig() - self.assertIsInstance(c.get_one_cloud(), cloud_config.CloudConfig) - - def test_get_one_cloud_with_config_files(self): + def setUp(self): + super(TestConfig, self).setUp() self.useFixture(fixtures.NestedTempfile()) conf = dict(USER_CONF) tdir = self.useFixture(fixtures.TempDir()) conf['cache']['path'] = tdir.path - cloud_yaml = _write_yaml(conf) - vendor_yaml = _write_yaml(VENDOR_CONF) - c = config.OpenStackConfig(config_files=[cloud_yaml], - vendor_files=[vendor_yaml]) + self.cloud_yaml = _write_yaml(conf) + self.vendor_yaml = _write_yaml(VENDOR_CONF) + + def test_get_one_cloud(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) + self.assertIsInstance(c.get_one_cloud(), cloud_config.CloudConfig) + + def test_get_one_cloud_with_config_files(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) self.assertIsInstance(c.cloud_config, dict) self.assertIn('cache', c.cloud_config) self.assertIsInstance(c.cloud_config['cache'], dict) |