def run(self, name, context, args): cls_name, method_name = name.split(".", 1) cls = scenario_base.Scenario.get_by_name(cls_name) # NOTE(boris-42): processing @types decorators args = types.preprocess(cls, method_name, context, args) with rutils.Timer() as timer: self._run_scenario(cls, method_name, context, args) return timer.duration()
def run(self, name, context, args): cls_name, method_name = name.split(".", 1) cls = scenario_base.Scenario.get_by_name(cls_name) # NOTE(boris-42): processing @types decorators args = types.preprocess(cls, method_name, context, args) with rutils.Timer() as timer: print("Runner context: %s" % (context)) self._run_scenario(cls, method_name, context, args) return timer.duration()
def test_preprocess(self, mock_osclients, mock_meta): cls = "some_class" method_name = "method_name" context = {"a": 1, "b": 2, "admin": {"endpoint": mock.MagicMock()}} args = {"a": 10, "b": 20} class Preprocessor(types.ResourceType): @classmethod def transform(cls, clients, resource_config): return resource_config * 2 mock_meta.return_value = {"a": Preprocessor} result = types.preprocess(cls, method_name, context, args) mock_meta.assert_called_once_with(cls, default={}, method_name=method_name, attr_name="preprocessors") mock_osclients.Clients.assert_called_once_with( context["admin"]["endpoint"]) self.assertEqual({"a": 20, "b": 20}, result)
def test_preprocess(self, mock_osclients, mock_scenario_meta): cls = "some_class" method_name = "method_name" context = { "a": 1, "b": 2, "admin": {"endpoint": mock.MagicMock()} } args = {"a": 10, "b": 20} class Preprocessor(types.ResourceType): @classmethod def transform(cls, clients, resource_config): return resource_config * 2 mock_scenario_meta.return_value = {"a": Preprocessor} result = types.preprocess(cls, method_name, context, args) mock_scenario_meta.assert_called_once_with( cls, default={}, method_name=method_name, attr_name="preprocessors") mock_osclients.Clients.assert_called_once_with( context["admin"]["endpoint"]) self.assertEqual({"a": 20, "b": 20}, result)