Browse Source

Merge "Updated relevant methods with namespace field for mistral"

tags/2.0.0
Zuul 3 months ago
committed by Gerrit Code Review
parent
commit
6847b85085
2 changed files with 103 additions and 14 deletions
  1. +45
    -6
      rally_openstack/scenarios/mistral/utils.py
  2. +58
    -8
      tests/unit/scenarios/mistral/test_utils.py

+ 45
- 6
rally_openstack/scenarios/mistral/utils.py View File

@@ -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"],


+ 58
- 8
tests/unit/scenarios/mistral/test_utils.py View File

@@ -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"
)

Loading…
Cancel
Save