A collection of plugins for Rally framework designed for the OpenStack platform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

207 lines
6.9 KiB

  1. # Copyright 2015: Mirantis Inc.
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. from rally_openstack.task.scenarios.mistral import utils
  16. from tests.unit import fakes
  17. from tests.unit import test
  18. MISTRAL_UTILS = "rally_openstack.task.scenarios.mistral.utils"
  19. PARAMS_EXAMPLE = {"env": {"env_param": "param_value"}}
  20. INPUT_EXAMPLE = """{"input1": "value1", "some_json_input": {"a": "b"}}"""
  21. class MistralScenarioTestCase(test.ScenarioTestCase):
  22. def test_list_workbooks(self):
  23. scenario = utils.MistralScenario(context=self.context)
  24. return_wbs_list = scenario._list_workbooks()
  25. self.assertEqual(
  26. self.clients("mistral").workbooks.list.return_value,
  27. return_wbs_list)
  28. self._test_atomic_action_timer(
  29. scenario.atomic_actions(),
  30. "mistral.list_workbooks"
  31. )
  32. def test_create_workbook(self):
  33. definition = "version: \"2.0\"\nname: wb"
  34. scenario = utils.MistralScenario(context=self.context)
  35. self.assertEqual(
  36. self.clients("mistral").workbooks.create.return_value,
  37. scenario._create_workbook(definition)
  38. )
  39. self._test_atomic_action_timer(
  40. scenario.atomic_actions(),
  41. "mistral.create_workbook"
  42. )
  43. def test_delete_workbook(self):
  44. scenario = utils.MistralScenario(context=self.context)
  45. scenario._delete_workbook("wb_name")
  46. self.clients("mistral").workbooks.delete.assert_called_once_with(
  47. "wb_name",
  48. namespace=""
  49. )
  50. self._test_atomic_action_timer(
  51. scenario.atomic_actions(),
  52. "mistral.delete_workbook"
  53. )
  54. def test_list_executions(self):
  55. scenario = utils.MistralScenario(context=self.context)
  56. return_executions_list = scenario._list_executions()
  57. self.assertEqual(
  58. return_executions_list,
  59. self.clients("mistral").executions.list.return_value
  60. )
  61. self._test_atomic_action_timer(
  62. scenario.atomic_actions(),
  63. "mistral.list_executions"
  64. )
  65. def test_create_execution(self):
  66. scenario = utils.MistralScenario(context=self.context)
  67. namespace = "namespace"
  68. wf_name = "fake_wf_name"
  69. mock_wait_for_status = self.mock_wait_for_status.mock
  70. mock_create_exec = self.clients("mistral").executions.create
  71. self.assertEqual(
  72. mock_wait_for_status.return_value,
  73. scenario._create_execution("%s" % wf_name, namespace=namespace)
  74. )
  75. mock_create_exec.assert_called_once_with(
  76. wf_name,
  77. workflow_input=None,
  78. namespace=namespace
  79. )
  80. args, kwargs = mock_wait_for_status.call_args
  81. self.assertEqual(mock_create_exec.return_value, args[0])
  82. self.assertEqual(["ERROR"], kwargs["failure_statuses"])
  83. self.assertEqual(["SUCCESS"], kwargs["ready_statuses"])
  84. self._test_atomic_action_timer(
  85. scenario.atomic_actions(),
  86. "mistral.create_execution"
  87. )
  88. def test_create_execution_with_input(self):
  89. scenario = utils.MistralScenario(context=self.context)
  90. mock_wait_for_status = self.mock_wait_for_status.mock
  91. wf_name = "fake_wf_name"
  92. mock_create_exec = self.clients("mistral").executions.create
  93. self.assertEqual(
  94. mock_wait_for_status.return_value,
  95. scenario._create_execution(
  96. wf_name, wf_input=str(INPUT_EXAMPLE))
  97. )
  98. mock_create_exec.assert_called_once_with(
  99. wf_name,
  100. workflow_input=INPUT_EXAMPLE,
  101. namespace=""
  102. )
  103. def test_create_execution_with_params(self):
  104. scenario = utils.MistralScenario(context=self.context)
  105. mock_wait_for_status = self.mock_wait_for_status.mock
  106. wf_name = "fake_wf_name"
  107. mock_create_exec = self.clients("mistral").executions.create
  108. self.assertEqual(
  109. mock_wait_for_status.return_value,
  110. scenario._create_execution(
  111. wf_name, **PARAMS_EXAMPLE)
  112. )
  113. mock_create_exec.assert_called_once_with(
  114. wf_name,
  115. workflow_input=None,
  116. namespace="",
  117. **PARAMS_EXAMPLE
  118. )
  119. args, kwargs = mock_wait_for_status.call_args
  120. self.assertEqual(mock_create_exec.return_value, args[0])
  121. self.assertEqual(["ERROR"], kwargs["failure_statuses"])
  122. self.assertEqual(["SUCCESS"], kwargs["ready_statuses"])
  123. self._test_atomic_action_timer(
  124. scenario.atomic_actions(),
  125. "mistral.create_execution"
  126. )
  127. args, kwargs = mock_wait_for_status.call_args
  128. self.assertEqual(mock_create_exec.return_value, args[0])
  129. self.assertEqual(["ERROR"], kwargs["failure_statuses"])
  130. self.assertEqual(["SUCCESS"], kwargs["ready_statuses"])
  131. self._test_atomic_action_timer(
  132. scenario.atomic_actions(),
  133. "mistral.create_execution"
  134. )
  135. def test_delete_execution(self):
  136. scenario = utils.MistralScenario(context=self.context)
  137. execution = fakes.FakeMistralClient().execution.create()
  138. scenario._delete_execution(execution)
  139. self.clients("mistral").executions.delete.assert_called_once_with(
  140. execution.id
  141. )
  142. self._test_atomic_action_timer(
  143. scenario.atomic_actions(),
  144. "mistral.delete_execution"
  145. )
  146. def test_create_workflow(self):
  147. scenario = utils.MistralScenario(context=self.context)
  148. definition = """
  149. wf:
  150. type: direct
  151. tasks:
  152. task1:
  153. action: std.noop
  154. """
  155. self.assertEqual(
  156. self.clients("mistral").workflows.create.return_value,
  157. scenario._create_workflow(definition)
  158. )
  159. self._test_atomic_action_timer(
  160. scenario.atomic_actions(),
  161. "mistral.create_workflow"
  162. )
  163. def test_delete_workflow(self):
  164. wf_identifier = "wf_identifier"
  165. namespace = "delete_wf_test"
  166. scenario = utils.MistralScenario(context=self.context)
  167. scenario._delete_workflow(wf_identifier, namespace=namespace)
  168. self.clients("mistral").workflows.delete.assert_called_once_with(
  169. wf_identifier,
  170. namespace=namespace
  171. )
  172. self._test_atomic_action_timer(
  173. scenario.atomic_actions(),
  174. "mistral.delete_workflow"
  175. )