def run(self, config): hint_filepath = '.avocado.hint' hint = None if os.path.exists(hint_filepath): hint = HintParser(hint_filepath) resolutions = resolver.resolve(config.get('nrun.references'), hint) tasks = job.resolutions_to_tasks(resolutions, config) # pylint: disable=W0201 self.pending_tasks, missing_requirements = nrunner.check_tasks_requirements( tasks) if missing_requirements: missing_tasks_msg = "\n".join( [str(t) for t in missing_requirements]) LOG_UI.warning( 'Tasks will not be run due to missing requirements: %s', missing_tasks_msg) if not self.pending_tasks: LOG_UI.error('No test to be executed, exiting...') sys.exit(exit_codes.AVOCADO_JOB_FAIL) if not config.get('nrun.disable_task_randomization'): random.shuffle(self.pending_tasks) self.spawned_tasks = [] # pylint: disable=W0201 try: if config.get('nrun.spawners.podman.enabled'): if not os.path.exists(PodmanSpawner.PODMAN_BIN): msg = ('Podman Spawner selected, but podman binary "%s" ' 'is not available on the system. Please install ' 'podman before attempting to use this feature.') msg %= PodmanSpawner.PODMAN_BIN LOG_UI.error(msg) sys.exit(exit_codes.AVOCADO_JOB_FAIL) self.spawner = PodmanSpawner() # pylint: disable=W0201 else: self.spawner = ProcessSpawner() # pylint: disable=W0201 listen = config.get('nrun.status_server.listen') verbose = config.get('core.verbose') self.status_server = nrunner.StatusServer( listen, # pylint: disable=W0201 [t.identifier for t in self.pending_tasks], verbose) self.status_server.start() parallel_tasks = config.get('nrun.parallel_tasks') loop = asyncio.get_event_loop() loop.run_until_complete(self.spawn_tasks(parallel_tasks)) loop.run_until_complete(self.status_server.wait()) self.report_results() exit_code = exit_codes.AVOCADO_ALL_OK if self.status_server.result.get('fail') is not None: exit_code |= exit_codes.AVOCADO_TESTS_FAIL elif self.status_server.result.get('error') is not None: exit_code |= exit_codes.AVOCADO_TESTS_FAIL return exit_code except Exception as e: # pylint: disable=W0703 LOG_UI.error(e) return exit_codes.AVOCADO_FAIL
def main(): """Basic example on how a download client command line could be. This probably will be integrated with the following command line: $ avocado job <id> download-output <task-id> Or something like that. """ job_id, task_id, dst_path = process_args() spawner_name = discover_spawner(job_id) if spawner_name == 'ProcessSpawner': spawner = ProcessSpawner() elif spawner_name == 'PodmanSpawner': spawner = PodmanSpawner() print("Downloading...") try: for filename, stream in spawner.stream_output(job_id, task_id): destination = os.path.join(dst_path, filename) save_stream_to_file(stream, destination) except SpawnerException as ex: print("Error: Failed to download: {}. Exiting...".format(ex)) sys.exit(-1)