def __init__(self, key, task, subtask, workload, runner, abort_on_sla_failure): """ResultConsumer constructor. :param key: Scenario identifier :param task: Instance of Task, task to run :param subtask: Instance of Subtask :param workload: Instance of Workload :param runner: ScenarioRunner instance that produces results to be consumed :param abort_on_sla_failure: True if the execution should be stopped when some SLA check fails """ self.key = key self.task = task self.subtask = subtask self.workload = workload self.runner = runner self.load_started_at = float("inf") self.load_finished_at = 0 self.workload_data_count = 0 self.sla_checker = sla.SLAChecker(key["kw"]) self.hook_executor = hook.HookExecutor(key["kw"], self.task) self.abort_on_sla_failure = abort_on_sla_failure self.is_done = threading.Event() self.unexpected_failure = {} self.results = [] self.thread = threading.Thread(target=self._consume_results) self.aborting_checker = threading.Thread(target=self.wait_and_abort) if "hooks" in self.key["kw"]: self.event_thread = threading.Thread(target=self._consume_events)
def __init__(self, workload_cfg, task, subtask, workload, runner, abort_on_sla_failure, ctx_manager): """ResultConsumer constructor. :param workload_cfg: A configuration of the Workload :param task: Instance of Task, task to run :param subtask: Instance of Subtask :param workload: Instance of Workload :param runner: ScenarioRunner instance that produces results to be consumed :param abort_on_sla_failure: True if the execution should be stopped when some SLA check fails :param ctx_manager: ContextManager instance """ self.task = task self.subtask = subtask self.workload = workload self.workload_cfg = workload_cfg self.runner = runner self.load_started_at = float("inf") self.load_finished_at = 0 self.workload_data_count = 0 self.sla_checker = sla.SLAChecker(self.workload_cfg) self.hook_executor = hook.HookExecutor(self.workload_cfg, self.task) self.abort_on_sla_failure = abort_on_sla_failure self.is_done = threading.Event() self.unexpected_failure = {} self.results = [] self.thread = threading.Thread(target=self._consume_results) self.aborting_checker = threading.Thread(target=self.wait_and_abort) if self.workload_cfg["hooks"]: self.event_thread = threading.Thread(target=self._consume_events) self._cm = ctx_manager
def test__validate_sla_types(self): sla_checker = sla.SLAChecker({"sla": {}}) mock_sla1 = mock.MagicMock() mock_sla2 = mock.MagicMock() sla_checker.sla_criteria = [mock_sla1, mock_sla2] another_sla_checker = sla.SLAChecker({"sla": {}}) mock_sla3 = mock.MagicMock() mock_sla4 = mock.MagicMock() another_sla_checker.sla_criteria = [mock_sla3, mock_sla4] sla_checker._validate_sla_types(another_sla_checker) mock_sla1.assert_has_calls([mock.call.validate_type(mock_sla3)]) mock_sla1.validate_type.assert_called_once_with(mock_sla3) mock_sla2.validate_type.assert_called_once_with(mock_sla4)
def test_set_aborted_manually(self): sla_checker = sla.SLAChecker({"sla": {}}) self.assertEqual([], sla_checker.results()) sla_checker.set_aborted_manually() self.assertEqual( [{"criterion": "aborted_manually", "success": False, "detail": "Task was aborted due to abort signal."}], sla_checker.results())
def test_set_aborted_on_sla(self): sla_checker = sla.SLAChecker({"sla": {}}) self.assertEqual([], sla_checker.results()) sla_checker.set_aborted_on_sla() self.assertEqual( [{"criterion": "aborted_on_sla", "success": False, "detail": "Task was aborted due to SLA failure(s)."}], sla_checker.results())
def test_set_unexpected_failure(self): exc = "error;(" sla_checker = sla.SLAChecker({"sla": {}}) self.assertEqual([], sla_checker.results()) sla_checker.set_unexpected_failure(exc) self.assertEqual([{"criterion": "something_went_wrong", "success": False, "detail": "Unexpected error: %s" % exc}], sla_checker.results())
def test_merge(self, merge_result1, merge_result2, result): sla_checker = sla.SLAChecker({"sla": {}}) mock_sla1 = mock.MagicMock() mock_sla2 = mock.MagicMock() sla_checker.sla_criteria = [mock_sla1, mock_sla2] mock_sla1.merge.return_value = merge_result1 mock_sla2.merge.return_value = merge_result2 another_sla_checker = sla.SLAChecker({"sla": {}}) mock_sla3 = mock.MagicMock() mock_sla4 = mock.MagicMock() another_sla_checker.sla_criteria = [mock_sla3, mock_sla4] sla_checker._validate_config = mock.MagicMock() sla_checker._validate_sla_types = mock.MagicMock() self.assertEqual(result, sla_checker.merge(another_sla_checker)) mock_sla1.merge.assert_called_once_with(mock_sla3) mock_sla2.merge.assert_called_once_with(mock_sla4)
def test_add_iteration_and_results(self): sla_checker = sla.SLAChecker({"sla": {"test_criterion": 42}}) iteration = {"key": {"name": "fake", "pos": 0}, "data": 42} self.assertTrue(sla_checker.add_iteration(iteration["data"])) expected_result = [{"criterion": "test_criterion", "detail": "detail", "success": True}] self.assertEqual(expected_result, sla_checker.results()) iteration["data"] = 43 self.assertFalse(sla_checker.add_iteration(iteration["data"])) expected_result = [{"criterion": "test_criterion", "detail": "detail", "success": False}] self.assertEqual(expected_result, sla_checker.results())
def __init__(self, key, task, runner, abort_on_sla_failure): """ResultConsumer constructor. :param key: Scenario identifier :param task: Task to run :param runner: ScenarioRunner instance that produces results to be consumed :param abort_on_sla_failure: True if the execution should be stopped when some SLA check fails """ self.key = key self.task = task self.runner = runner self.sla_checker = sla.SLAChecker(key["kw"]) self.abort_on_sla_failure = abort_on_sla_failure self.is_done = threading.Event() self.unexpected_failure = {} self.results = [] self.thread = threading.Thread(target=self._consume_results)
def test__validate_config_negative(self): sla_checker = sla.SLAChecker({"sla": {}}) another_sla_checker = sla.SLAChecker({"sla": {"test_criterion": 42}}) self.assertRaises(TypeError, sla_checker._validate_config, another_sla_checker)
def test__validate_config_positive(self): sla_checker = sla.SLAChecker({"sla": {}}) another_sla_checker = sla.SLAChecker({"sla": {}}) sla_checker._validate_config(another_sla_checker)