Generate default execution id
When execution id is not sent by the client, the api will generate source execution id Change-Id: Iae1ff327b5cb1af857d53ca53782d9fb30eefc27 Closes-Bug: #1774164
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
from pecan import rest
|
||||
from wsme import types as wtypes
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
@@ -36,7 +37,6 @@ from mistral.utils import merge_dicts
|
||||
from mistral.utils import rest_utils
|
||||
from mistral.workflow import states
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
STATE_TYPES = wtypes.Enum(
|
||||
@@ -228,19 +228,23 @@ class ExecutionsController(rest.RestController):
|
||||
|
||||
exec_id = exec_dict.get('id')
|
||||
|
||||
source_execution_id = exec_dict.get('source_execution_id')
|
||||
|
||||
source_exec_dict = None
|
||||
|
||||
if exec_id:
|
||||
if not exec_id:
|
||||
exec_id = uuidutils.generate_uuid()
|
||||
LOG.debug("Generated execution id [exec_id=%s]", exec_id)
|
||||
exec_dict.update({'id': exec_id})
|
||||
wf_ex = None
|
||||
else:
|
||||
# If ID is present we need to check if such execution exists.
|
||||
# If yes, the method just returns the object. If not, the ID
|
||||
# will be used to create a new execution.
|
||||
wf_ex = _get_workflow_execution(exec_id, must_exist=False)
|
||||
|
||||
if wf_ex:
|
||||
return resources.Execution.from_db_model(wf_ex)
|
||||
|
||||
source_execution_id = exec_dict.get('source_execution_id')
|
||||
|
||||
source_exec_dict = None
|
||||
|
||||
if source_execution_id:
|
||||
# If source execution is present we will perform a lookup for
|
||||
# previous workflow execution model and the information to start
|
||||
@@ -267,7 +271,7 @@ class ExecutionsController(rest.RestController):
|
||||
result_exec_dict.get('workflow_id',
|
||||
result_exec_dict.get('workflow_name')),
|
||||
result_exec_dict.get('workflow_namespace', ''),
|
||||
exec_id,
|
||||
result_exec_dict.get('id'),
|
||||
result_exec_dict.get('input'),
|
||||
description=result_exec_dict.get('description', ''),
|
||||
**result_exec_dict.get('params', {})
|
||||
|
@@ -496,19 +496,16 @@ class TestExecutionsController(base.APITest):
|
||||
self.assertIn(expected_fault, resp.json['faultstring'])
|
||||
|
||||
@mock.patch.object(rpc_clients.EngineClient, 'start_workflow')
|
||||
@mock.patch.object(db_api, 'load_workflow_execution')
|
||||
def test_post_auto_id(self, load_wf_ex_func, start_wf_func):
|
||||
def test_post_auto_id(self, start_wf_func):
|
||||
# NOTE: In fact, we use "white box" testing here to understand
|
||||
# if the REST controller calls other APIs as expected. This is
|
||||
# the only way of testing available with the current testing
|
||||
# infrastructure.
|
||||
start_wf_func.return_value = WF_EX.to_dict()
|
||||
wf_ex_dict = WF_EX.to_dict()
|
||||
start_wf_func.return_value = wf_ex_dict
|
||||
|
||||
json_body = WF_EX_JSON_WITH_DESC.copy()
|
||||
|
||||
# We don't want to pass execution ID in this case.
|
||||
del json_body['id']
|
||||
|
||||
expected_json = WF_EX_JSON_WITH_DESC
|
||||
|
||||
resp = self.app.post_json('/v2/executions', json_body)
|
||||
@@ -516,15 +513,13 @@ class TestExecutionsController(base.APITest):
|
||||
self.assertEqual(201, resp.status_int)
|
||||
self.assertDictEqual(expected_json, resp.json)
|
||||
|
||||
load_wf_ex_func.assert_not_called()
|
||||
|
||||
kwargs = json.loads(expected_json['params'])
|
||||
kwargs['description'] = expected_json['description']
|
||||
|
||||
start_wf_func.assert_called_once_with(
|
||||
expected_json['workflow_id'],
|
||||
'',
|
||||
None,
|
||||
wf_ex_dict['id'],
|
||||
json.loads(expected_json['input']),
|
||||
**kwargs
|
||||
)
|
||||
@@ -630,10 +625,8 @@ class TestExecutionsController(base.APITest):
|
||||
@mock.patch.object(rpc_clients.EngineClient, 'start_workflow')
|
||||
def test_post_with_src_exec_id_without_exec_id(self, wf_exec_mock):
|
||||
source_wf_ex = copy.copy(SOURCE_WF_EX)
|
||||
source_wf_ex.id = ""
|
||||
|
||||
source_wf_ex_json = copy.copy(SOURCE_WF_EX_JSON_WITH_DESC)
|
||||
source_wf_ex_json['id'] = ''
|
||||
|
||||
wf_exec_mock.return_value = source_wf_ex.to_dict()
|
||||
|
||||
@@ -654,7 +647,7 @@ class TestExecutionsController(base.APITest):
|
||||
wf_exec_mock.assert_called_once_with(
|
||||
exec_dict['workflow_id'],
|
||||
'',
|
||||
'',
|
||||
exec_dict['id'],
|
||||
json.loads(exec_dict['input']),
|
||||
description=expected_description,
|
||||
**json.loads(exec_dict['params'])
|
||||
|
Reference in New Issue
Block a user