def test_run(self, mock_timer_duration):
        runner_obj = serial.SerialScenarioRunner(mock.MagicMock(),
                                                 mock.MagicMock())

        runner_obj._run_scenario = mock.MagicMock()

        scenario_name = "NovaServers.boot_server_from_volume_and_delete"
        config_kwargs = {"image": {"id": 1}, "flavor": {"id": 1}}

        context_obj = {
            "task": runner_obj.task,
            "scenario_name": scenario_name,
            "admin": {
                "endpoint": mock.MagicMock()
            },
            "config": {
                "cleanup": ["nova", "cinder"],
                "some_ctx": 2,
                "users": {}
            }
        }

        result = runner_obj.run(scenario_name, context_obj, config_kwargs)

        self.assertEqual(result, mock_timer_duration.return_value)
        self.assertEqual(list(runner_obj.result_queue), [])

        cls_name, method_name = scenario_name.split(".", 1)
        cls = scenario.Scenario.get(scenario_name)._meta_get("cls_ref")

        expected_config_kwargs = {"image": 1, "flavor": 1}
        runner_obj._run_scenario.assert_called_once_with(
            cls, method_name, context_obj, expected_config_kwargs)
Пример #2
0
 def test__run_scenario_aborted(self):
     runner = serial.SerialScenarioRunner(mock.MagicMock(),
                                          {"times": 5})
     runner.abort()
     runner._run_scenario(fakes.FakeScenario, "do_it",
                          fakes.FakeContext().context, {})
     self.assertEqual(len(runner.result_queue), 0)
Пример #3
0
    def test_run_classbased(self, mock_timer_duration):
        scenario_class = fakes.FakeClassBasedScenario
        runner_obj = serial.SerialScenarioRunner(mock.MagicMock(),
                                                 mock.MagicMock())
        runner_obj._run_scenario = mock.Mock()
        context_obj = {
            "task": runner_obj.task,
            "scenario_name": "classbased.fooscenario",
            "admin": {
                "credential": "foo_credentials"
            },
            "config": {}
        }

        result = runner_obj.run("classbased.fooscenario", context_obj, {
            "foo": 11,
            "bar": "spam"
        })

        self.assertIsNone(result)
        self.assertEqual(runner_obj.run_duration,
                         mock_timer_duration.return_value)
        self.assertEqual([], list(runner_obj.result_queue))

        runner_obj._run_scenario.assert_called_once_with(
            scenario_class, "run", context_obj, {
                "foo": 11,
                "bar": "spam"
            })
Пример #4
0
    def test__run_scenario(self, mock__run_scenario_once, mock_deque_as_queue):
        times = 5
        result = {"duration": 10., "idle_duration": 0., "error": [],
                  "output": {"additive": [], "complete": []},
                  "atomic_actions": [],
                  "timestamp": 1.}
        mock__run_scenario_once.return_value = result
        deque_as_queue_inst = mock_deque_as_queue.return_value
        expected_results = [[result] for i in range(times)]
        runner = serial.SerialScenarioRunner(mock.MagicMock(),
                                             {"times": times})

        runner._run_scenario(fakes.FakeScenario, "do_it",
                             fakes.FakeContext().context, {})

        self.assertEqual(len(runner.result_queue), times)
        results = list(runner.result_queue)
        self.assertEqual(results, expected_results)
        expected_calls = []
        for i in range(times):
            ctxt = fakes.FakeContext().context
            ctxt["iteration"] = i + 1
            ctxt["task"] = mock.ANY
            expected_calls.append(
                mock.call(fakes.FakeScenario, "do_it", ctxt, {},
                          deque_as_queue_inst)
            )
        mock__run_scenario_once.assert_has_calls(expected_calls)
        mock_deque_as_queue.assert_called_once_with(runner.event_queue)
Пример #5
0
 def test_abort(self):
     runner_obj = serial.SerialScenarioRunner(
         mock.MagicMock(),
         mock.MagicMock())
     self.assertFalse(runner_obj.aborted.is_set())
     runner_obj.abort()
     self.assertTrue(runner_obj.aborted.is_set())
Пример #6
0
    def test_run(self, mock_timer_duration):
        runner_obj = serial.SerialScenarioRunner(
            mock.MagicMock(),
            mock.MagicMock())

        runner_obj._run_scenario = mock.MagicMock()

        scenario_name = "NovaServers.boot_server_from_volume_and_delete"
        config_kwargs = {"image": {"id": 1}, "flavor": {"id": 1}}

        context_obj = {
            "task": runner_obj.task,
            "scenario_name": scenario_name,
            "admin": {"credential": mock.MagicMock()},
            "config": {
                "cleanup": ["nova", "cinder"], "some_ctx": 2, "users": {}
            }
        }

        result = runner_obj.run(scenario_name, context_obj, config_kwargs)

        self.assertIsNone(result)
        self.assertEqual(runner_obj.run_duration,
                         mock_timer_duration.return_value)
        self.assertEqual(list(runner_obj.result_queue), [])

        plugin_cls, method_name = scenario.Scenario.get(scenario_name), "run"

        self.assertTrue(plugin_cls.is_classbased)

        expected_config_kwargs = {"image": 1, "flavor": 1}
        runner_obj._run_scenario.assert_called_once_with(
            plugin_cls, method_name, context_obj, expected_config_kwargs)
    def test__join_processes(self, mock_scenario_runner__send_result):
        process = mock.MagicMock(is_alive=mock.MagicMock(return_value=False))
        processes = 10
        process_pool = collections.deque([process] * processes)
        mock_result_queue = mock.MagicMock(empty=mock.MagicMock(
            return_value=True))

        runner_obj = serial.SerialScenarioRunner(mock.MagicMock(),
                                                 mock.MagicMock())

        runner_obj._join_processes(process_pool, mock_result_queue)

        self.assertEqual(processes, process.join.call_count)
        mock_result_queue.close.assert_called_once_with()
    def test__create_process_pool(self):
        runner_obj = serial.SerialScenarioRunner(mock.MagicMock(),
                                                 mock.MagicMock())

        processes_to_start = 10

        def worker_process(i):
            pass

        counter = ((i, ) for i in range(100))

        process_pool = runner_obj._create_process_pool(processes_to_start,
                                                       worker_process, counter)
        self.assertEqual(processes_to_start, len(process_pool))
        for process in process_pool:
            self.assertIsInstance(process, multiprocessing.Process)
Пример #9
0
    def test__run_scenario(self, mock__run_scenario_once):
        times = 5
        result = {"duration": 10., "idle_duration": 0., "error": [],
                  "output": {"additive": [], "complete": []},
                  "atomic_actions": {},
                  "timestamp": 1.}
        mock__run_scenario_once.return_value = result
        expected_results = [[result] for i in range(times)]

        runner = serial.SerialScenarioRunner(mock.MagicMock(),
                                             {"times": times})
        runner._run_scenario(fakes.FakeScenario, "do_it",
                             fakes.FakeContext().context, {})
        self.assertEqual(len(runner.result_queue), times)
        results = list(runner.result_queue)
        self.assertEqual(results, expected_results)
 def test_runner_send_result_exception(self):
     runner_obj = serial.SerialScenarioRunner(mock.MagicMock(),
                                              mock.MagicMock())
     self.assertRaises(jsonschema.ValidationError,
                       lambda: runner_obj._send_result(mock.MagicMock()))
Пример #11
0
 def test_abort(self):
     runner = serial.SerialScenarioRunner(mock.MagicMock(),
                                          {"times": 5})
     self.assertFalse(runner.aborted.is_set())
     runner.abort()
     self.assertTrue(runner.aborted.is_set())