diff --git a/contrib/heat_mistral/heat_mistral/resources/workflow.py b/contrib/heat_mistral/heat_mistral/resources/workflow.py index 0ece18873f..c58844036b 100644 --- a/contrib/heat_mistral/heat_mistral/resources/workflow.py +++ b/contrib/heat_mistral/heat_mistral/resources/workflow.py @@ -329,12 +329,10 @@ class Workflow(signal_responder.SignalResponder, result_input.update( {key: details.get( self.SIGNAL_DATA_INPUT).get(key) or value}) - if details.get(self.PARAMS) is not None: - for key, value in six.iteritems( - self.properties.get(self.PARAMS)): - result_params.update( - {key: details.get( - self.SIGNAL_DATA_PARAMS).get(key) or value}) + if details.get(self.SIGNAL_DATA_PARAMS) is not None: + if self.properties.get(self.PARAMS) is not None: + result_params.update(self.properties.get(self.PARAMS)) + result_params.update(details.get(self.SIGNAL_DATA_PARAMS)) if not result_input and self.properties.get(self.INPUT): result_input.update(self.properties.get(self.INPUT)) diff --git a/contrib/heat_mistral/heat_mistral/tests/test_workflow.py b/contrib/heat_mistral/heat_mistral/tests/test_workflow.py index b76510e301..3eb58b2ad6 100644 --- a/contrib/heat_mistral/heat_mistral/tests/test_workflow.py +++ b/contrib/heat_mistral/heat_mistral/tests/test_workflow.py @@ -42,6 +42,35 @@ resources: result: <% $.hello %> """ +workflow_template_with_params = """ +heat_template_version: 2013-05-23 +resources: + workflow: + type: OS::Mistral::Workflow + properties: + params: {'test':'param_value'} + type: direct + tasks: + - name: hello + action: std.echo output='Good morning!' + publish: + result: <% $.hello %> +""" +workflow_template_with_params_override = """ +heat_template_version: 2013-05-23 +resources: + workflow: + type: OS::Mistral::Workflow + properties: + params: {'test':'param_value_override','test1':'param_value_override_1'} + type: direct + tasks: + - name: hello + action: std.echo output='Good morning!' + publish: + result: <% $.hello %> +""" + workflow_template_full = """ heat_template_version: 2013-05-23 resources: @@ -141,13 +170,11 @@ resources: class FakeWorkflow(object): - def __init__(self, name): self.name = name class TestWorkflow(common.HeatTestCase): - def setUp(self): super(TestWorkflow, self).setUp() utils.setup_dummy_db() @@ -398,3 +425,56 @@ class TestWorkflow(common.HeatTestCase): scheduler.TaskRunner(wf.delete)() self.assertEqual(1, self.mistral.executions.delete.call_count) self.assertEqual((wf.DELETE, wf.COMPLETE), wf.state) + + def test_workflow_params(self): + tmpl = template_format.parse(workflow_template_full) + stack = utils.parse_stack(tmpl) + rsrc_defns = stack.t.resource_definitions(stack)['create_vm'] + wf = workflow.Workflow('create_vm', rsrc_defns, stack) + self.mistral.workflows.create.return_value = [ + FakeWorkflow('create_vm')] + scheduler.TaskRunner(wf.create)() + details = {'input': {'flavor': '3'}, + 'params': {'test': 'param_value', 'test1': 'param_value_1'}} + execution = mock.Mock() + execution.id = '12345' + self.mistral.executions.create.side_effect = ( + lambda *args, **kw: self.verify_params(*args, **kw)) + scheduler.TaskRunner(wf.signal, details)() + + def test_workflow_params_merge(self): + tmpl = template_format.parse(workflow_template_with_params) + stack = utils.parse_stack(tmpl) + rsrc_defns = stack.t.resource_definitions(stack)['workflow'] + wf = workflow.Workflow('workflow', rsrc_defns, stack) + self.mistral.workflows.create.return_value = [ + FakeWorkflow('workflow')] + scheduler.TaskRunner(wf.create)() + details = {'params': {'test1': 'param_value_1'}} + execution = mock.Mock() + execution.id = '12345' + self.mistral.executions.create.side_effect = ( + lambda *args, **kw: self.verify_params(*args, **kw)) + scheduler.TaskRunner(wf.signal, details)() + + def test_workflow_params_override(self): + tmpl = template_format.parse(workflow_template_with_params_override) + stack = utils.parse_stack(tmpl) + rsrc_defns = stack.t.resource_definitions(stack)['workflow'] + wf = workflow.Workflow('workflow', rsrc_defns, stack) + self.mistral.workflows.create.return_value = [ + FakeWorkflow('workflow')] + scheduler.TaskRunner(wf.create)() + details = {'params': {'test': 'param_value', 'test1': 'param_value_1'}} + execution = mock.Mock() + execution.id = '12345' + self.mistral.executions.create.side_effect = ( + lambda *args, **kw: self.verify_params(*args, **kw)) + scheduler.TaskRunner(wf.signal, details)() + + def verify_params(self, workflow_name, workflow_input=None, **params): + self.assertEqual({'test': 'param_value', 'test1': 'param_value_1'}, + params) + execution = mock.Mock() + execution.id = '12345' + return execution