def new_job(config): """ Produce a new job object and thus a job. :param config: command line arguments :type config: {str, str} """ with job.Job(config) as job_instance: pre_post_dispatcher = dispatcher.JobPrePostDispatcher() try: # run job pre plugins output.log_plugin_failures(pre_post_dispatcher.load_failures) pre_post_dispatcher.map_method('pre', job_instance) # second initiation stage (as a test runner) yield job_instance finally: # run job post plugins pre_post_dispatcher.map_method('post', job_instance) result_dispatcher = dispatcher.ResultDispatcher() if result_dispatcher.extensions: result_dispatcher.map_method('render', job_instance.result, job_instance)
def run(self): """ Runs all job phases, returning the test execution results. This method is supposed to be the simplified interface for jobs, that is, they run all phases of a job. :return: Integer with overall job status. See :mod:`avocado.core.exit_codes` for more information. """ assert self.tmpdir is not None, "Job.setup() not called" if self.time_start == -1: self.time_start = time.monotonic() try: self.result.tests_total = self.size pre_post_dispatcher = dispatcher.JobPrePostDispatcher() output.log_plugin_failures(pre_post_dispatcher.load_failures) pre_post_dispatcher.map_method("pre", self) self.pre_tests() return self.run_tests() except exceptions.JobBaseException as details: self.status = details.status fail_class = details.__class__.__name__ self.log.error("\nAvocado job failed: %s: %s", fail_class, details) self.exitcode |= exit_codes.AVOCADO_JOB_FAIL return self.exitcode except exceptions.OptionValidationError as details: self.log.error("\n%s", str(details)) self.exitcode |= exit_codes.AVOCADO_JOB_FAIL return self.exitcode except Exception as details: # pylint: disable=W0703 self.status = "ERROR" exc_type, exc_value, exc_traceback = sys.exc_info() tb_info = traceback.format_exception( exc_type, exc_value, exc_traceback.tb_next ) fail_class = details.__class__.__name__ self.log.error("\nAvocado crashed: %s: %s", fail_class, details) for line in tb_info: self.log.debug(line) self.log.error( "Please include the traceback info and command line" " used on your bug report" ) self.log.error("Report bugs visiting %s", _NEW_ISSUE_LINK) self.exitcode |= exit_codes.AVOCADO_FAIL return self.exitcode finally: self.post_tests() if self.time_end == -1: self.time_end = time.monotonic() self.time_elapsed = self.time_end - self.time_start self.render_results() pre_post_dispatcher.map_method("post", self)
def result_events_dispatcher(self): # 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 on first usage. # A future optimization may load it on demand. if self._result_events_dispatcher is None: self._result_events_dispatcher = dispatcher.ResultEventsDispatcher( self.config) output.log_plugin_failures( self._result_events_dispatcher.load_failures) return self._result_events_dispatcher
def run(self, config): """ Run test modules or simple tests. :param config: Configuration received from command line parser and possibly other sources. :type config: dict """ if 'output_check_record' in config: process.OUTPUT_CHECK_RECORD_MODE = config.get( 'output_check_record', None) warnings.warn( "The following arguments will be changed to boolean soon: " "sysinfo, output-check, failfast, keep-tmp, " "ignore-missing-references, sysinfo and output-check", FutureWarning) if config.get('unique_job_id') is not None: try: int(config.get('unique_job_id'), 16) if len(config.get('unique_job_id')) != 40: raise ValueError except ValueError: LOG_UI.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) try: config['job_timeout'] = time_to_seconds(config.get('job_timeout')) except ValueError as detail: LOG_UI.error(detail.args[0]) sys.exit(exit_codes.AVOCADO_FAIL) with job.Job(config) as job_instance: 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', job_instance.result, job_instance) return job_run
def run(self, args): """ Run test modules or simple tests. :param args: Command line args received from the run subparser. """ if 'output_check_record' in args: process.OUTPUT_CHECK_RECORD_MODE = getattr(args, 'output_check_record', None) if args.unique_job_id is not None: try: int(args.unique_job_id, 16) if len(args.unique_job_id) != 40: raise ValueError except ValueError: LOG_UI.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) try: args.job_timeout = time_to_seconds(args.job_timeout) except ValueError as detail: LOG_UI.error(detail.args[0]) sys.exit(exit_codes.AVOCADO_FAIL) with job.Job(args) as job_instance: 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', job_instance.result, job_instance) return job_run
def run(self, args): """ Run test modules or simple tests. :param args: Command line args received from the run subparser. """ if 'output_check_record' in args: process.OUTPUT_CHECK_RECORD_MODE = getattr(args, 'output_check_record', None) if args.unique_job_id is not None: try: int(args.unique_job_id, 16) if len(args.unique_job_id) != 40: raise ValueError except ValueError: LOG_UI.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) try: args.job_timeout = time_to_seconds(args.job_timeout) except ValueError as detail: LOG_UI.error(detail.args[0]) sys.exit(exit_codes.AVOCADO_FAIL) with job.Job(args) as job_instance: 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', job_instance.result, job_instance) return job_run
def run(self, config): """ Run test modules or simple tests. :param config: Configuration received from command line parser and possibly other sources. :type config: dict """ if 'run.output_check_record' in config: check_record = config.get('run.output_check_record') process.OUTPUT_CHECK_RECORD_MODE = check_record unique_job_id = config.get('run.unique_job_id') if unique_job_id is not None: try: int(unique_job_id, 16) if len(unique_job_id) != 40: raise ValueError except ValueError: LOG_UI.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) try: suite = TestSuite.from_config(config, name='') if suite.size == 0: sys.exit(exit_codes.AVOCADO_JOB_FAIL) except TestSuiteError as err: LOG_UI.error(err) sys.exit(exit_codes.AVOCADO_JOB_FAIL) with job.Job(config, [suite]) as job_instance: 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) return job_run
def run(self, config): namespace = 'job.replay.source_job_id' source_job_id = config.get(namespace) source_job_config = self._retrieve_source_job_config(source_job_id) if hasattr(source_job_config, namespace): del (source_job_config[namespace]) # Flag that this is indeed a replayed job, which is impossible to # tell solely based on the job.replay.source_job_id given that it # has a default value of 'latest' for convenience reasons source_job_config['job.replay.enabled'] = True with job.Job.from_config(source_job_config) as job_instance: pre_post_dispatcher = JobPrePostDispatcher() try: output.log_plugin_failures(pre_post_dispatcher.load_failures) pre_post_dispatcher.map_method('pre', job_instance) job_run = job_instance.run() finally: pre_post_dispatcher.map_method('post', job_instance) return job_run
def run(self, config): """ Run test modules or simple tests. :param config: Configuration received from command line parser and possibly other sources. :type config: dict """ if 'run.output_check_record' in config: check_record = config.get('run.output_check_record') process.OUTPUT_CHECK_RECORD_MODE = check_record warnings.warn( "The following arguments will be changed to boolean soon: " "sysinfo, output-check, failfast and keep-tmp. ", FutureWarning) unique_job_id = config.get('run.unique_job_id') if unique_job_id is not None: try: int(unique_job_id, 16) if len(unique_job_id) != 40: raise ValueError except ValueError: LOG_UI.error('Unique Job ID needs to be a 40 digit hex number') sys.exit(exit_codes.AVOCADO_FAIL) with job.Job(config) as job_instance: 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) return job_run
def __init__(self): # Catch all libc runtime errors to STDERR os.environ['LIBC_FATAL_STDERR_'] = '1' signal.signal(signal.SIGTSTP, signal.SIG_IGN) # ignore ctrl+z self.parser = Parser() output.early_start() try: self.cli_dispatcher = CLIDispatcher() self.cli_cmd_dispatcher = CLICmdDispatcher() output.log_plugin_failures(self.cli_dispatcher.load_failures + self.cli_cmd_dispatcher.load_failures) self.parser.start() if self.cli_cmd_dispatcher.extensions: self.cli_cmd_dispatcher.map_method('configure', self.parser) if self.cli_dispatcher.extensions: self.cli_dispatcher.map_method('configure', self.parser) self.parser.finish() if self.cli_dispatcher.extensions: self.cli_dispatcher.map_method('run', self.parser.args) except SystemExit as e: # If someone tries to exit Avocado, we should first close the # STD_OUTPUT and only then exit. setattr(self.parser.args, 'paginator', 'off') output.reconfigure(self.parser.args) STD_OUTPUT.close() sys.exit(e.code) except: # For any other exception we also need to close the STD_OUTPUT. setattr(self.parser.args, 'paginator', 'off') output.reconfigure(self.parser.args) STD_OUTPUT.close() raise else: # In case of no exceptions, we just reconfigure the output. output.reconfigure(self.parser.args)
def _load_cli_plugins(self): self._cli_dispatcher = CLIDispatcher() self._cli_cmd_dispatcher = CLICmdDispatcher() output.log_plugin_failures(self._cli_dispatcher.load_failures + self._cli_cmd_dispatcher.load_failures)