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: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 249005cf
...@@ -178,27 +178,32 @@ class Job(object): ...@@ -178,27 +178,32 @@ class Job(object):
self.test_dir = data_dir.get_test_dir() self.test_dir = data_dir.get_test_dir()
self.test_index = 1 self.test_index = 1
self.status = "RUNNING" self.status = "RUNNING"
self.result_proxy = result.TestResultProxy()
self.output_manager = output.OutputManager() self.output_manager = output.OutputManager()
def _make_test_runner(self, test_result): def _make_test_runner(self):
if hasattr(self.args, 'test_runner'): if hasattr(self.args, 'test_runner'):
test_runner_class = self.args.test_runner test_runner_class = self.args.test_runner
else: else:
test_runner_class = TestRunner test_runner_class = TestRunner
test_runner = test_runner_class(job=self,
test_result=test_result)
return test_runner
def _make_test_result(self, urls): self.test_runner = test_runner_class(job=self,
if hasattr(self.args, 'test_result'): test_result=self.result_proxy)
test_result_class = self.args.test_result
else: def _make_test_result(self):
test_result_class = result.HumanTestResult if self.args:
if self.args is not None: for key in self.args.__dict__:
self.args.test_result_total = len(urls) if key.endswith('_result'):
test_result = test_result_class(self.output_manager, self.args) result_class = getattr(self.args, key)
return test_result 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): def _run(self, urls=None, multiplex_file=None):
""" """
...@@ -248,8 +253,11 @@ class Job(object): ...@@ -248,8 +253,11 @@ class Job(object):
for dct in parser.get_dicts(): for dct in parser.get_dicts():
params_list.append(dct) params_list.append(dct)
test_result = self._make_test_result(params_list) if self.args is not None:
self.test_runner = self._make_test_runner(test_result) 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.output_manager.start_file_logging(self.debuglog,
self.loglevel) self.loglevel)
......
...@@ -121,4 +121,4 @@ class Journal(plugin.Plugin): ...@@ -121,4 +121,4 @@ class Journal(plugin.Plugin):
def activate(self, app_args): def activate(self, app_args):
if app_args.journal: if app_args.journal:
self.parser.set_defaults(test_result=TestResultJournal) self.parser.set_defaults(journal_result=TestResultJournal)
...@@ -94,4 +94,4 @@ class JSON(plugin.Plugin): ...@@ -94,4 +94,4 @@ class JSON(plugin.Plugin):
def activate(self, app_args): def activate(self, app_args):
if app_args.json: if app_args.json:
self.parser.set_defaults(test_result=JSONTestResult) self.parser.set_defaults(json_result=JSONTestResult)
...@@ -120,6 +120,7 @@ class VMTestResult(TestResult): ...@@ -120,6 +120,7 @@ class VMTestResult(TestResult):
self.vm.remote.send_files(test_path, self.remote_test_dir) self.vm.remote.send_files(test_path, self.remote_test_dir)
def setup(self): def setup(self):
self.urls = self.args.url.split()
if self.args.vm_domain is None: if self.args.vm_domain is None:
e_msg = ('Please set Virtual Machine Domain with option ' e_msg = ('Please set Virtual Machine Domain with option '
'--vm-domain.') '--vm-domain.')
...@@ -289,5 +290,5 @@ class RunVM(plugin.Plugin): ...@@ -289,5 +290,5 @@ class RunVM(plugin.Plugin):
def activate(self, app_args): def activate(self, app_args):
if app_args.vm: if app_args.vm:
self.parser.set_defaults(test_result=VMTestResult, self.parser.set_defaults(vm_result=VMTestResult,
test_runner=VMTestRunner) test_runner=VMTestRunner)
...@@ -222,4 +222,4 @@ class XUnit(plugin.Plugin): ...@@ -222,4 +222,4 @@ class XUnit(plugin.Plugin):
def activate(self, app_args): def activate(self, app_args):
if app_args.xunit: if app_args.xunit:
self.parser.set_defaults(test_result=xUnitTestResult) self.parser.set_defaults(xunit_result=xUnitTestResult)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册