Refactor stack output fetching

We are duplicating the code to fetch a specific value from the stack
outputs. This adds a get_stack_output_item that can be used to fetch
any named stack output and refactors the other functions that did this
same type of action.

Change-Id: I9f45661d432c47f9df962009cc3c6b9182006d1c
This commit is contained in:
Alex Schultz 2019-05-09 09:05:45 -06:00
parent 48ddd36845
commit fd61c26a65
2 changed files with 46 additions and 13 deletions

View File

@ -613,6 +613,36 @@ class TestCreateTempestDeployerInput(TestCase):
'[volume-feature-enabled]\nbootable = true', cfg)
class TestGetStackOutputItem(TestCase):
def test_get_stack_output_item(self):
stack = mock.MagicMock()
emap = {'KeystonePublic': {'uri': 'http://foo:8000/'}}
stack.to_dict.return_value = {
'outputs': [{'output_key': 'EndpointMap',
'output_value': emap}]
}
endpoint_map = utils.get_stack_output_item(stack, 'EndpointMap')
self.assertEqual(endpoint_map,
{'KeystonePublic': {'uri': 'http://foo:8000/'}})
def test_get_stack_output_item_not_found(self):
stack = mock.MagicMock()
stack.to_dict.return_value = {
'outputs': [{'output_key': 'foo',
'output_value': 'bar'}]
}
val = utils.get_stack_output_item(stack, 'baz')
self.assertEqual(val, None)
def test_get_stack_output_item_no_stack(self):
stack = None
val = utils.get_stack_output_item(stack, 'baz')
self.assertEqual(val, None)
class TestGetEndpointMap(TestCase):
def test_get_endpoint_map(self):

View File

@ -511,10 +511,19 @@ def set_nodes_state(baremetal_client, nodes, transition, target_state,
yield node.uuid
def get_overcloud_endpoint(stack):
def get_stack_output_item(stack, item):
if not stack:
return None
for output in stack.to_dict().get('outputs', {}):
if output['output_key'] == 'KeystoneURL':
if output['output_key'] == item:
return output['output_value']
# item not found in outputs
return None
def get_overcloud_endpoint(stack):
return get_stack_output_item(stack, 'KeystoneURL')
def get_service_ips(stack):
@ -525,24 +534,18 @@ def get_service_ips(stack):
def get_endpoint_map(stack):
endpoint_map = {}
for output in stack.to_dict().get('outputs', {}):
if output['output_key'] == 'EndpointMap':
endpoint_map = output['output_value']
break
endpoint_map = get_stack_output_item(stack, 'EndpointMap')
if not endpoint_map:
endpoint_map = {}
return endpoint_map
def get_blacklisted_ip_addresses(stack):
for output in stack.to_dict().get('outputs', {}):
if output['output_key'] == 'BlacklistedIpAddresses':
return output['output_value']
return get_stack_output_item(stack, 'BlacklistedIpAddresses')
def get_role_net_ip_map(stack):
for output in stack.to_dict().get('outputs', {}):
if output['output_key'] == 'RoleNetIpMap':
return output['output_value']
return get_stack_output_item(stack, 'RoleNetIpMap')
def get_endpoint(key, stack):