def run(self, args): log = logging.getLogger("avocado.app") log.info('Config files read (in order):') for cfg_path in settings.config_paths: log.debug(' %s' % cfg_path) if settings.config_paths_failed: log.error('\nConfig files that failed to read:') for cfg_path in settings.config_paths_failed: log.error(' %s' % cfg_path) log.debug("") if not args.datadir: blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" log.debug(format_str, 'Section.Key', 'Value') for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) log.debug(format_str, config_key, value[1]) else: log.debug("Avocado replaces config dirs that can't be accessed") log.debug("with sensible defaults. Please edit your local config") log.debug("file to customize values") log.debug('') log.info('Avocado Data Directories:') log.debug(' base ' + data_dir.get_base_dir()) log.debug(' tests ' + data_dir.get_test_dir()) log.debug(' data ' + data_dir.get_data_dir()) log.debug(' logs ' + data_dir.get_logs_dir())
def handle_default(): LOG_UI.info("Config files read (in order, '*' means the file exists " "and had been read):") # Getting from settings because is already sorted config = settings.as_dict() for cfg_path in settings.all_config_paths: if cfg_path in settings.config_paths: LOG_UI.debug(' * %s', cfg_path) else: LOG_UI.debug(' %s', cfg_path) LOG_UI.debug("") if not config.get('config.datadir'): blength = 0 for namespace, value in config.items(): clength = len(namespace) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" LOG_UI.debug(format_str, 'Section.Key', 'Value') for namespace, value in config.items(): LOG_UI.debug(format_str, namespace, value) else: LOG_UI.debug("Avocado replaces config dirs that can't be accessed") LOG_UI.debug("with sensible defaults. Please edit your local config") LOG_UI.debug("file to customize values") LOG_UI.debug('') LOG_UI.info('Avocado Data Directories:') LOG_UI.debug(' base %s', data_dir.get_base_dir()) LOG_UI.debug(' tests %s', data_dir.get_test_dir()) LOG_UI.debug(' data %s', data_dir.get_data_dir()) LOG_UI.debug(' logs %s', data_dir.get_logs_dir()) LOG_UI.debug(' cache %s', ", ".join(data_dir.get_cache_dirs()))
def run(self, args): LOG_UI.info('Config files read (in order):') for cfg_path in settings.config_paths: LOG_UI.debug(' %s' % cfg_path) if settings.config_paths_failed: LOG_UI.error('\nConfig files that failed to read:') for cfg_path in settings.config_paths_failed: LOG_UI.error(' %s' % cfg_path) LOG_UI.debug("") if not args.datadir: blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" LOG_UI.debug(format_str, 'Section.Key', 'Value') for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) LOG_UI.debug(format_str, config_key, value[1]) else: LOG_UI.debug("Avocado replaces config dirs that can't be accessed") LOG_UI.debug("with sensible defaults. Please edit your local config") LOG_UI.debug("file to customize values") LOG_UI.debug('') LOG_UI.info('Avocado Data Directories:') LOG_UI.debug(' base ' + data_dir.get_base_dir()) LOG_UI.debug(' tests ' + data_dir.get_test_dir()) LOG_UI.debug(' data ' + data_dir.get_data_dir()) LOG_UI.debug(' logs ' + data_dir.get_logs_dir()) LOG_UI.debug(' cache ' + ", ".join(data_dir.get_cache_dirs()))
def run(self, config): LOG_UI.info("Config files read (in order, '*' means the file exists " "and had been read):") for cfg_path in settings.all_config_paths: if cfg_path in settings.config_paths: LOG_UI.debug(' * %s', cfg_path) else: LOG_UI.debug(' %s', cfg_path) LOG_UI.debug("") if not config.get("datadir"): blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" LOG_UI.debug(format_str, 'Section.Key', 'Value') for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) LOG_UI.debug(format_str, config_key, value[1]) else: LOG_UI.debug("Avocado replaces config dirs that can't be accessed") LOG_UI.debug("with sensible defaults. Please edit your local config") LOG_UI.debug("file to customize values") LOG_UI.debug('') LOG_UI.info('Avocado Data Directories:') LOG_UI.debug(' base %s', data_dir.get_base_dir()) LOG_UI.debug(' tests %s', data_dir.get_test_dir()) LOG_UI.debug(' data %s', data_dir.get_data_dir()) LOG_UI.debug(' logs %s', data_dir.get_logs_dir()) LOG_UI.debug(' cache %s', ", ".join(data_dir.get_cache_dirs()))
def run(self, args): LOG_UI.info("Config files read (in order, '*' means the file exists " "and had been read):") for cfg_path in settings.all_config_paths: if cfg_path in settings.config_paths: LOG_UI.debug(' * %s', cfg_path) else: LOG_UI.debug(' %s', cfg_path) LOG_UI.debug("") if not args.datadir: blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" LOG_UI.debug(format_str, 'Section.Key', 'Value') for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) LOG_UI.debug(format_str, config_key, value[1]) else: LOG_UI.debug("Avocado replaces config dirs that can't be accessed") LOG_UI.debug("with sensible defaults. Please edit your local config") LOG_UI.debug("file to customize values") LOG_UI.debug('') LOG_UI.info('Avocado Data Directories:') LOG_UI.debug(' base %s', data_dir.get_base_dir()) LOG_UI.debug(' tests %s', data_dir.get_test_dir()) LOG_UI.debug(' data %s', data_dir.get_data_dir()) LOG_UI.debug(' logs %s', data_dir.get_logs_dir()) LOG_UI.debug(' cache %s', ", ".join(data_dir.get_cache_dirs()))
def run(self, args): view = output.View() view.notify(event="message", msg='Avocado Data Directories:') view.notify(event="message", msg=' base dir ' + data_dir.get_base_dir()) view.notify(event="message", msg=' tests dir ' + data_dir.get_test_dir()) view.notify(event="message", msg=' data dir ' + data_dir.get_data_dir()) view.notify(event="message", msg=' logs dir ' + data_dir.get_logs_dir()) view.notify(event="message", msg=' tmp dir ' + data_dir.get_tmp_dir())
def list_data_dirs(self, args): bcolors = output.colors pipe = output.get_paginator() pipe.write(bcolors.header_str('Avocado Data Directories:')) pipe.write('\n base dir: ' + data_dir.get_base_dir()) pipe.write('\n tests dir: ' + data_dir.get_test_dir()) pipe.write('\n data dir: ' + data_dir.get_data_dir()) pipe.write('\n logs dir: ' + data_dir.get_logs_dir()) pipe.write('\n tmp dir: ' + data_dir.get_tmp_dir())
def run(self, args): view = output.View(use_paginator=(args.paginator == 'on')) try: view.notify(event="message", msg='Config files read (in order):') for cfg_path in settings.config_paths: view.notify(event="message", msg=' %s' % cfg_path) if settings.config_paths_failed: view.notify(event="minor", msg='') view.notify(event="error", msg='Config files that failed to read:') for cfg_path in settings.config_paths_failed: view.notify(event="error", msg=' %s' % cfg_path) view.notify(event="minor", msg='') if not args.datadir: blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" view.notify(event="minor", msg=format_str % ('Section.Key', 'Value')) for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) view.notify(event="minor", msg=format_str % (config_key, value[1])) else: view.notify( event="minor", msg="Avocado replaces config dirs that can't be accessed") view.notify( event="minor", msg="with sensible defaults. Please edit your local config" ) view.notify(event="minor", msg="file to customize values") view.notify(event="message", msg='') view.notify(event="message", msg='Avocado Data Directories:') view.notify(event="minor", msg=' base ' + data_dir.get_base_dir()) view.notify(event="minor", msg=' tests ' + data_dir.get_test_dir()) view.notify(event="minor", msg=' data ' + data_dir.get_data_dir()) view.notify(event="minor", msg=' logs ' + data_dir.get_logs_dir()) finally: view.cleanup()
def run(self, config): results = {} jobs_dir = get_logs_dir() for result in glob(os.path.join(jobs_dir, '*/results.json')): with open(result, 'r') as fp: job = json.load(fp) results[job['job_id']] = result subcommand = config.get('jobs_subcommand') if subcommand == 'list': return self.handle_list_command(results) elif subcommand == 'show': return self.handle_show_command(config) elif subcommand == 'get-output-files': return self.handle_output_files_command(config) return exit_codes.AVOCADO_ALL_OK
def run(self, config): results = {} jobs_dir = get_logs_dir() for result in glob(os.path.join(jobs_dir, "*/results.json")): with open(result, "r", encoding="utf-8") as fp: job = json.load(fp) results[job["job_id"]] = result subcommand = config.get("jobs_subcommand") if subcommand == "list": return self.handle_list_command(results) elif subcommand == "show": return self.handle_show_command(config) elif subcommand == "get-output-files": return self.handle_output_files_command(config) return exit_codes.AVOCADO_ALL_OK
def run_but_fail_before_create_job_dir(self, complement_args, expected_rc): """ Runs avocado but checks that it fails before creating the job dir :param complement_args: the complement arguments to an 'avocado run' command line """ os.chdir(basedir) log_dir = data_dir.get_logs_dir() self.assertIsNotNone(log_dir) job = job_id.create_unique_job_id() cmd_line = '%s run --sysinfo=off --force-job-id=%%s %%s' % AVOCADO cmd_line %= (job, complement_args) result = process.run(cmd_line, ignore_status=True) self.assertEqual(result.exit_status, expected_rc, 'Avocado did not return rc %d:\n%s' % (expected_rc, result)) path_job_glob = os.path.join(log_dir, "job-*-%s" % job[0:7]) self.assertEquals(glob.glob(path_job_glob), [])
def run_but_fail_before_create_job_dir(self, complement_args, expected_rc): """ Runs avocado but checks that it fails before creating the job dir :param complement_args: the complement arguments to an 'avocado run' command line """ os.chdir(BASEDIR) log_dir = data_dir.get_logs_dir() self.assertIsNotNone(log_dir) job = job_id.create_unique_job_id() cmd_line = '%s run --disable-sysinfo --force-job-id=%%s %%s' % AVOCADO cmd_line %= (job, complement_args) result = process.run(cmd_line, ignore_status=True) self.assertEqual(result.exit_status, expected_rc, 'Avocado did not return rc %d:\n%s' % (expected_rc, result)) path_job_glob = os.path.join(log_dir, "job-*-%s" % job[0:7]) self.assertEqual(glob.glob(path_job_glob), [])
def run(self, args): view = output.View(use_paginator=(args.paginator == 'on')) try: view.notify(event="message", msg='Config files read (in order):') for cfg_path in settings.config_paths: view.notify(event="message", msg=' %s' % cfg_path) if settings.config_paths_failed: view.notify(event="minor", msg='') view.notify(event="error", msg='Config files that failed to read:') for cfg_path in settings.config_paths_failed: view.notify(event="error", msg=' %s' % cfg_path) view.notify(event="minor", msg='') if not args.datadir: blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" view.notify(event="minor", msg=format_str % ('Section.Key', 'Value')) for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) view.notify(event="minor", msg=format_str % (config_key, value[1])) else: view.notify(event="minor", msg="Avocado replaces config dirs that can't be accessed") view.notify(event="minor", msg="with sensible defaults. Please edit your local config") view.notify(event="minor", msg="file to customize values") view.notify(event="message", msg='') view.notify(event="message", msg='Avocado Data Directories:') view.notify(event="minor", msg=' base ' + data_dir.get_base_dir()) view.notify(event="minor", msg=' tests ' + data_dir.get_test_dir()) view.notify(event="minor", msg=' data ' + data_dir.get_data_dir()) view.notify(event="minor", msg=' logs ' + data_dir.get_logs_dir()) finally: view.cleanup()
print "%-40s %-15s %-15s %-15s %-10s %-10s" % ( "CaseName", "Status", "StartTime", "EndTime", "Result", "TimeElapsed") else: print "%-40s %-15s %-10s" % ("CaseName", "Status", "Result") for row in records: if not skip_timestamp: print "%s %s %s %s %s %s" % ( row[0], row[1], row[2], row[3], colour_result(row[4]), row[5]) else: print "%s %s %s" % (row[0], row[1], colour_result(row[4])) summarise_records(records) if __name__ == "__main__": default_results_dir = os.path.join(data_dir.get_logs_dir(), 'latest') parser = argparse.ArgumentParser(description="Avocado journal dump tool") parser.add_argument( '-d', '--test-results-dir', action='store', default=default_results_dir, dest='results_dir', help="avocado test results dir, Default: %s" % default_results_dir) parser.add_argument( '-s', '--skip-timestamp', action='store_true', default=False, dest='skip_timestamp',
con.close() return records def print_data(records): """ Print formated tests status info""" if not records: return print "%-40s %-15s %-15s %-15s %-10s %-10s" % ( "CaseName", "Status", "StartTime", "EndTime", "Result", "TimeElapsed") for row in records: print "%s %s %s %s %s %s" % row if __name__ == "__main__": default_results_dir = os.path.join(data_dir.get_logs_dir(), 'latest') parser = argparse.ArgumentParser(description="Avocado journal dump tool") parser.add_argument('-d', '--test-results-dir', action='store', default=default_results_dir, dest='results_dir', help="avocado test results dir, Default: %s" % default_results_dir) parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0') arguments = parser.parse_args() db_file = os.path.join(arguments.results_dir, '.journal.sqlite') if not os.path.isfile(db_file):
fail_reason = None formatted['fail_reason'] = fail_reason formatted['logdir'] = os.path.basename(test['logdir']) self.tests.append(formatted) class TestJob(object): def __init__(self, log_dir): self.logdir = log_dir self.args = type('', tuple(), dict()) self.args.html_job_result = 'on' self.args.html_output = None self.args.open_browser = False self.args.stdout_claimed_by = None if __name__ == '__main__': if len(sys.argv) != 2: print 'a job is needed' sys.exit(1) log_dir = os.path.join(data_dir.get_logs_dir(), sys.argv[1]) job = TestJob(log_dir) result = TestResult(os.path.join(log_dir, 'results.json')) outputer = avocado_result_html.HTMLResult() outputer.render(result, job)