Fix v2 auth with v3 args present
The translation of the auth arg handling workarounds from OSC missed a detail in the differences between OSC's option Namespace and os-client-config's config dict: the auth args are in a 'auth' sub-dict. Also expanded some of the testing to catch more edge cases. Closes-Bug: 1603479 Change-Id: I80bb42992a1a93857be4c6367405df645780a33d
This commit is contained in:
parent
13850bc044
commit
b1022ac336
@ -65,10 +65,10 @@ class OSC_Config(OpenStackConfig):
|
||||
"""
|
||||
|
||||
if ('auth_type' in config and config['auth_type'].startswith("v2")):
|
||||
if 'project_id' in config:
|
||||
config['tenant_id'] = config['project_id']
|
||||
if 'project_name' in config:
|
||||
config['tenant_name'] = config['project_name']
|
||||
if 'project_id' in config['auth']:
|
||||
config['auth']['tenant_id'] = config['auth']['project_id']
|
||||
if 'project_name' in config['auth']:
|
||||
config['auth']['tenant_name'] = config['auth']['project_name']
|
||||
return config
|
||||
|
||||
def _auth_v2_ignore_v3(self, config):
|
||||
@ -89,7 +89,7 @@ class OSC_Config(OpenStackConfig):
|
||||
'user_domain_name',
|
||||
]
|
||||
for prop in domain_props:
|
||||
if config.pop(prop, None) is not None:
|
||||
if config['auth'].pop(prop, None) is not None:
|
||||
LOG.warning("Ignoring domain related config " +
|
||||
prop + " because identity API version is 2.0")
|
||||
return config
|
||||
@ -113,18 +113,20 @@ class OSC_Config(OpenStackConfig):
|
||||
# NOTE(stevemar): If PROJECT_DOMAIN_ID or PROJECT_DOMAIN_NAME is
|
||||
# present, then do not change the behaviour. Otherwise, set the
|
||||
# PROJECT_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
|
||||
if ('project_domain_id' in config and
|
||||
not config.get('project_domain_id') and
|
||||
not config.get('project_domain_name')):
|
||||
config['project_domain_id'] = default_domain
|
||||
if (
|
||||
not config['auth'].get('project_domain_id') and
|
||||
not config['auth'].get('project_domain_name')
|
||||
):
|
||||
config['auth']['project_domain_id'] = default_domain
|
||||
|
||||
# NOTE(stevemar): If USER_DOMAIN_ID or USER_DOMAIN_NAME is present,
|
||||
# then do not change the behaviour. Otherwise, set the
|
||||
# USER_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
|
||||
if ('user_domain_id' in config and
|
||||
not config.get('user_domain_id') and
|
||||
not config.get('user_domain_name')):
|
||||
config['user_domain_id'] = default_domain
|
||||
if (
|
||||
not config['auth'].get('user_domain_id') and
|
||||
not config['auth'].get('user_domain_name')
|
||||
):
|
||||
config['auth']['user_domain_id'] = default_domain
|
||||
return config
|
||||
|
||||
def auth_config_hook(self, config):
|
||||
|
@ -85,70 +85,101 @@ class TestOSCConfig(utils.TestCase):
|
||||
config = {
|
||||
'identity_api_version': '2',
|
||||
'auth_type': 'v2password',
|
||||
'username': 'fred',
|
||||
'auth': {
|
||||
'username': 'fred',
|
||||
},
|
||||
}
|
||||
ret_config = self.cloud._auth_v2_arguments(config)
|
||||
self.assertEqual('fred', ret_config['username'])
|
||||
self.assertFalse('tenant_id' in ret_config)
|
||||
self.assertFalse('tenant_name' in ret_config)
|
||||
self.assertEqual('fred', ret_config['auth']['username'])
|
||||
self.assertFalse('tenant_id' in ret_config['auth'])
|
||||
self.assertFalse('tenant_name' in ret_config['auth'])
|
||||
|
||||
config = {
|
||||
'identity_api_version': '3',
|
||||
'auth_type': 'v3password',
|
||||
'username': 'fred',
|
||||
'project_id': 'id',
|
||||
'auth': {
|
||||
'username': 'fred',
|
||||
'project_id': 'id',
|
||||
},
|
||||
}
|
||||
ret_config = self.cloud._auth_v2_arguments(config)
|
||||
self.assertEqual('fred', ret_config['username'])
|
||||
self.assertFalse('tenant_id' in ret_config)
|
||||
self.assertFalse('tenant_name' in ret_config)
|
||||
self.assertEqual('fred', ret_config['auth']['username'])
|
||||
self.assertFalse('tenant_id' in ret_config['auth'])
|
||||
self.assertFalse('tenant_name' in ret_config['auth'])
|
||||
|
||||
config = {
|
||||
'identity_api_version': '2',
|
||||
'auth_type': 'v2password',
|
||||
'username': 'fred',
|
||||
'project_id': 'id',
|
||||
'auth': {
|
||||
'username': 'fred',
|
||||
'project_id': 'id',
|
||||
},
|
||||
}
|
||||
ret_config = self.cloud._auth_v2_arguments(config)
|
||||
self.assertEqual('id', ret_config['tenant_id'])
|
||||
self.assertFalse('tenant_name' in ret_config)
|
||||
self.assertEqual('id', ret_config['auth']['tenant_id'])
|
||||
self.assertFalse('tenant_name' in ret_config['auth'])
|
||||
|
||||
config = {
|
||||
'identity_api_version': '2',
|
||||
'auth_type': 'v2password',
|
||||
'username': 'fred',
|
||||
'project_name': 'name',
|
||||
'auth': {
|
||||
'username': 'fred',
|
||||
'project_name': 'name',
|
||||
},
|
||||
}
|
||||
ret_config = self.cloud._auth_v2_arguments(config)
|
||||
self.assertFalse('tenant_id' in ret_config)
|
||||
self.assertEqual('name', ret_config['tenant_name'])
|
||||
self.assertFalse('tenant_id' in ret_config['auth'])
|
||||
self.assertEqual('name', ret_config['auth']['tenant_name'])
|
||||
|
||||
def test_auth_v2_ignore_v3(self):
|
||||
config = {
|
||||
'identity_api_version': '2',
|
||||
'auth_type': 'v2password',
|
||||
'username': 'fred',
|
||||
'project_id': 'id',
|
||||
'project_domain_id': 'bad',
|
||||
'auth': {
|
||||
'username': 'fred',
|
||||
'project_id': 'id',
|
||||
'project_domain_id': 'bad',
|
||||
},
|
||||
}
|
||||
ret_config = self.cloud._auth_v2_ignore_v3(config)
|
||||
self.assertEqual('fred', ret_config['username'])
|
||||
self.assertFalse('project_domain_id' in ret_config)
|
||||
self.assertEqual('fred', ret_config['auth']['username'])
|
||||
self.assertFalse('project_domain_id' in ret_config['auth'])
|
||||
|
||||
def test_auth_config_hook_default_domain(self):
|
||||
def test_auth_default_domain_use_default(self):
|
||||
config = {
|
||||
'identity_api_version': '3',
|
||||
'auth_type': 'admin_token',
|
||||
'auth_type': 'v3password',
|
||||
'default_domain': 'default',
|
||||
'username': 'fred',
|
||||
'project_id': 'id',
|
||||
'project_domain_id': None,
|
||||
'auth': {
|
||||
'username': 'fred',
|
||||
'project_id': 'id',
|
||||
},
|
||||
}
|
||||
ret_config = self.cloud.auth_config_hook(config)
|
||||
self.assertEqual('admin_token', ret_config['auth_type'])
|
||||
ret_config = self.cloud._auth_default_domain(config)
|
||||
self.assertEqual('v3password', ret_config['auth_type'])
|
||||
self.assertEqual('default', ret_config['default_domain'])
|
||||
self.assertEqual('fred', ret_config['username'])
|
||||
self.assertEqual('default', ret_config['project_domain_id'])
|
||||
self.assertEqual('fred', ret_config['auth']['username'])
|
||||
self.assertEqual('default', ret_config['auth']['project_domain_id'])
|
||||
self.assertEqual('default', ret_config['auth']['user_domain_id'])
|
||||
|
||||
def test_auth_default_domain_use_given(self):
|
||||
config = {
|
||||
'identity_api_version': '3',
|
||||
'auth_type': 'v3password',
|
||||
'default_domain': 'default',
|
||||
'auth': {
|
||||
'username': 'fred',
|
||||
'project_id': 'id',
|
||||
'project_domain_id': 'proj',
|
||||
'user_domain_id': 'use'
|
||||
},
|
||||
}
|
||||
ret_config = self.cloud._auth_default_domain(config)
|
||||
self.assertEqual('v3password', ret_config['auth_type'])
|
||||
self.assertEqual('default', ret_config['default_domain'])
|
||||
self.assertEqual('fred', ret_config['auth']['username'])
|
||||
self.assertEqual('proj', ret_config['auth']['project_domain_id'])
|
||||
self.assertEqual('use', ret_config['auth']['user_domain_id'])
|
||||
|
||||
def test_auth_config_hook_default(self):
|
||||
config = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user