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
This commit is contained in:
Monty Taylor 2015-03-03 16:09:00 -05:00 committed by Dean Troyer
parent df91dcf111
commit 3b5a20ea03
2 changed files with 37 additions and 11 deletions

View File

@ -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()):

View File

@ -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)