Pop domain-id from the config if we infer values

If the user specifies a project_{name,id}, then we currently infer that
a domain_{name,id} is meant to be shorthand for user_domain_{name,id} and
project_domain_{name,id}. However, in other contexts, domain_id is a
perfectly valid value to pass to the auth plugins - such as when doing
domain-scoped activities.

The problem that was uncovered by the correction of argument precedence
is that we didn't pop the domain-id out of the root config dict, so if a
user set OS_DOMAIN_ID in the environment, we were happily setting the
user and project versions, but then leaving domain_id set as well. This
then meant that when we do the pass to pull valid arguments from the
root dict to the auth dict, we also pulled in domain_id - which led to
the error:

  AuthorizationFailure: Authentication cannot be scoped to multiple
  targets. Pick one of: project, domain, trust or unscoped

Popping the value from the root dict causes the things to work as
documented.

Change-Id: I6d208e5ec4115d2e72d30b2fedc90a81ea754d5a
This commit is contained in:
Monty Taylor 2016-08-11 08:14:39 -05:00
parent 600a638e74
commit a6840f69ff
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 3 additions and 0 deletions

View File

@ -562,6 +562,7 @@ class OpenStackConfig(object):
for key in possible_values:
if target_key in cloud['auth'] and key not in cloud['auth']:
cloud['auth'][key] = cloud['auth'][target_key]
cloud.pop(target_key, None)
cloud['auth'].pop(target_key, None)
return cloud

View File

@ -102,6 +102,7 @@ class TestConfig(base.TestCase):
self.assertEqual('123456789', cc.auth['project_domain_id'])
self.assertNotIn('domain_id', cc.auth)
self.assertNotIn('domain-id', cc.auth)
self.assertNotIn('domain_id', cc)
def test_get_one_cloud_domain_scoped(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
@ -118,6 +119,7 @@ class TestConfig(base.TestCase):
self.assertEqual('awesome-domain', cc.auth['user_domain_id'])
self.assertEqual('awesome-domain', cc.auth['project_domain_id'])
self.assertNotIn('domain_id', cc.auth)
self.assertNotIn('domain_id', cc)
def test_get_one_cloud_with_hyphenated_project_id(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],