From b60fbc195901ba4ddbd30cef8cefd1de8b2a5da3 Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Tue, 10 Jun 2014 04:52:16 -0300 Subject: [PATCH] avocado: Make it possible to use multiple output plugins Set up the TestResultProxy for the Job object, and populate the test result objects according to what the currently active plugins set. This means we go on finding arguments with the suffix _result and selecting any values that are classes derived from TestResult and appending them to the result proxy. With this, we can use any number of test result plugins we'd like. If no test result objects are set by plugins, fall back to the human output plugin. Signed-off-by: Lucas Meneghel Rodrigues --- avocado/job.py | 38 +++++++++++++++++++++-------------- avocado/plugins/journal.py | 2 +- avocado/plugins/jsonresult.py | 2 +- avocado/plugins/vm.py | 3 ++- avocado/plugins/xunit.py | 2 +- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/avocado/job.py b/avocado/job.py index e8ea33d2..2a36f1f6 100644 --- a/avocado/job.py +++ b/avocado/job.py @@ -178,27 +178,32 @@ class Job(object): self.test_dir = data_dir.get_test_dir() self.test_index = 1 self.status = "RUNNING" + self.result_proxy = result.TestResultProxy() self.output_manager = output.OutputManager() - def _make_test_runner(self, test_result): + def _make_test_runner(self): if hasattr(self.args, 'test_runner'): test_runner_class = self.args.test_runner else: test_runner_class = TestRunner - test_runner = test_runner_class(job=self, - test_result=test_result) - return test_runner - def _make_test_result(self, urls): - if hasattr(self.args, 'test_result'): - test_result_class = self.args.test_result - else: - test_result_class = result.HumanTestResult - if self.args is not None: - self.args.test_result_total = len(urls) - test_result = test_result_class(self.output_manager, self.args) - return test_result + self.test_runner = test_runner_class(job=self, + test_result=self.result_proxy) + + def _make_test_result(self): + if self.args: + for key in self.args.__dict__: + if key.endswith('_result'): + result_class = getattr(self.args, key) + if issubclass(result_class, result.TestResult): + result_plugin = result_class(self.output_manager, + self.args) + self.result_proxy.add_output_plugin(result_plugin) + + if not self.result_proxy.output_plugins: + default_plugin = result.HumanTestResult(self.output_manager, self.args) + self.result_proxy.add_output_plugin(default_plugin) def _run(self, urls=None, multiplex_file=None): """ @@ -248,8 +253,11 @@ class Job(object): for dct in parser.get_dicts(): params_list.append(dct) - test_result = self._make_test_result(params_list) - self.test_runner = self._make_test_runner(test_result) + if self.args is not None: + self.args.test_result_total = len(params_list) + + self._make_test_result() + self._make_test_runner() self.output_manager.start_file_logging(self.debuglog, self.loglevel) diff --git a/avocado/plugins/journal.py b/avocado/plugins/journal.py index 7ae8ff67..8bc7d418 100644 --- a/avocado/plugins/journal.py +++ b/avocado/plugins/journal.py @@ -121,4 +121,4 @@ class Journal(plugin.Plugin): def activate(self, app_args): if app_args.journal: - self.parser.set_defaults(test_result=TestResultJournal) + self.parser.set_defaults(journal_result=TestResultJournal) diff --git a/avocado/plugins/jsonresult.py b/avocado/plugins/jsonresult.py index 654f5ad1..32dcfc55 100644 --- a/avocado/plugins/jsonresult.py +++ b/avocado/plugins/jsonresult.py @@ -94,4 +94,4 @@ class JSON(plugin.Plugin): def activate(self, app_args): if app_args.json: - self.parser.set_defaults(test_result=JSONTestResult) + self.parser.set_defaults(json_result=JSONTestResult) diff --git a/avocado/plugins/vm.py b/avocado/plugins/vm.py index 79886b2c..7f52a1cf 100644 --- a/avocado/plugins/vm.py +++ b/avocado/plugins/vm.py @@ -120,6 +120,7 @@ class VMTestResult(TestResult): self.vm.remote.send_files(test_path, self.remote_test_dir) def setup(self): + self.urls = self.args.url.split() if self.args.vm_domain is None: e_msg = ('Please set Virtual Machine Domain with option ' '--vm-domain.') @@ -289,5 +290,5 @@ class RunVM(plugin.Plugin): def activate(self, app_args): if app_args.vm: - self.parser.set_defaults(test_result=VMTestResult, + self.parser.set_defaults(vm_result=VMTestResult, test_runner=VMTestRunner) diff --git a/avocado/plugins/xunit.py b/avocado/plugins/xunit.py index 4b89c321..10228866 100644 --- a/avocado/plugins/xunit.py +++ b/avocado/plugins/xunit.py @@ -222,4 +222,4 @@ class XUnit(plugin.Plugin): def activate(self, app_args): if app_args.xunit: - self.parser.set_defaults(test_result=xUnitTestResult) + self.parser.set_defaults(xunit_result=xUnitTestResult) -- GitLab