From 99df30084cc7ff1c03141cf8ae62266da1f24520 Mon Sep 17 00:00:00 2001 From: Narasimhan V Date: Mon, 11 May 2020 18:12:24 +0530 Subject: [PATCH] Log all config files for reference This commit: * Creates a folder with timestamp for logs * Creates a file with command line used to trigger the wrapper * Logs all test configs * Logs input file and no_run configs * Logs wrapper log to that folder Signed-off-by: Narasimhan V --- avocado-setup.py | 59 ++++++++++++++++++++++++++++++++++++------------ lib/helper.py | 20 ++++++++++++++-- 2 files changed, 63 insertions(+), 16 deletions(-) diff --git a/avocado-setup.py b/avocado-setup.py index 2bbd81ba..6d0023a3 100755 --- a/avocado-setup.py +++ b/avocado-setup.py @@ -26,7 +26,6 @@ import binascii from shutil import copyfile -from lib.logger import logger_init from lib import helper BASE_PATH = os.path.dirname(os.path.abspath(__file__)) @@ -47,7 +46,6 @@ TEST_DIR = "%s/tests" % BASE_PATH DATA_DIR = "%s/data" % BASE_PATH LOG_DIR = "%s/results" % BASE_PATH -logger = logger_init(filepath=BASE_PATH).getlogger() prescript_dir = CONFIGFILE.get('script-dir', 'prescriptdir') postscipt_dir = CONFIGFILE.get('script-dir', 'postscriptdir') @@ -97,9 +95,8 @@ def config(self): os.system(cmd) self.conf = cfg elif self.type == 'host': - local_cfg = "%s/%s/%s.cfg" % (TEST_CONF_PATH, - self.type, - self.shortname) + local_cfg = "%s/%s.cfg" % (TEST_CONF_PATH, + self.conf.replace('_', '/', 1)) if not os.path.isfile(local_cfg): return self.conf self.conf = local_cfg @@ -271,6 +268,7 @@ def install_optional_plugin(plugin): pass + def create_config(logdir): """ Create the local avocado config file @@ -349,7 +347,6 @@ def bootstrap(enable_kvm=False): os.makedirs(postscipt_dir) helper.copy_dir_file(postscipt, postscipt_dir) - def run_test(testsuite, avocado_bin): """ To run given testsuite @@ -403,6 +400,26 @@ def run_test(testsuite, avocado_bin): return +def log_files(test_list, log_dir): + """ + Log the test config files, input file, norun config files, command line. + """ + with open(os.path.join(log_dir, "command.txt"), "w") as fp: + fp.write(" ".join(sys.argv)) + fp.write("\n") + + no_run_tests = os.path.join(log_dir, "no_run_tests") + helper.copy_file(NORUNTEST_PATH, no_run_tests) + + config_path = os.path.join(log_dir, "test_configs") + for test in test_list: + helper.copy_file(Testsuites[test].config(), config_path) + + if args.inputfile: + input_file = os.path.join(log_dir, "input_file") + helper.copy_file(args.inputfile, input_file) + + def env_clean(): """ Clean/uninstall avocado and autotest @@ -418,7 +435,6 @@ def env_clean(): if os.path.isdir(postscipt_dir): helper.remove_file(postscipt, postscipt_dir) - def edit_mux_file(test_config_name, mux_file_path, tmp_mux_path): """ Edit the mux file with input given in input config file. @@ -611,6 +627,21 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm): default=False, help='enable bootstrap kvm tests') args = parser.parse_args() + + if args.outputdir: + # Check if it is valid path + if not os.path.isdir(os.path.abspath(args.outputdir)): + raise ValueError("No output dir") + outputdir = args.outputdir + else: + outputdir = BASE_PATH + outputdir = os.path.join(outputdir, "results") + timeObj = time.localtime(time.time()) + log_dir = os.path.join(outputdir, "%d-%d-%d_%d_%d_%d" % (timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year, + timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec)) + os.makedirs(log_dir) + logger = helper.get_logger(log_dir) + if helper.get_machine_type() == 'pHyp': args.enable_kvm = False if args.run_suite: @@ -628,13 +659,6 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm): additional_args = args.add_args if args.verbose: additional_args += ' --show-job-log' - if args.outputdir: - # Check if it valid path - if not os.path.isdir(os.path.abspath(args.outputdir)): - raise ValueError("No output dir") - outputdir = os.path.join(args.outputdir, 'results') - else: - outputdir = os.path.join(BASE_PATH, 'results') additional_args += ' --job-results-dir %s' % outputdir bootstraped = False @@ -709,6 +733,7 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm): outputdir, args.vt_type, test['test'], test['mux'], test['args']) + Testsuites[test_suite_name].conf = test_suite Testsuites_list.append(test_suite_name) if 'guest' in test_suite: @@ -720,6 +745,10 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm): Testsuites[test_suite].runstatus("Cant_Run", "Config file not present") continue + + # Log config files + log_files(Testsuites_list, log_dir) + # Run Tests for test_suite in Testsuites_list: if not Testsuites[test_suite].run == "Cant_Run": @@ -744,7 +773,9 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm): Testsuites[test_suite].run.ljust(10), Testsuites[test_suite].runsummary)) summary_output.append(Testsuites[test_suite].runlink) + summary_output.append("") logger.info("\n".join(summary_output)) + logger.info("Results and Configs logged at: %s" % log_dir) if os.path.isdir("/tmp/mux/"): logger.info("Removing temporary mux dir") diff --git a/lib/helper.py b/lib/helper.py index 6a1284ca..ec5eca78 100644 --- a/lib/helper.py +++ b/lib/helper.py @@ -22,9 +22,11 @@ from .logger import logger_init -LOG_PATH = os.path.dirname(os.path.abspath(os.path.join(__file__, os.pardir))) -logger = logger_init(filepath=LOG_PATH).getlogger() +def get_logger(logger_path): + global logger + logger = logger_init(filepath=logger_path).getlogger() + return logger def runcmd(cmd, ignore_status=False, err_str="", info_str="", debug_str=""): @@ -128,6 +130,20 @@ def get_avocado_bin(ignore_status=False): err_str="avocado command not installed or not found in path")[1] +def copy_file(source, destination): + """ + Copy source file to destination provided. + If destination does not exist, creates one. + If source file does not exist, logs error and returns. + """ + if not os.path.isdir(destination): + os.makedirs(destination) + if not os.path.isfile(source): + logger.error("File %s not present" % source) + return + shutil.copy(source, destination) + + def get_install_cmd(): """ Get the command to install, based on the distro