Skip to content

Commit dfe837c

Browse files
committed
Log all config files for reference
This commit: * Creates a folder with timestamp for results * Creates a file with command line used to trigger the wrapper * Logs all test configs * Logs input file and no_run configs * Logs wrapper file to that folder * Pushes job results to that folder Signed-off-by: Narasimhan V <sim@linux.vnet.ibm.com>
1 parent d14a603 commit dfe837c

File tree

2 files changed

+62
-15
lines changed

2 files changed

+62
-15
lines changed

avocado-setup.py

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
DATA_DIR = "%s/data" % BASE_PATH
4646
LOG_DIR = "%s/results" % BASE_PATH
4747

48-
logger = logger_init(filepath=BASE_PATH).getlogger()
49-
5048

5149
class TestSuite():
5250
guest_add_args = ""
@@ -93,9 +91,8 @@ def config(self):
9391
os.system(cmd)
9492
self.conf = cfg
9593
elif self.type == 'host':
96-
local_cfg = "%s/%s/%s.cfg" % (TEST_CONF_PATH,
97-
self.type,
98-
self.shortname)
94+
local_cfg = "%s/%s.cfg" % (TEST_CONF_PATH,
95+
self.conf.replace('_','/', 1)
9996
if not os.path.isfile(local_cfg):
10097
return self.conf
10198
self.conf = local_cfg
@@ -384,6 +381,26 @@ def run_test(testsuite, avocado_bin):
384381
return
385382

386383

384+
def log_files(test_list, log_dir):
385+
"""
386+
Log the test config files, input file, norun config files, command line.
387+
"""
388+
with open(os.path.join(log_dir, "command.txt"), "w") as fp:
389+
fp.write(" ".join(sys.argv))
390+
fp.write("\n")
391+
392+
no_run_tests = os.path.join(log_dir, "no_run_tests")
393+
helper.copy_file(NORUNTEST_PATH, no_run_tests)
394+
395+
config_path = os.path.join(log_dir, "test_configs")
396+
for test in test_list:
397+
helper.copy_file(Testsuites[test].config(), config_path)
398+
399+
if args.inputfile:
400+
input_file = os.path.join(log_dir, "input_file")
401+
helper.copy_file(args.inputfile, input_file)
402+
403+
387404
def env_clean():
388405
"""
389406
Clean/uninstall avocado and autotest
@@ -587,6 +604,21 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
587604
default=False, help='enable bootstrap kvm tests')
588605

589606
args = parser.parse_args()
607+
608+
if args.outputdir:
609+
# Check if it is valid path
610+
if not os.path.isdir(os.path.abspath(args.outputdir)):
611+
raise ValueError("No output dir")
612+
outputdir = args.outputdir
613+
else:
614+
outputdir = BASE_PATH
615+
timeObj = time.localtime(time.time())
616+
log_dir = os.path.join(outputdir, "%d-%d-%d_%d_%d_%d" % (timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year,
617+
timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec))
618+
os.makedirs(log_dir)
619+
logger = helper.get_logger(log_dir)
620+
outputdir = os.path.join(log_dir, "results")
621+
590622
if helper.get_machine_type() == 'pHyp':
591623
args.enable_kvm = False
592624
if args.run_suite:
@@ -604,13 +636,6 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
604636
additional_args = args.add_args
605637
if args.verbose:
606638
additional_args += ' --show-job-log'
607-
if args.outputdir:
608-
# Check if it valid path
609-
if not os.path.isdir(os.path.abspath(args.outputdir)):
610-
raise ValueError("No output dir")
611-
outputdir = os.path.join(args.outputdir, 'results')
612-
else:
613-
outputdir = os.path.join(BASE_PATH, 'results')
614639

615640
additional_args += ' --job-results-dir %s' % outputdir
616641
bootstraped = False
@@ -685,6 +710,7 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
685710
outputdir, args.vt_type,
686711
test['test'], test['mux'],
687712
test['args'])
713+
Testsuites[test_suite_name].conf = test_suite
688714
Testsuites_list.append(test_suite_name)
689715

690716
if 'guest' in test_suite:
@@ -696,6 +722,10 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
696722
Testsuites[test_suite].runstatus("Cant_Run",
697723
"Config file not present")
698724
continue
725+
726+
# Log config files
727+
log_files(Testsuites_list, log_dir)
728+
699729
# Run Tests
700730
for test_suite in Testsuites_list:
701731
if not Testsuites[test_suite].run == "Cant_Run":
@@ -711,7 +741,9 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
711741
Testsuites[test_suite].run,
712742
Testsuites[test_suite].runsummary))
713743
summary_output.append(Testsuites[test_suite].runlink)
744+
summary_output.append("")
714745
logger.info("\n".join(summary_output))
746+
logger.info("Results and Configs logged at: %s" % log_dir)
715747

716748
if os.path.isdir("/tmp/mux/"):
717749
logger.info("Removing temporary mux dir")

lib/helper.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
from .logger import logger_init
2323

24-
LOG_PATH = os.path.dirname(os.path.abspath(os.path.join(__file__, os.pardir)))
25-
26-
logger = logger_init(filepath=LOG_PATH).getlogger()
24+
def get_logger(logger_path):
25+
global logger
26+
logger = logger_init(filepath=logger_path).getlogger()
27+
return logger
2728

2829

2930
def runcmd(cmd, ignore_status=False, err_str="", info_str="", debug_str=""):
@@ -127,6 +128,20 @@ def get_avocado_bin(ignore_status=False):
127128
err_str="avocado command not installed or not found in path")[1]
128129

129130

131+
def copy_file(source, destination):
132+
"""
133+
Copy source file to destination provided.
134+
If destination does not exist, creates one.
135+
If source file does not exist, logs error and returns.
136+
"""
137+
if not os.path.isdir(destination):
138+
os.makedirs(destination)
139+
if not os.path.isfile(source):
140+
logger.error("File %s not present" % source)
141+
return
142+
shutil.copy(source, destination)
143+
144+
130145
def get_install_cmd():
131146
"""
132147
Get the command to install, based on the distro

0 commit comments

Comments
 (0)