Avoid string actions on non-string objects
When config is coming from a clouds.yaml file, Python's yaml parser may turn the version into an int if it is not quoted in the yaml. Ensure that we set the value to a string before interacting with it. Also fix a possible string action on a None object. Change-Id: Ibf02a85d89c95ba76688b3f5c417f861173008d5 Closes-Bug: #1634986
This commit is contained in:
parent
f0d0a4d8b4
commit
fe8b2a798d
|
@ -33,7 +33,7 @@ class OSC_Config(config.OpenStackConfig):
|
|||
Migrated from auth.select_auth_plugin()
|
||||
"""
|
||||
|
||||
identity_version = config.get('identity_api_version', '')
|
||||
identity_version = str(config.get('identity_api_version', ''))
|
||||
|
||||
if config.get('username', None) and not config.get('auth_type', None):
|
||||
if identity_version == '3':
|
||||
|
@ -82,8 +82,8 @@ class OSC_Config(config.OpenStackConfig):
|
|||
# NOTE(hieulq): If USER_DOMAIN_NAME, USER_DOMAIN_ID, PROJECT_DOMAIN_ID
|
||||
# or PROJECT_DOMAIN_NAME is present and API_VERSION is 2.0, then
|
||||
# ignore all domain related configs.
|
||||
if (config.get('identity_api_version', '').startswith('2') and
|
||||
config.get('auth_type', None).endswith('password')):
|
||||
if (str(config.get('identity_api_version', '')).startswith('2') and
|
||||
config.get('auth_type').endswith('password')):
|
||||
domain_props = [
|
||||
'project_domain_id',
|
||||
'project_domain_name',
|
||||
|
@ -102,7 +102,7 @@ class OSC_Config(config.OpenStackConfig):
|
|||
Migrated from clientmanager.setup_auth()
|
||||
"""
|
||||
|
||||
identity_version = config.get('identity_api_version', '')
|
||||
identity_version = str(config.get('identity_api_version', ''))
|
||||
auth_type = config.get('auth_type', None)
|
||||
|
||||
# TODO(mordred): This is a usability improvement that's broadly useful
|
||||
|
|
|
@ -46,6 +46,15 @@ class TestOSCConfig(utils.TestCase):
|
|||
self.assertEqual('v2password', ret_config['auth_type'])
|
||||
self.assertEqual('fred', ret_config['username'])
|
||||
|
||||
def test_auth_select_default_plugin_password_v2_int(self):
|
||||
config = {
|
||||
'identity_api_version': 2,
|
||||
'username': 'fred',
|
||||
}
|
||||
ret_config = self.cloud._auth_select_default_plugin(config)
|
||||
self.assertEqual('v2password', ret_config['auth_type'])
|
||||
self.assertEqual('fred', ret_config['username'])
|
||||
|
||||
def test_auth_select_default_plugin_password_v3(self):
|
||||
config = {
|
||||
'identity_api_version': '3',
|
||||
|
@ -55,6 +64,15 @@ class TestOSCConfig(utils.TestCase):
|
|||
self.assertEqual('v3password', ret_config['auth_type'])
|
||||
self.assertEqual('fred', ret_config['username'])
|
||||
|
||||
def test_auth_select_default_plugin_password_v3_int(self):
|
||||
config = {
|
||||
'identity_api_version': 3,
|
||||
'username': 'fred',
|
||||
}
|
||||
ret_config = self.cloud._auth_select_default_plugin(config)
|
||||
self.assertEqual('v3password', ret_config['auth_type'])
|
||||
self.assertEqual('fred', ret_config['username'])
|
||||
|
||||
def test_auth_select_default_plugin_token(self):
|
||||
config = {
|
||||
'token': 'subway',
|
||||
|
|
Loading…
Reference in New Issue