Skip to content

Commit d9f7123

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 d9f7123

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

avocado-setup.py

Lines changed: 45 additions & 9 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 = ""
@@ -384,6 +382,30 @@ def run_test(testsuite, avocado_bin):
384382
return
385383

386384

385+
def log_files(log_dir):
386+
"""
387+
Log the test config files, input file, norun config files, command line.
388+
"""
389+
with open(os.path.join(log_dir, "command.txt"), "w") as fp:
390+
fp.write(" ".join(sys.argv))
391+
fp.write("\n")
392+
393+
no_run_tests = os.path.join(log_dir, "no_run_tests")
394+
helper.copy_file(NORUNTEST_PATH, no_run_tests)
395+
396+
config_path = os.path.join(log_dir, "test_configs")
397+
for suite in args.run_suite.split(','):
398+
if 'host' in suite:
399+
helper.copy_file("%s/%s.cfg" % (TEST_CONF_PATH, suite.replace('_', '/', 1)), config_path)
400+
elif 'guest' in suite:
401+
config_sub_path = os.path.join(config_path, suite.split("_")[1])
402+
helper.copy_file("%s/%s.cfg" % (TEST_CONF_PATH, suite.replace('_', '/', 2)), config_sub_path)
403+
404+
if args.inputfile:
405+
input_file = os.path.join(log_dir, "input_file")
406+
helper.copy_file(args.inputfile, input_file)
407+
408+
387409
def env_clean():
388410
"""
389411
Clean/uninstall avocado and autotest
@@ -587,6 +609,21 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
587609
default=False, help='enable bootstrap kvm tests')
588610

589611
args = parser.parse_args()
612+
613+
if args.outputdir:
614+
# Check if it is valid path
615+
if not os.path.isdir(os.path.abspath(args.outputdir)):
616+
raise ValueError("No output dir")
617+
outputdir = args.outputdir
618+
else:
619+
outputdir = BASE_PATH
620+
timeObj = time.localtime(time.time())
621+
log_dir = os.path.join(outputdir, "%d-%d-%d_%d_%d_%d" % (timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year,
622+
timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec))
623+
os.makedirs(log_dir)
624+
logger = helper.get_logger(log_dir)
625+
outputdir = os.path.join(log_dir, "results")
626+
590627
if helper.get_machine_type() == 'pHyp':
591628
args.enable_kvm = False
592629
if args.run_suite:
@@ -604,13 +641,6 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
604641
additional_args = args.add_args
605642
if args.verbose:
606643
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')
614644

615645
additional_args += ' --job-results-dir %s' % outputdir
616646
bootstraped = False
@@ -696,6 +726,10 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
696726
Testsuites[test_suite].runstatus("Cant_Run",
697727
"Config file not present")
698728
continue
729+
730+
# Log config files
731+
log_files(log_dir)
732+
699733
# Run Tests
700734
for test_suite in Testsuites_list:
701735
if not Testsuites[test_suite].run == "Cant_Run":
@@ -711,7 +745,9 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
711745
Testsuites[test_suite].run,
712746
Testsuites[test_suite].runsummary))
713747
summary_output.append(Testsuites[test_suite].runlink)
748+
summary_output.append("")
714749
logger.info("\n".join(summary_output))
750+
logger.info("Results and Configs logged at: %s" % log_dir)
715751

716752
if os.path.isdir("/tmp/mux/"):
717753
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)