From 06a0ff39ff7a6d8c7d20834a3afc524ae6272b6e Mon Sep 17 00:00:00 2001 From: abdelal ali Date: Sun, 8 Mar 2020 13:12:50 +0000 Subject: [PATCH] Updated relevant methods with namespace field for mistral mistral supports namespace for, workbooks and workflows, updated utils.py for mistral and added a new method ('create_workflow') for creating workflows not in a workbook. Change-Id: Icb9ac70486e506e658b875a54ce4db479b089ef2 Depends-On: Ia225e3735db9de029a1992c5db60f38e8f8124a0 --- rally_openstack/scenarios/mistral/utils.py | 51 +++++++++++++++-- tests/unit/scenarios/mistral/test_utils.py | 66 +++++++++++++++++++--- 2 files changed, 103 insertions(+), 14 deletions(-) diff --git a/rally_openstack/scenarios/mistral/utils.py b/rally_openstack/scenarios/mistral/utils.py index 243fe9c3..ebb5774e 100644 --- a/rally_openstack/scenarios/mistral/utils.py +++ b/rally_openstack/scenarios/mistral/utils.py @@ -37,26 +37,59 @@ class MistralScenario(scenario.OpenStackScenario): return self.clients("mistral").workbooks.list() @atomic.action_timer("mistral.create_workbook") - def _create_workbook(self, definition): + def _create_workbook(self, definition, namespace=''): """Create a new workbook. :param definition: workbook description in string (yaml string) format + :param namespace: the namespace where the workbook + will be created in :returns: workbook object """ definition = yaml.safe_load(definition) definition["name"] = self.generate_random_name() definition = yaml.safe_dump(definition) - return self.clients("mistral").workbooks.create(definition) + return self.clients("mistral").workbooks.create( + definition, + namespace=namespace + ) @atomic.action_timer("mistral.delete_workbook") - def _delete_workbook(self, wb_name): + def _delete_workbook(self, wb_name, namespace=''): """Delete the given workbook. :param wb_name: the name of workbook that would be deleted. + :param namespace: the namespace of workbook that would be deleted. """ - self.clients("mistral").workbooks.delete(wb_name) + self.clients("mistral").workbooks.delete( + wb_name, + namespace=namespace + ) + + @atomic.action_timer("mistral.create_workflow") + def _create_workflow(self, definition, namespace=''): + """creates a workflow in the given namespace. + + :param definition: the definition of workflow + :param namespace: the namespace of the workflow + """ + return self.clients("mistral").workflows.create( + definition, + namespace=namespace + ) + + @atomic.action_timer("mistral.delete_workflow") + def _delete_workflow(self, workflow_identifier, namespace=''): + """Delete the given workflow. + + :param workflow_identifier: the identifier of workflow + :param namespace: the namespace of the workflow + """ + self.clients("mistral").workflows.delete( + workflow_identifier, + namespace=namespace + ) @atomic.action_timer("mistral.list_executions") def _list_executions(self, marker="", limit=None, sort_keys="", @@ -71,10 +104,12 @@ class MistralScenario(scenario.OpenStackScenario): sort_dirs=sort_dirs) @atomic.action_timer("mistral.create_execution") - def _create_execution(self, workflow_identifier, wf_input=None, **params): + def _create_execution(self, workflow_identifier, wf_input=None, + namespace='', **params): """Create a new execution. :param workflow_identifier: name or id of the workflow to execute + :param namespace: namespace of the workflow to execute :param input_: json string of mistral workflow input :param params: optional mistral params (this is the place to pass environment). @@ -82,7 +117,11 @@ class MistralScenario(scenario.OpenStackScenario): """ execution = self.clients("mistral").executions.create( - workflow_identifier, workflow_input=wf_input, **params) + workflow_identifier, + namespace=namespace, + workflow_input=wf_input, + **params + ) execution = utils.wait_for_status( execution, ready_statuses=["SUCCESS"], failure_statuses=["ERROR"], diff --git a/tests/unit/scenarios/mistral/test_utils.py b/tests/unit/scenarios/mistral/test_utils.py index d660622d..8c8b5067 100644 --- a/tests/unit/scenarios/mistral/test_utils.py +++ b/tests/unit/scenarios/mistral/test_utils.py @@ -50,9 +50,11 @@ class MistralScenarioTestCase(test.ScenarioTestCase): def test_delete_workbook(self): scenario = utils.MistralScenario(context=self.context) + scenario._delete_workbook("wb_name") self.clients("mistral").workbooks.delete.assert_called_once_with( - "wb_name" + "wb_name", + namespace='' ) self._test_atomic_action_timer( scenario.atomic_actions(), @@ -74,16 +76,22 @@ class MistralScenarioTestCase(test.ScenarioTestCase): def test_create_execution(self): scenario = utils.MistralScenario(context=self.context) - mock_wait_for_status = self.mock_wait_for_status.mock + namespace = 'namespace' wf_name = "fake_wf_name" + + mock_wait_for_status = self.mock_wait_for_status.mock mock_create_exec = self.clients("mistral").executions.create self.assertEqual( mock_wait_for_status.return_value, - scenario._create_execution("%s" % wf_name) + scenario._create_execution("%s" % wf_name, namespace=namespace) ) - mock_create_exec.assert_called_once_with(wf_name, workflow_input=None) + mock_create_exec.assert_called_once_with( + wf_name, + workflow_input=None, + namespace=namespace + ) args, kwargs = mock_wait_for_status.call_args self.assertEqual(mock_create_exec.return_value, args[0]) @@ -107,8 +115,11 @@ class MistralScenarioTestCase(test.ScenarioTestCase): wf_name, wf_input=str(INPUT_EXAMPLE)) ) - mock_create_exec.assert_called_once_with(wf_name, - workflow_input=INPUT_EXAMPLE) + mock_create_exec.assert_called_once_with( + wf_name, + workflow_input=INPUT_EXAMPLE, + namespace='' + ) def test_create_execution_with_params(self): scenario = utils.MistralScenario(context=self.context) @@ -122,8 +133,12 @@ class MistralScenarioTestCase(test.ScenarioTestCase): scenario._create_execution( wf_name, **PARAMS_EXAMPLE) ) - mock_create_exec.assert_called_once_with(wf_name, workflow_input=None, - **PARAMS_EXAMPLE) + mock_create_exec.assert_called_once_with( + wf_name, + workflow_input=None, + namespace='', + **PARAMS_EXAMPLE + ) args, kwargs = mock_wait_for_status.call_args self.assertEqual(mock_create_exec.return_value, args[0]) @@ -154,3 +169,38 @@ class MistralScenarioTestCase(test.ScenarioTestCase): scenario.atomic_actions(), "mistral.delete_execution" ) + + def test_create_workflow(self): + scenario = utils.MistralScenario(context=self.context) + definition = """ +wf: + type: direct + tasks: + task1: + action: std.noop +""" + self.assertEqual( + self.clients("mistral").workflows.create.return_value, + scenario._create_workflow(definition) + ) + self._test_atomic_action_timer( + scenario.atomic_actions(), + "mistral.create_workflow" + ) + + def test_delete_workflow(self): + wf_identifier = 'wf_identifier' + namespace = 'delete_wf_test' + + scenario = utils.MistralScenario(context=self.context) + scenario._delete_workflow(wf_identifier, namespace=namespace) + + self.clients("mistral").workflows.delete.assert_called_once_with( + wf_identifier, + namespace=namespace + ) + + self._test_atomic_action_timer( + scenario.atomic_actions(), + "mistral.delete_workflow" + )