Skip to content

Commit 278d2f8

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 278d2f8

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed

avocado-setup.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import binascii
2626
from shutil import copyfile
2727

28-
from lib.logger import logger_init
2928
from lib import helper
3029

3130
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
@@ -45,8 +44,6 @@
4544
DATA_DIR = "%s/data" % BASE_PATH
4645
LOG_DIR = "%s/results" % BASE_PATH
4746

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

5148
class TestSuite():
5249
guest_add_args = ""
@@ -93,9 +90,8 @@ def config(self):
9390
os.system(cmd)
9491
self.conf = cfg
9592
elif self.type == 'host':
96-
local_cfg = "%s/%s/%s.cfg" % (TEST_CONF_PATH,
97-
self.type,
98-
self.shortname)
93+
local_cfg = "%s/%s.cfg" % (TEST_CONF_PATH,
94+
self.conf.replace('_', '/', 1))
9995
if not os.path.isfile(local_cfg):
10096
return self.conf
10197
self.conf = local_cfg
@@ -384,6 +380,26 @@ def run_test(testsuite, avocado_bin):
384380
return
385381

386382

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

589605
args = parser.parse_args()
606+
607+
if args.outputdir:
608+
# Check if it is valid path
609+
if not os.path.isdir(os.path.abspath(args.outputdir)):
610+
raise ValueError("No output dir")
611+
outputdir = args.outputdir
612+
else:
613+
outputdir = BASE_PATH
614+
timeObj = time.localtime(time.time())
615+
log_dir = os.path.join(outputdir, "%d-%d-%d_%d_%d_%d" % (timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year,
616+
timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec))
617+
os.makedirs(log_dir)
618+
logger = helper.get_logger(log_dir)
619+
outputdir = os.path.join(log_dir, "results")
620+
590621
if helper.get_machine_type() == 'pHyp':
591622
args.enable_kvm = False
592623
if args.run_suite:
@@ -604,13 +635,6 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
604635
additional_args = args.add_args
605636
if args.verbose:
606637
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')
614638

615639
additional_args += ' --job-results-dir %s' % outputdir
616640
bootstraped = False
@@ -685,6 +709,7 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
685709
outputdir, args.vt_type,
686710
test['test'], test['mux'],
687711
test['args'])
712+
Testsuites[test_suite_name].conf = test_suite
688713
Testsuites_list.append(test_suite_name)
689714

690715
if 'guest' in test_suite:
@@ -696,6 +721,10 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
696721
Testsuites[test_suite].runstatus("Cant_Run",
697722
"Config file not present")
698723
continue
724+
725+
# Log config files
726+
log_files(Testsuites_list, log_dir)
727+
699728
# Run Tests
700729
for test_suite in Testsuites_list:
701730
if not Testsuites[test_suite].run == "Cant_Run":
@@ -711,7 +740,9 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
711740
Testsuites[test_suite].run,
712741
Testsuites[test_suite].runsummary))
713742
summary_output.append(Testsuites[test_suite].runlink)
743+
summary_output.append("")
714744
logger.info("\n".join(summary_output))
745+
logger.info("Results and Configs logged at: %s" % log_dir)
715746

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

lib/helper.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
import os
1919
import re
2020
import sys
21+
import shutil
2122

2223
from .logger import logger_init
2324

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

2830

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

129131

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

0 commit comments

Comments
 (0)