提交 5c375c51 编写于 作者: C Cleber Rosa

Job Pre/Post plugins: move them to the appropriate location

The JobPre and JobPost plugin interfaces were intended to be run
before and after the job, but in reality they have been executed
at different points *within* the job execution.

This puts the execution of those plugins at their original intended
location:

 * Plugins implementing JobPre will be executed right after the Job
   instance is created, *before any other action*, such as the
   creation of the test suite.

 * Plugins implementing JobPost will be executed right after the Job
   instance `run()` method.

 * Plugins implementing `Result` will be executed after JobPost ones.

Users relying on the old location please take notice.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 a2dad4aa
......@@ -122,9 +122,6 @@ class Job(object):
#: test was found during resolution.
self.test_suite = None
# A job may not have a dispatcher for pre/post tests execution plugins
self._job_pre_post_dispatcher = None
# The result events dispatcher is shared with the test runner.
# Because of our goal to support using the phases of a job
# freely, let's get the result events dispatcher ready early.
......@@ -422,11 +419,8 @@ class Job(object):
Run the pre tests execution hooks
By default this runs the plugins that implement the
:class:`avocado.core.plugin_interfaces.JobPre` interface.
:class:`avocado.core.plugin_interfaces.JobPreTests` interface.
"""
self._job_pre_post_dispatcher = dispatcher.JobPrePostDispatcher()
output.log_plugin_failures(self._job_pre_post_dispatcher.load_failures)
self._job_pre_post_dispatcher.map_method('pre', self)
self._result_events_dispatcher.map_method('pre_tests', self)
def run_tests(self):
......@@ -472,12 +466,9 @@ class Job(object):
Run the post tests execution hooks
By default this runs the plugins that implement the
:class:`avocado.core.plugin_interfaces.JobPost` interface.
:class:`avocado.core.plugin_interfaces.JobPostTests` interface.
"""
if self._job_pre_post_dispatcher is None:
self._job_pre_post_dispatcher = dispatcher.JobPrePostDispatcher()
output.log_plugin_failures(self._job_pre_post_dispatcher.load_failures)
self._job_pre_post_dispatcher.map_method('post', self)
self._result_events_dispatcher.map_method('post_tests', self)
def run(self):
"""
......
......@@ -573,7 +573,6 @@ class TestRunner(object):
if self.job.sysinfo is not None:
self.job.sysinfo.end_job_hook()
self.result.end_tests()
self.job._result_events_dispatcher.map_method('post_tests', self.job)
self.job.funcatexit.run()
signal.signal(signal.SIGTSTP, signal.SIG_IGN)
return summary
......@@ -23,8 +23,10 @@ import sys
from avocado.core import exit_codes
from avocado.core import job
from avocado.core import loader
from avocado.core import output
from avocado.core.plugin_interfaces import CLICmd
from avocado.core.dispatcher import ResultDispatcher
from avocado.core.dispatcher import JobPrePostDispatcher
from avocado.core.settings import settings
from avocado.utils.data_structures import time_to_seconds
......@@ -165,8 +167,19 @@ class Run(CLICmd):
except ValueError as e:
log.error(e.message)
sys.exit(exit_codes.AVOCADO_FAIL)
job_instance = job.Job(args)
job_run = job_instance.run()
pre_post_dispatcher = JobPrePostDispatcher()
try:
# Run JobPre plugins
output.log_plugin_failures(pre_post_dispatcher.load_failures)
pre_post_dispatcher.map_method('pre', job_instance)
job_run = job_instance.run()
finally:
# Run JobPost plugins
pre_post_dispatcher.map_method('post', job_instance)
result_dispatcher = ResultDispatcher()
if result_dispatcher.extensions:
result_dispatcher.map_method('render',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册