From 4878202c0e2a404c0b38b8db53728dde98403797 Mon Sep 17 00:00:00 2001 From: hardik Date: Wed, 24 Feb 2016 11:48:30 +0900 Subject: [PATCH] Fixed 'workflow_name' key error when workflow execution is created by workflow_id 'workflow_name' key error was raised. Now 'workflow_name' is extracted from dictionary using get() function. Change-Id: I5a648742b2653818d3bc4d4025ce1fe0b73a2d24 Closes-bug: #1549047 --- mistral/api/controllers/v2/execution.py | 2 +- mistral_tempest_tests/services/base.py | 8 ++++++-- .../tests/api/v2/test_mistral_basic_v2.py | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mistral/api/controllers/v2/execution.py b/mistral/api/controllers/v2/execution.py index 83654b99c..0ddcaefb4 100644 --- a/mistral/api/controllers/v2/execution.py +++ b/mistral/api/controllers/v2/execution.py @@ -232,7 +232,7 @@ class ExecutionsController(rest.RestController): ) result = engine.start_workflow( - exec_dict.get('workflow_id', exec_dict['workflow_name']), + exec_dict.get('workflow_id', exec_dict.get('workflow_name')), exec_dict.get('input'), exec_dict.get('description', ''), **exec_dict.get('params') or {} diff --git a/mistral_tempest_tests/services/base.py b/mistral_tempest_tests/services/base.py index 790f6b80a..121c563c5 100644 --- a/mistral_tempest_tests/services/base.py +++ b/mistral_tempest_tests/services/base.py @@ -19,6 +19,7 @@ import time import mock import six +from oslo_utils import uuidutils from tempest import clients from tempest import config from tempest import test as test @@ -164,8 +165,11 @@ class MistralClientV2(MistralClientBase): return resp, json.loads(body) - def create_execution(self, wf_name, wf_input=None, params=None): - body = {"workflow_name": "%s" % wf_name} + def create_execution(self, identifier, wf_input=None, params=None): + if uuidutils.is_uuid_like(identifier): + body = {"workflow_id": "%s" % identifier} + else: + body = {"workflow_name": "%s" % identifier} if wf_input: body.update({'input': json.dumps(wf_input)}) diff --git a/mistral_tempest_tests/tests/api/v2/test_mistral_basic_v2.py b/mistral_tempest_tests/tests/api/v2/test_mistral_basic_v2.py index be60cf6b3..f43d26087 100644 --- a/mistral_tempest_tests/tests/api/v2/test_mistral_basic_v2.py +++ b/mistral_tempest_tests/tests/api/v2/test_mistral_basic_v2.py @@ -408,6 +408,7 @@ class ExecutionTestsV2(base.TestCase): self.direct_wf_name = 'wf' self.direct_wf2_name = 'wf2' + self.direct_wf_id = body['workflows'][0]['id'] reverse_wfs = [wf for wf in body['workflows'] if wf['name'] == 'wf1'] self.reverse_wf = reverse_wfs[0] @@ -516,6 +517,20 @@ class ExecutionTestsV2(base.TestCase): self.assertEqual(200, resp.status) self.assertEqual('SUCCESS', body['state']) + @test.attr(type='sanity') + def test_create_execution_by_wf_id(self): + resp, body = self.client.create_execution(self.direct_wf_id) + exec_id = body['id'] + self.assertEqual(201, resp.status) + self.assertEqual(self.direct_wf_id, body['workflow_id']) + self.assertEqual('RUNNING', body['state']) + + resp, body = self.client.get_list_obj('executions') + self.assertIn( + exec_id, + [ex_id['id'] for ex_id in body['executions']] + ) + @test.attr(type='sanity') def test_get_execution(self): _, execution = self.client.create_execution(self.direct_wf_name)