Parse stack output value for bay

To retrieve a k8s address correctly, this parses stack output values.
Sequence of outputs seems have no particular order.

Change-Id: I2ab74528a0914d4bd63ce65a5c62211ccc6d723a
This commit is contained in:
OTSUKA, Yuanying 2015-01-13 09:19:54 +09:00
parent 596233a2b4
commit cdd963fd2d
2 changed files with 51 additions and 3 deletions

View File

@ -83,6 +83,22 @@ def _create_stack(ctxt, osc, bay):
return created_stack
def _parse_stack_outputs(outputs):
parsed_outputs = {}
for output in outputs:
output_key = output["output_key"]
output_value = output["output_value"]
if output_key == "kube_minions_external":
parsed_outputs["kube_minions_external"] = output_value
if output_key == "kube_minions":
parsed_outputs["kube_minions"] = output_value
if output_key == "kube_master":
parsed_outputs["kube_master"] = output_value
return parsed_outputs
class Handler(object):
def __init__(self):
super(Handler, self).__init__()
@ -104,10 +120,11 @@ class Handler(object):
def poll_and_check():
stack = osc.heat().stacks.get(bay.stack_id)
if stack.stack_status == 'CREATE_COMPLETE':
master_address = stack.outputs[0]['output_value']
minion_addresses = stack.outputs[2]['output_value']
parsed_outputs = _parse_stack_outputs(stack.outputs)
master_address = parsed_outputs["kube_master"]
minion_address = parsed_outputs["kube_minions_external"]
bay.master_address = master_address
bay.minions_address = minion_addresses
bay.minions_address = minion_address
bay.save()
raise loopingcall.LoopingCallDone()
# poll_and_check is detached and polling long time to check status,

View File

@ -106,6 +106,37 @@ class TestBayK8sHeat(base.BaseTestCase):
}
self.assertEqual(expected, bay_definition)
def test_parse_stack_outputs(self):
expected_master_address = 'master_address'
expected_minion_address = ['minion', 'address']
expected_minion_external_address = ['ex_minion', 'address']
expected_return_value = {
'kube_master': expected_master_address,
'kube_minions': expected_minion_address,
'kube_minions_external': expected_minion_external_address
}
outputs = [
{
"output_value": expected_minion_external_address,
"description": "No description given",
"output_key": "kube_minions_external"
},
{
"output_value": expected_minion_address,
"description": "No description given",
"output_key": "kube_minions"
},
{
"output_value": expected_master_address,
"description": "No description given",
"output_key": "kube_master"
}
]
parsed_outputs = bay_k8s_heat._parse_stack_outputs(outputs)
self.assertEqual(expected_return_value, parsed_outputs)
@patch('heatclient.common.template_utils.get_template_contents')
@patch('magnum.objects.BayModel.get_by_uuid')
@patch('magnum.conductor.handlers.bay_k8s_heat._extract_bay_definition')