Merge "Add guard checks in _get_cpid_from_keystone."
This commit is contained in:
commit
1c7db8829e
@ -190,7 +190,15 @@ class RefstackClient:
|
|||||||
token = client.auth_ref
|
token = client.auth_ref
|
||||||
for service in token['serviceCatalog']:
|
for service in token['serviceCatalog']:
|
||||||
if service['type'] == 'identity':
|
if service['type'] == 'identity':
|
||||||
return service['endpoints'][0]['id']
|
if 'endpoints' in service and \
|
||||||
|
len(service['endpoints']) > 0:
|
||||||
|
return service['endpoints'][0]['id']
|
||||||
|
else:
|
||||||
|
message = "Unable to retrieve CPID. " + \
|
||||||
|
"Identity service endpoint was " + \
|
||||||
|
"not found in Keystone v2 catalog."
|
||||||
|
self.logger.error(message)
|
||||||
|
raise RuntimeError(message)
|
||||||
elif auth_version == 'v3':
|
elif auth_version == 'v3':
|
||||||
args['auth_url'] = conf_file.get('identity', 'uri_v3')
|
args['auth_url'] = conf_file.get('identity', 'uri_v3')
|
||||||
if conf_file.has_option('identity', 'domain_name'):
|
if conf_file.has_option('identity', 'domain_name'):
|
||||||
@ -204,8 +212,15 @@ class RefstackClient:
|
|||||||
client = ksclient3.Client(**args)
|
client = ksclient3.Client(**args)
|
||||||
token = client.auth_ref
|
token = client.auth_ref
|
||||||
for service in token['catalog']:
|
for service in token['catalog']:
|
||||||
if service['type'] == 'identity':
|
if service['type'] == 'identity' and \
|
||||||
return service['id']
|
'id' in service and service['id'] is not None:
|
||||||
|
return service['id']
|
||||||
|
else:
|
||||||
|
message = "Unable to retrive CPID. " + \
|
||||||
|
"Identity service ID was not " + \
|
||||||
|
"found in Keystone v3 catalog."
|
||||||
|
self.logger.error(message)
|
||||||
|
raise RuntimeError(message)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Auth_version %s is unsupported'
|
raise ValueError('Auth_version %s is unsupported'
|
||||||
'' % auth_version)
|
'' % auth_version)
|
||||||
|
@ -94,6 +94,33 @@ class TestRefstackClient(unittest.TestCase):
|
|||||||
return_value=self.mock_ks3_client
|
return_value=self.mock_ks3_client
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def mock_keystone_with_wrong_service(self):
|
||||||
|
"""
|
||||||
|
Mock the Keystone client methods.
|
||||||
|
"""
|
||||||
|
self.mock_identity_service_v2 = {'type': 'identity',
|
||||||
|
'endpoints': []}
|
||||||
|
self.mock_identity_service_v3 = {'type': 'identity',
|
||||||
|
'id': None}
|
||||||
|
self.mock_ks2_client = MagicMock(
|
||||||
|
name='ks_client',
|
||||||
|
**{'auth_ref':
|
||||||
|
{'serviceCatalog': [self.mock_identity_service_v2]}}
|
||||||
|
)
|
||||||
|
self.mock_ks3_client = MagicMock(
|
||||||
|
name='ks_client',
|
||||||
|
**{'auth_ref':
|
||||||
|
{'catalog': [self.mock_identity_service_v3]}}
|
||||||
|
)
|
||||||
|
self.ks2_client_builder = self.patch(
|
||||||
|
'refstack_client.refstack_client.ksclient2.Client',
|
||||||
|
return_value=self.mock_ks2_client
|
||||||
|
)
|
||||||
|
self.ks3_client_builder = self.patch(
|
||||||
|
'refstack_client.refstack_client.ksclient3.Client',
|
||||||
|
return_value=self.mock_ks3_client
|
||||||
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Test case setup
|
Test case setup
|
||||||
@ -329,6 +356,34 @@ class TestRefstackClient(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual('test-id', cpid)
|
self.assertEqual('test-id', cpid)
|
||||||
|
|
||||||
|
def test_get_cpid_from_keystone_v2_exits(self):
|
||||||
|
"""
|
||||||
|
Test getting the CPID from keystone API v2 exits with wrong service.
|
||||||
|
"""
|
||||||
|
argv = self.mock_argv()
|
||||||
|
args = rc.parse_cli_args(argv)
|
||||||
|
client = rc.RefstackClient(args)
|
||||||
|
client.tempest_dir = self.test_path
|
||||||
|
client._prep_test()
|
||||||
|
self.mock_keystone_with_wrong_service()
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
client._get_cpid_from_keystone(client.conf)
|
||||||
|
|
||||||
|
def test_get_cpid_from_keystone_v3_exits(self):
|
||||||
|
"""
|
||||||
|
Test getting the CPID from keystone API v3 exits.
|
||||||
|
"""
|
||||||
|
args = rc.parse_cli_args(self.mock_argv())
|
||||||
|
client = rc.RefstackClient(args)
|
||||||
|
client.tempest_dir = self.test_path
|
||||||
|
client._prep_test()
|
||||||
|
client.conf.remove_option('identity', 'tenant_id')
|
||||||
|
client.conf.set('identity', 'tenant_name', 'tenant_name')
|
||||||
|
client.conf.set('identity-feature-enabled', 'api_v3', 'true')
|
||||||
|
self.mock_keystone_with_wrong_service()
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
client._get_cpid_from_keystone(client.conf)
|
||||||
|
|
||||||
def test_form_result_content(self):
|
def test_form_result_content(self):
|
||||||
"""
|
"""
|
||||||
Test that the request content is formed into the expected format.
|
Test that the request content is formed into the expected format.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user