Exemplo n.º 1
0
    def test_get_user_ctx_for_validation_existing_users(
            self, mock_existing_users, mock_task_config):

        context = {"a": 10}
        users = [mock.MagicMock(), mock.MagicMock()]

        eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock(),
                                users=users)

        result = eng._get_user_ctx_for_validation(context)

        self.assertEqual(context["config"]["existing_users"], users)
        mock_existing_users.assert_called_once_with(context)

        self.assertEqual(mock_existing_users.return_value, result)
Exemplo n.º 2
0
    def test_validate(self, mock_validate, mock_task_config):
        mock_task_config.return_value = config = mock.MagicMock()
        eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock(),
                                mock.Mock())
        mock_validate = mock.MagicMock()

        eng._validate_config_syntax = mock_validate.syntax
        eng._validate_config_platforms = mock_validate.platforms
        eng._validate_config_semantic = mock_validate.semantic

        eng.validate()

        mock_validate.syntax.assert_called_once_with(config)
        mock_validate.platforms.assert_called_once_with(config)
        mock_validate.semantic.assert_called_once_with(config)
Exemplo n.º 3
0
    def validate(cls, deployment, config, task_instance=None):
        """Validate a task config against specified deployment.

        :param deployment: UUID or name of the deployment
        :param config: a dict with a task configuration
        """
        deployment = objects.Deployment.get(deployment)
        task = task_instance or objects.Task(
            deployment_uuid=deployment["uuid"], temporary=True)
        benchmark_engine = engine.TaskEngine(config,
                                             task,
                                             admin=deployment["admin"],
                                             users=deployment["users"])

        benchmark_engine.validate()
Exemplo n.º 4
0
    def test_validate__wrong_semantic(self, mock_task_config):
        task = mock.MagicMock()
        eng = engine.TaskEngine(mock.MagicMock(), task, mock.Mock())
        eng._validate_config_syntax = mock.MagicMock()
        eng._validate_config_platforms = mock.MagicMock()
        eng._validate_config_semantic = mock.MagicMock(
            side_effect=exceptions.InvalidTaskConfig)

        self.assertRaises(exceptions.InvalidTaskException, eng.validate)
        self.assertTrue(task.set_failed.called)
        # all steps of validation are called, which means that the last one is
        # failed
        self.assertTrue(eng._validate_config_syntax)
        self.assertTrue(eng._validate_config_platforms)
        self.assertTrue(eng._validate_config_semantic)
Exemplo n.º 5
0
    def test__validate_config_scenarios_name(self, mock_scenario_get_all,
                                             mock_task_config):

        mock_task_instance = mock.MagicMock()
        mock_subtask = mock.MagicMock()
        mock_subtask.scenarios = [{"name": "a"}, {"name": "b"}]
        mock_task_instance.subtasks = [mock_subtask]

        mock_scenario_get_all.return_value = [
            mock.MagicMock(get_name=lambda: "e"),
            mock.MagicMock(get_name=lambda: "b"),
            mock.MagicMock(get_name=lambda: "a")
        ]
        eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock())
        eng._validate_config_scenarios_name(mock_task_instance)
Exemplo n.º 6
0
    def test__validate_config_syntax__wrong_context(
            self, mock_context_manager, mock_scenario_runner_validate,
            mock_task_config):
        mock_task_instance = mock.MagicMock()
        mock_subtask = mock.MagicMock()
        mock_subtask.workloads = [
            engine.Workload({"name": "sca", "context": "a"}),
            engine.Workload({"name": "sca", "runner": "b"})
        ]
        mock_task_instance.subtasks = [mock_subtask]
        eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock())

        mock_context_manager.validate = mock.MagicMock(
            side_effect=jsonschema.ValidationError("a"))
        self.assertRaises(exceptions.InvalidTaskConfig,
                          eng._validate_config_syntax, mock_task_instance)
Exemplo n.º 7
0
    def test__validate_config_semantic(
            self, mock_deployment_get,
            mock__validate_config_semantic_helper,
            mock_task_config, mock_context,
            mock_scenario_get):
        admin = fakes.fake_credential(foo="admin")
        users = [fakes.fake_credential(bar="user1")]
        deployment = fakes.FakeDeployment(
            uuid="deployment_uuid", admin=admin, users=users)

        class SomeScen(object):

            is_classbased = True

            @classmethod
            def get_namespace(cls):
                return "openstack"

            @classmethod
            def get_info(cls):
                return {"title": "foo"}

        mock_scenario_get.return_value = SomeScen

        mock_task_instance = mock.MagicMock()
        mock_subtask1 = mock.MagicMock()
        wconf1 = engine.Workload({"name": "a", "runner": "ra",
                                  "context": {"users": {}}}, 0)
        wconf2 = engine.Workload({"name": "a", "runner": "rb"}, 1)
        mock_subtask1.workloads = [wconf1, wconf2]

        mock_subtask2 = mock.MagicMock()
        wconf3 = engine.Workload({"name": "b", "runner": "ra"}, 0)
        mock_subtask2.workloads = [wconf3]

        mock_task_instance.subtasks = [mock_subtask1, mock_subtask2]
        fake_task = mock.MagicMock()
        eng = engine.TaskEngine(mock_task_instance, fake_task, deployment)

        eng._validate_config_semantic(mock_task_instance)

        user_context = mock_context.get.return_value.return_value

        mock__validate_config_semantic_helper.assert_has_calls([
            mock.call(admin, user_context, [wconf1], "openstack"),
            mock.call(admin, user_context, [wconf2, wconf3], "openstack"),
        ], any_order=True)
Exemplo n.º 8
0
    def test_validate__wrong_syntax(self):
        task = mock.MagicMock()
        eng = engine.TaskEngine(mock.MagicMock(), task, mock.Mock())
        e = exceptions.InvalidTaskConfig(name="foo",
                                         pos=0,
                                         config="",
                                         reason="foo")
        eng._validate_config_syntax = mock.MagicMock(side_effect=e)
        eng._validate_config_platforms = mock.Mock()

        actual_e = self.assertRaises(exceptions.InvalidTaskException,
                                     eng.validate)
        self.assertEqual(e, actual_e)

        self.assertTrue(task.set_failed.called)
        # the next validation step should not be processed
        self.assertFalse(eng._validate_config_platforms.called)
Exemplo n.º 9
0
    def test__validate_config_semantic(self, mock_context_manager_setup,
                                       mock_context_manager_cleanup):
        env = mock.MagicMock(uuid="env_uuid")
        env.check_health.return_value = {
            "foo": {
                "available": True,
                "message": ""
            },
            "bar": {
                "available": True,
                "message": ""
            }
        }

        @scenario.configure("SomeScen.scenario")
        class SomeScen(scenario.Scenario):
            def run(self):
                pass

        mock_task_instance = mock.MagicMock()
        wconf1 = self._make_workload(name="SomeScen.scenario")
        wconf2 = self._make_workload(name="SomeScen.scenario", position=1)
        subtask1 = {"workloads": [wconf1, wconf2]}

        wconf3 = self._make_workload(name="SomeScen.scenario", position=2)
        subtask2 = {"workloads": [wconf3]}

        mock_task_instance.subtasks = [subtask1, subtask2]
        fake_task = mock.MagicMock()
        eng = engine.TaskEngine(mock_task_instance, fake_task, env)

        eng._validate_config_semantic(mock_task_instance)

        env.check_health.return_value = {
            "foo": {
                "available": True,
                "message": ""
            },
            "bar": {
                "available": False,
                "message": "",
                "traceback": "AAAA"
            }
        }
        self.assertRaises(exceptions.ValidationError,
                          eng._validate_config_semantic, mock_task_instance)
Exemplo n.º 10
0
 def test__validate_config_semantic_helper(self, mock_task_config,
                                           mock_scenario_get):
     deployment = mock.Mock()
     eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock(),
                             deployment)
     mock_scenario = mock_scenario_get.return_value
     workloads = [engine.Workload(
         {"name": "name", "runner": "runner", "args": "args"}, 0)]
     user_context = mock.MagicMock()
     user_context.__enter__.return_value.context = {
         "users": [{"foo": "user1"}]}
     eng._validate_config_semantic_helper("admin", user_context, workloads,
                                          deployment)
     mock_scenario.validate.assert_called_once_with(
         "name", {"runner": "runner", "args": "args"},
         admin="admin", users=[{"foo": "user1"}],
         deployment=deployment)
Exemplo n.º 11
0
    def test__validate_config_semantic_helper(self, mock_task_config):
        eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock(),
                                mock.Mock())
        eng._validate_workload = mock.Mock()
        workloads = [engine.Workload(
            {"name": "name", "runner": "runner", "args": "args"}, 0)]
        users = [{"foo": "user1"}]
        user_context = mock.MagicMock()
        user_context.__enter__.return_value.context = {"users": users}

        eng._validate_config_semantic_helper(
            "admin", user_context, workloads, "foo")

        eng._validate_workload.assert_called_once_with(
            workloads[0], credentials={"foo": {"admin": "admin",
                                               "users": users}},
            vtype="semantic")
Exemplo n.º 12
0
    def test__validate_config_scenarios_name_non_exsisting(
            self, mock_scenario, mock_task_config):

        mock_task_instance = mock.MagicMock()
        mock_subtask = mock.MagicMock()
        mock_subtask.workloads = [
            engine.Workload({"name": "exist"}),
            engine.Workload({"name": "nonexist1"}),
            engine.Workload({"name": "nonexist2"})
        ]
        mock_task_instance.subtasks = [mock_subtask]
        mock_scenario.list_benchmark_scenarios.return_value = ["exist", "aaa"]
        eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock())

        self.assertRaises(exceptions.NotFoundScenarios,
                          eng._validate_config_scenarios_name,
                          mock_task_instance)
Exemplo n.º 13
0
    def test_validate(self, mock_validate, mock_task_config):
        mock_task_config.return_value = config = mock.MagicMock()
        eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock())
        mock_validate = mock.MagicMock()

        eng._validate_config_scenarios_name = mock_validate.names
        eng._validate_config_syntax = mock_validate.syntax
        eng._validate_config_semantic = mock_validate.semantic

        eng.validate()

        expected_calls = [
            mock.call.names(config),
            mock.call.syntax(config),
            mock.call.semantic(config)
        ]
        mock_validate.assert_has_calls(expected_calls)
Exemplo n.º 14
0
    def test__validate_config_semantic(
            self, mock_deployment_get,
            mock__validate_config_semantic_helper,
            mock_task_config, mock_context,
            mock_scenario_get):
        admin = fakes.fake_credential(foo="admin")
        users = [fakes.fake_credential(bar="user1")]
        deployment = fakes.FakeDeployment(
            uuid="deployment_uuid", admin=admin, users=users)

        # TODO(boris-42): Refactor this test case to make it
        #                 up to date with other code
        class SomeScen(object):

            is_classbased = True

            @classmethod
            def get_platform(cls):
                return "openstack"

            @classmethod
            def get_info(cls):
                return {"title": "foo"}

        mock_scenario_get.return_value = SomeScen

        mock_task_instance = mock.MagicMock()
        wconf1 = self._make_workload(name="a", runner="ra",
                                     context={"users": {}})
        wconf2 = self._make_workload(name="a", runner="rb", position=1)
        subtask1 = {"workloads": [wconf1, wconf2]}

        wconf3 = self._make_workload(name="b", runner="ra", position=2)
        subtask2 = {"workloads": [wconf3]}

        mock_task_instance.subtasks = [subtask1, subtask2]
        fake_task = mock.MagicMock()
        eng = engine.TaskEngine(mock_task_instance, fake_task, deployment)

        eng._validate_config_semantic(mock_task_instance)

        user_context = mock_context.get.return_value.return_value

        mock__validate_config_semantic_helper.assert_called_once_with(
            admin, user_context, [wconf1, wconf2, wconf3], "openstack")
Exemplo n.º 15
0
    def test___validate_workload__wrong_runner(
            self, mock_scenario_runner_validate, mock_task_config,
            mock_scenario_get, mock_dumps):
        mock_dumps.return_value = "<JSON>"
        result = validation.ValidationResult(False, "There is no such runner")
        mock_scenario_runner_validate.return_value = [result]
        scenario_cls = mock_scenario_get.return_value
        scenario_cls.get_default_context.return_value = {}
        workload = engine.Workload({"name": "sca", "runner": {"type": "b"}}, 0)
        eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock(),
                                mock.Mock())

        e = self.assertRaises(exceptions.InvalidTaskConfig,
                              eng._validate_workload, workload)
        self.assertEqual("Input task is invalid!\n\nSubtask sca[0] has wrong "
                         "configuration\nSubtask configuration:\n"
                         "<JSON>\n\nReason(s):\n"
                         " There is no such runner", e.format_message())
Exemplo n.º 16
0
    def test___validate_workload__wrong_runner(
            self, mock_scenario_runner_validate, mock_task_config,
            mock_scenario_get, mock_dumps):
        mock_dumps.return_value = "<JSON>"
        mock_scenario_runner_validate.return_value = [
            "There is no such runner"]
        scenario_cls = mock_scenario_get.return_value
        scenario_cls.get_default_context.return_value = {}
        workload = self._make_workload(name="sca", runner=("b", {}))
        eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock(),
                                mock.Mock())

        e = self.assertRaises(exceptions.InvalidTaskConfig,
                              eng._validate_workload, workload)
        self.assertEqual("Input task is invalid!\n\nSubtask sca[0] has wrong "
                         "configuration\nSubtask configuration:\n"
                         "<JSON>\n\nReason(s):\n"
                         " There is no such runner", e.format_message())
Exemplo n.º 17
0
 def test__validate_config_semantic_helper(self, mock_scenario_validate,
                                           mock_task_config):
     deployment = mock.MagicMock()
     eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock())
     workload = engine.Workload({
         "name": "name",
         "runner": "runner",
         "args": "args"
     })
     eng._validate_config_semantic_helper("admin", "user", workload, "pos",
                                          deployment)
     mock_scenario_validate.assert_called_once_with("name", {
         "runner": "runner",
         "args": "args"
     },
                                                    admin="admin",
                                                    users=["user"],
                                                    deployment=deployment)
Exemplo n.º 18
0
    def test__prepare_context(self):
        @context.configure("test1", 1, platform="testing")
        class TestContext1(context.Context):
            pass

        self.addCleanup(TestContext1.unregister)

        @context.configure("test2", 2, platform="testing")
        class TestContext2(context.Context):
            pass

        self.addCleanup(TestContext2.unregister)

        @scenario.configure("test_ctx.test",
                            platform="testing",
                            context={"test1@testing": {
                                "a": 1
                            }})
        class TestScenario(scenario.Scenario):
            pass

        self.addCleanup(TestScenario.unregister)

        task = mock.MagicMock()
        name = "test_ctx.test"
        context_config = {"test1": 1, "test2": 2}

        env = mock.MagicMock()
        eng = engine.TaskEngine({}, task, env)

        result = eng._prepare_context(context_config, name, "foo_uuid")

        expected_result = {
            "task": task,
            "owner_id": "foo_uuid",
            "scenario_name": name,
            "config": {
                "test1@testing": 1,
                "test2@testing": 2
            },
            "env": env.data
        }
        self.assertEqual(expected_result, result)
Exemplo n.º 19
0
 def test_run__task_aborted(
         self, mock_scenario_runner, mock_scenario,
         mock_context_manager_setup, mock_context_manager_cleanup,
         mock_result_consumer, mock_task_get_status):
     task = mock.MagicMock(spec=objects.Task)
     config = {
         "a.task": [{"runner": {"type": "a", "b": 1}}],
         "b.task": [{"runner": {"type": "a", "b": 1}}],
         "c.task": [{"runner": {"type": "a", "b": 1}}]
     }
     fake_runner_cls = mock.MagicMock()
     fake_runner = mock.MagicMock()
     fake_runner_cls.return_value = fake_runner
     mock_task_get_status.return_value = consts.TaskStatus.SOFT_ABORTING
     mock_scenario_runner.get.return_value = fake_runner_cls
     eng = engine.TaskEngine(config, task, mock.Mock())
     eng.run()
     self.assertEqual(mock.call(consts.TaskStatus.ABORTED),
                      task.update_status.mock_calls[-1])
Exemplo n.º 20
0
 def test__validate_config_syntax(
         self, mock_context_manager_validate,
         mock_scenario_runner_validate,
         mock_task_config
 ):
     mock_task_instance = mock.MagicMock()
     mock_subtask = mock.MagicMock()
     mock_subtask.workloads = [
         engine.Workload({"name": "sca", "context": "a"}),
         engine.Workload({"name": "sca", "runner": "b"})
     ]
     mock_task_instance.subtasks = [mock_subtask]
     eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock())
     eng._validate_config_syntax(mock_task_instance)
     mock_scenario_runner_validate.assert_has_calls(
         [mock.call({}), mock.call("b")], any_order=True)
     mock_context_manager_validate.assert_has_calls(
         [mock.call("a", non_hidden=True), mock.call({}, non_hidden=True)],
         any_order=True)
Exemplo n.º 21
0
    def test_run_exception_is_logged(self, mock_context_manager_setup,
                                     mock_context_manager_cleanup,
                                     mock_scenario_runner, mock_scenario,
                                     mock_context, mock_result_consumer,
                                     mock_log, mock_task_get_status):
        scenario_cls = mock_scenario.get.return_value
        scenario_cls.get_default_context.return_value = {}

        context_cls = mock_context.get.return_value
        context_cls.get_fullname.return_value = "context_a"

        mock_context_manager_setup.side_effect = Exception
        mock_result_consumer.is_task_in_aborting_status.return_value = False

        mock_task_instance = mock.MagicMock()

        mock_task_instance.subtasks = [{
            "title":
            "foo",
            "description":
            "Do not launch it!!",
            "contexts": {},
            "workloads": [
                self._make_workload(name="a.task",
                                    description="foo",
                                    contexts={"context_a": {
                                        "a": 1
                                    }}),
                self._make_workload(name="a.task",
                                    description="foo",
                                    contexts={"context_a": {
                                        "b": 2
                                    }},
                                    position=2)
            ]
        }]
        eng = engine.TaskEngine(mock_task_instance, mock.MagicMock(),
                                mock.MagicMock())

        eng.run()

        self.assertEqual(2, mock_log.exception.call_count)
Exemplo n.º 22
0
    def test__validate_config_semantic(
            self, mock_deployment_get,
            mock__validate_config_semantic_helper,
            mock_users_ctx, mock_clients, mock_task_config):
        mock_users_ctx.UserGenerator = fakes.FakeUserContext
        mock_clients.return_value = mock.MagicMock()

        mock_task_instance = mock.MagicMock()
        mock_subtask1 = mock.MagicMock()
        wconf1 = engine.Workload({"name": "a", "runner": "ra"})
        wconf2 = engine.Workload({"name": "a", "runner": "rb"})
        mock_subtask1.workloads = [wconf1, wconf2]

        mock_subtask2 = mock.MagicMock()
        wconf3 = engine.Workload({"name": "b", "runner": "ra"})
        mock_subtask2.workloads = [wconf3]

        mock_task_instance.subtasks = [mock_subtask1, mock_subtask2]
        fake_task = mock.MagicMock()
        eng = engine.TaskEngine(mock_task_instance, fake_task)

        eng.admin = "admin"

        eng._validate_config_semantic(mock_task_instance)

        expected_calls = [
            mock.call("admin"),
            mock.call(fakes.FakeUserContext.user["credential"])
        ]
        mock_clients.assert_has_calls(expected_calls)

        mock_deployment_get.assert_called_once_with(fake_task["uuid"])

        admin = user = mock_clients.return_value
        fake_deployment = mock_deployment_get.return_value
        expected_calls = [
            mock.call(admin, user, wconf1, 0, fake_deployment),
            mock.call(admin, user, wconf2, 1, fake_deployment),
            mock.call(admin, user, wconf3, 0, fake_deployment)
        ]
        mock__validate_config_semantic_helper.assert_has_calls(
            expected_calls, any_order=True)
Exemplo n.º 23
0
    def test_validate__wrong_semantic(self):
        task = mock.MagicMock()
        eng = engine.TaskEngine(mock.MagicMock(), task, mock.Mock())
        e = exceptions.InvalidTaskConfig(name="foo",
                                         pos=0,
                                         config="",
                                         reason="foo")
        eng._validate_config_syntax = mock.MagicMock()
        eng._validate_config_platforms = mock.MagicMock()
        eng._validate_config_semantic = mock.MagicMock(side_effect=e)

        actual_e = self.assertRaises(exceptions.InvalidTaskException,
                                     eng.validate)
        self.assertEqual(e, actual_e)
        self.assertTrue(task.set_failed.called)
        # all steps of validation are called, which means that the last one is
        # failed
        self.assertTrue(eng._validate_config_syntax)
        self.assertTrue(eng._validate_config_platforms)
        self.assertTrue(eng._validate_config_semantic)
Exemplo n.º 24
0
    def test_schema_is_valid(self):
        discover.load_plugins(os.path.join(self.rally_jobs_path, "plugins"))

        files = {
            f
            for f in os.listdir(self.rally_jobs_path)
            if (os.path.isfile(os.path.join(self.rally_jobs_path, f))
                and f.endswith(".yaml") and not f.endswith("_args.yaml"))
        }

        # TODO(andreykurilin): figure out why it fails
        files -= {"rally-mos.yaml", "sahara-clusters.yaml"}

        for filename in files:
            full_path = os.path.join(self.rally_jobs_path, filename)

            with open(full_path) as task_file:
                try:
                    args_file = os.path.join(
                        self.rally_jobs_path,
                        filename.rsplit(".", 1)[0] + "_args.yaml")

                    args = {}
                    if os.path.exists(args_file):
                        args = yaml.safe_load(open(args_file).read())
                        if not isinstance(args, dict):
                            raise TypeError(
                                "args file %s must be dict in yaml or json "
                                "presentation" % args_file)

                    task_inst = api._Task(api.API(skip_db_check=True))
                    task = task_inst.render_template(
                        task_template=task_file.read(), **args)
                    task = task_cfg.TaskConfig(yaml.safe_load(task))
                    task_obj = fakes.FakeTask({"uuid": full_path})

                    eng = engine.TaskEngine(task, task_obj, mock.Mock())
                    eng.validate(only_syntax=True)
                except Exception:
                    print(traceback.format_exc())
                    self.fail("Wrong task input file: %s" % full_path)
Exemplo n.º 25
0
    def test_run__subtask_crashed(self, mock_scenario_runner, mock_scenario,
                                  mock_context_manager_setup,
                                  mock_context_manager_cleanup,
                                  mock_result_consumer, mock_task_get_status):
        task = mock.MagicMock(spec=objects.Task)
        subtask_obj = task.add_subtask.return_value
        subtask_obj.add_workload.side_effect = MyException()
        mock_result_consumer.is_task_in_aborting_status.return_value = False
        config = task_cfg.TaskConfig({
            "a.task": [{
                "runner": {
                    "type": "a",
                    "b": 1
                }
            }],
            "b.task": [{
                "runner": {
                    "type": "a",
                    "b": 1
                }
            }],
            "c.task": [{
                "runner": {
                    "type": "a",
                    "b": 1
                }
            }]
        })
        fake_runner_cls = mock.MagicMock()
        fake_runner = mock.MagicMock()
        fake_runner_cls.return_value = fake_runner
        mock_scenario_runner.get.return_value = fake_runner_cls
        eng = engine.TaskEngine(config, task, mock.Mock())
        self.assertRaises(MyException, eng.run)

        task.update_status.assert_has_calls((
            mock.call(consts.TaskStatus.RUNNING),
            mock.call(consts.TaskStatus.CRASHED),
        ))
        subtask_obj.update_status.assert_called_once_with(
            consts.SubtaskStatus.CRASHED)
Exemplo n.º 26
0
 def test__validate_config_syntax__wrong_sla(
         self, mock_task_config, mock_sla_validate, mock_scenario_get,
         mock_dumps):
     mock_dumps.return_value = "<JSON>"
     mock_sla_validate.return_value = ["sla_error"]
     scenario_cls = mock_scenario_get.return_value
     scenario_cls.get_default_context.return_value = {}
     mock_task_instance = mock.MagicMock()
     mock_task_instance.subtasks = [{"workloads": [
         self._make_workload(name="sca"),
         self._make_workload(name="sca", position=1,
                             sla={"foo_sla": "sla_conf"})
     ]}]
     eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock(),
                             mock.Mock())
     e = self.assertRaises(exceptions.InvalidTaskConfig,
                           eng._validate_config_syntax, mock_task_instance)
     self.assertEqual("Input task is invalid!\n\n"
                      "Subtask sca[1] has wrong configuration\n"
                      "Subtask configuration:\n<JSON>\n\n"
                      "Reason(s):\n sla_error", e.format_message())
Exemplo n.º 27
0
    def test_run__task_soft_aborted(self, mock_scenario_runner, mock_scenario,
                                    mock_context_manager_setup,
                                    mock_context_manager_cleanup,
                                    mock_result_consumer):
        task = mock.MagicMock()
        mock_result_consumer.is_task_in_aborting_status.side_effect = [
            False, False, True
        ]
        config = {
            "a.task": [{
                "runner": {
                    "type": "a",
                    "b": 1
                }
            }],
            "b.task": [{
                "runner": {
                    "type": "a",
                    "b": 1
                }
            }],
            "c.task": [{
                "runner": {
                    "type": "a",
                    "b": 1
                }
            }]
        }
        fake_runner_cls = mock.MagicMock()
        fake_runner = mock.MagicMock()
        fake_runner_cls.return_value = fake_runner
        mock_scenario_runner.get.return_value = fake_runner_cls
        eng = engine.TaskEngine(config, task)

        eng.run()

        self.assertEqual(2, fake_runner.run.call_count)
        self.assertEqual(mock.call(consts.TaskStatus.ABORTED),
                         task.update_status.mock_calls[-1])
Exemplo n.º 28
0
    def test__validate_config_semantic(
            self, mock_deployment_get,
            mock__validate_config_semantic_helper,
            mock_task_config, mock_credential, mock_context,
            mock_scenario_get, mock_clients):
        deployment = fakes.FakeDeployment(
            uuid="deployment_uuid", admin={"foo": "admin"},
            users=[{"bar": "user1"}])

        scenario_cls = mock_scenario_get.return_value
        scenario_cls.get_namespace.return_value = "default"

        mock_task_instance = mock.MagicMock()
        mock_subtask1 = mock.MagicMock()
        wconf1 = engine.Workload({"name": "a", "runner": "ra",
                                  "context": {"users": {}}}, 0)
        wconf2 = engine.Workload({"name": "a", "runner": "rb"}, 1)
        mock_subtask1.workloads = [wconf1, wconf2]

        mock_subtask2 = mock.MagicMock()
        wconf3 = engine.Workload({"name": "b", "runner": "ra"}, 0)
        mock_subtask2.workloads = [wconf3]

        mock_task_instance.subtasks = [mock_subtask1, mock_subtask2]
        fake_task = mock.MagicMock()
        eng = engine.TaskEngine(mock_task_instance, fake_task, deployment)

        eng._validate_config_semantic(mock_task_instance)

        admin = mock_credential.return_value
        user_context = mock_context.get.return_value.return_value

        mock_clients.assert_called_once_with(admin)
        mock_clients.return_value.verified_keystone.assert_called_once_with()

        mock__validate_config_semantic_helper.assert_has_calls([
            mock.call(admin, user_context, [wconf1], deployment),
            mock.call(admin, user_context, [wconf2, wconf3], deployment),
        ], any_order=True)
Exemplo n.º 29
0
    def test__validate_config_scenarios_name_non_exsisting(
            self, mock_scenario, mock_task_config):

        mock_task_instance = mock.MagicMock()
        mock_subtask = mock.MagicMock()
        mock_subtask.workloads = [
            engine.Workload({"name": "exist"}, 0),
            engine.Workload({"name": "nonexist1"}, 1),
            engine.Workload({"name": "nonexist2"}, 2)
        ]
        mock_task_instance.subtasks = [mock_subtask]
        mock_scenario.get_all.return_value = [
            mock.Mock(get_name=lambda: "exist"),
            mock.Mock(get_name=lambda: "aaa")]
        eng = engine.TaskEngine(mock.MagicMock(), mock.MagicMock(),
                                mock.Mock())

        exc = self.assertRaises(exceptions.NotFoundScenarios,
                                eng._validate_config_scenarios_name,
                                mock_task_instance)
        self.assertEqual("There are no benchmark scenarios with names: "
                         "`nonexist2, nonexist1`.", str(exc))
Exemplo n.º 30
0
    def test_consume_results_abort_manually(self, mock_sla_checker, mock_event,
                                            mock_thread, mock_task_get_status):
        runner = mock.MagicMock(result_queue=False)

        is_done = mock.MagicMock()
        is_done.isSet.side_effect = (False, True)

        task = mock.MagicMock()
        mock_task_get_status.return_value = consts.TaskStatus.ABORTED

        key = {"kw": {"fake": 2}, "name": "fake", "pos": 0}

        eng = engine.TaskEngine({}, task)
        eng.duration = 123
        eng.full_duration = 456

        with engine.ResultConsumer(key, task, runner, True):
            pass

        mock_sla_checker.assert_called_once_with(key["kw"])
        mocked_set_aborted = mock_sla_checker.return_value.set_aborted_manually
        mocked_set_aborted.assert_called_once_with()