From 817a2372671575d264da4a9e8e21b1dcf12ba0cd Mon Sep 17 00:00:00 2001 From: Michal Gershenzon Date: Mon, 28 Nov 2016 18:24:17 +0000 Subject: [PATCH] Filter workflow executions by creating task execution id This will enable the mistral UI to go from task execution screen to the workflow execution screen of the workflow execution created by the task. Change-Id: Ia2ac765a26acc8dcd27134f5f467cddef03fea95 Implements: blueprint filter-workflow-executions-by-creating-task-id --- .../resources/v2/wf_wrapping_wf_v2.yaml | 8 +++++ mistralclient/api/v2/executions.py | 6 +++- mistralclient/commands/v2/executions.py | 8 ++++- .../tests/functional/cli/v2/base_v2.py | 4 +++ .../tests/functional/cli/v2/cli_tests_v2.py | 32 ++++++++++++++++--- .../tests/unit/v2/test_cli_executions.py | 6 ++-- 6 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 functionaltests/resources/v2/wf_wrapping_wf_v2.yaml diff --git a/functionaltests/resources/v2/wf_wrapping_wf_v2.yaml b/functionaltests/resources/v2/wf_wrapping_wf_v2.yaml new file mode 100644 index 00000000..5ac1e37b --- /dev/null +++ b/functionaltests/resources/v2/wf_wrapping_wf_v2.yaml @@ -0,0 +1,8 @@ +--- +version: '2.0' + +wrapping_wf: + type: direct + tasks: + hello: + workflow: wf diff --git a/mistralclient/api/v2/executions.py b/mistralclient/api/v2/executions.py index bafe87d6..4efe37b3 100644 --- a/mistralclient/api/v2/executions.py +++ b/mistralclient/api/v2/executions.py @@ -69,9 +69,13 @@ class ExecutionManager(base.ResourceManager): return self._update('/executions/%s' % id, data) - def list(self, marker='', limit=None, sort_keys='', sort_dirs=''): + def list(self, task=None, marker='', limit=None, sort_keys='', + sort_dirs=''): qparams = {} + if task: + qparams['task_execution_id'] = task + if marker: qparams['marker'] = marker diff --git a/mistralclient/commands/v2/executions.py b/mistralclient/commands/v2/executions.py index c49bd925..61585237 100644 --- a/mistralclient/commands/v2/executions.py +++ b/mistralclient/commands/v2/executions.py @@ -76,7 +76,12 @@ class List(base.MistralLister): def get_parser(self, parsed_args): parser = super(List, self).get_parser(parsed_args) - + parser.add_argument( + '--task', + nargs='?', + help="Parent task execution ID associated with workflow " + "execution list.", + ) parser.add_argument( '--marker', type=str, @@ -113,6 +118,7 @@ class List(base.MistralLister): def _get_resources(self, parsed_args): mistral_client = self.app.client_manager.workflow_engine return mistral_client.executions.list( + task=parsed_args.task, marker=parsed_args.marker, limit=parsed_args.limit, sort_keys=parsed_args.sort_keys, diff --git a/mistralclient/tests/functional/cli/v2/base_v2.py b/mistralclient/tests/functional/cli/v2/base_v2.py index d039af59..357a149f 100644 --- a/mistralclient/tests/functional/cli/v2/base_v2.py +++ b/mistralclient/tests/functional/cli/v2/base_v2.py @@ -51,6 +51,10 @@ class MistralClientTestBase(base.MistralCLIAuth, base.MistralCLIAltAuth): 'functionaltests/resources/v2/wf_delay_v2.yaml', os.getcwd() ) + cls.wf_wrapping_wf = os.path.relpath( + 'functionaltests/resources/v2/wf_wrapping_wf_v2.yaml', os.getcwd() + ) + cls.act_def = os.path.relpath( 'functionaltests/resources/v2/action_v2.yaml', os.getcwd() ) diff --git a/mistralclient/tests/functional/cli/v2/cli_tests_v2.py b/mistralclient/tests/functional/cli/v2/cli_tests_v2.py index 3ab85a9f..10c9461a 100644 --- a/mistralclient/tests/functional/cli/v2/cli_tests_v2.py +++ b/mistralclient/tests/functional/cli/v2/cli_tests_v2.py @@ -501,14 +501,38 @@ class ExecutionCLITests(base_v2.MistralClientTestBase): self.assertEqual([], ex_output) + def test_executions_list_with_task(self): + wrapping_wf = self.workflow_create(self.wf_wrapping_wf) + decoy = self.execution_create(wrapping_wf[-1]['Name']) + wrapping_wf_ex = self.execution_create(wrapping_wf[-1]['Name']) + + wrapping_wf_ex_id = self.get_field_value(wrapping_wf_ex, 'ID') + + self.assertIsNot(wrapping_wf_ex_id, self.get_field_value(decoy, 'ID')) + + tasks = self.mistral_admin( + 'task-list', + params=wrapping_wf_ex_id + ) + + wrapping_task_id = tasks[-1]['ID'] + + wf_execs = self.mistral_cli( + True, + 'execution-list', + params="--task {}".format(wrapping_task_id) + ) + + self.assertEqual(1, len(wf_execs)) + wf_exec = wf_execs[0] + self.assertEqual(wrapping_task_id, wf_exec['Task Execution ID']) + def test_executions_list_with_pagination(self): - wf_ex1 = self.mistral_admin( - 'execution-create', + wf_ex1 = self.execution_create( params='{0} -d "a"'.format(self.direct_wf['Name']) ) - wf_ex2 = self.mistral_admin( - 'execution-create', + wf_ex2 = self.execution_create( params='{0} -d "b"'.format(self.direct_wf['Name']) ) diff --git a/mistralclient/tests/unit/v2/test_cli_executions.py b/mistralclient/tests/unit/v2/test_cli_executions.py index 416896b1..adaf1a9c 100644 --- a/mistralclient/tests/unit/v2/test_cli_executions.py +++ b/mistralclient/tests/unit/v2/test_cli_executions.py @@ -232,7 +232,8 @@ class TestCLIExecutionsV2(base.BaseCommandTest): limit=None, marker='', sort_dirs='asc', - sort_keys='created_at' + sort_keys='created_at', + task=None ) self.call( @@ -249,7 +250,8 @@ class TestCLIExecutionsV2(base.BaseCommandTest): limit=5, marker='abc', sort_dirs='id, Workflow', - sort_keys='desc' + sort_keys='desc', + task=None ) def test_get(self):