Skip to content

Commit ac08b57

Browse files
committed
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 <sim@linux.vnet.ibm.com>
1 parent 8225de2 commit ac08b57

File tree

2 files changed

+63
-15
lines changed

2 files changed

+63
-15
lines changed

avocado-setup.py

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

29-
from lib.logger import logger_init
3029
from lib import helper
3130

3231
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
@@ -47,7 +46,6 @@
4746
TEST_DIR = "%s/tests" % BASE_PATH
4847
DATA_DIR = "%s/data" % BASE_PATH
4948
LOG_DIR = "%s/results" % BASE_PATH
50-
logger = logger_init(filepath=BASE_PATH).getlogger()
5149
prescript_dir=CONFIGFILE.get('script-dir', 'prescriptdir')
5250
postscipt_dir=CONFIGFILE.get('script-dir', 'postscriptdir')
5351

@@ -97,9 +95,8 @@ def config(self):
9795
os.system(cmd)
9896
self.conf = cfg
9997
elif self.type == 'host':
100-
local_cfg = "%s/%s/%s.cfg" % (TEST_CONF_PATH,
101-
self.type,
102-
self.shortname)
98+
local_cfg = "%s/%s.cfg" % (TEST_CONF_PATH,
99+
self.conf.replace('_', '/', 1))
103100
if not os.path.isfile(local_cfg):
104101
return self.conf
105102
self.conf = local_cfg
@@ -403,6 +400,26 @@ def run_test(testsuite, avocado_bin):
403400
return
404401

405402

403+
def log_files(test_list, log_dir):
404+
"""
405+
Log the test config files, input file, norun config files, command line.
406+
"""
407+
with open(os.path.join(log_dir, "command.txt"), "w") as fp:
408+
fp.write(" ".join(sys.argv))
409+
fp.write("\n")
410+
411+
no_run_tests = os.path.join(log_dir, "no_run_tests")
412+
helper.copy_file(NORUNTEST_PATH, no_run_tests)
413+
414+
config_path = os.path.join(log_dir, "test_configs")
415+
for test in test_list:
416+
helper.copy_file(Testsuites[test].config(), config_path)
417+
418+
if args.inputfile:
419+
input_file = os.path.join(log_dir, "input_file")
420+
helper.copy_file(args.inputfile, input_file)
421+
422+
406423
def env_clean():
407424
"""
408425
Clean/uninstall avocado and autotest
@@ -610,6 +627,21 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
610627
default=False, help='enable bootstrap kvm tests')
611628

612629
args = parser.parse_args()
630+
631+
if args.outputdir:
632+
# Check if it is valid path
633+
if not os.path.isdir(os.path.abspath(args.outputdir)):
634+
raise ValueError("No output dir")
635+
outputdir = args.outputdir
636+
else:
637+
outputdir = BASE_PATH
638+
outputdir = os.path.join(log_dir, "results")
639+
timeObj = time.localtime(time.time())
640+
log_dir = os.path.join(outputdir, "%d-%d-%d_%d_%d_%d" % (timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year,
641+
timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec))
642+
os.makedirs(log_dir)
643+
logger = helper.get_logger(log_dir)
644+
613645
if helper.get_machine_type() == 'pHyp':
614646
args.enable_kvm = False
615647
if args.run_suite:
@@ -627,13 +659,6 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
627659
additional_args = args.add_args
628660
if args.verbose:
629661
additional_args += ' --show-job-log'
630-
if args.outputdir:
631-
# Check if it valid path
632-
if not os.path.isdir(os.path.abspath(args.outputdir)):
633-
raise ValueError("No output dir")
634-
outputdir = os.path.join(args.outputdir, 'results')
635-
else:
636-
outputdir = os.path.join(BASE_PATH, 'results')
637662

638663
additional_args += ' --job-results-dir %s' % outputdir
639664
bootstraped = False
@@ -708,6 +733,7 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
708733
outputdir, args.vt_type,
709734
test['test'], test['mux'],
710735
test['args'])
736+
Testsuites[test_suite_name].conf = test_suite
711737
Testsuites_list.append(test_suite_name)
712738

713739
if 'guest' in test_suite:
@@ -719,6 +745,10 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
719745
Testsuites[test_suite].runstatus("Cant_Run",
720746
"Config file not present")
721747
continue
748+
749+
# Log config files
750+
log_files(Testsuites_list, log_dir)
751+
722752
# Run Tests
723753
for test_suite in Testsuites_list:
724754
if not Testsuites[test_suite].run == "Cant_Run":
@@ -743,7 +773,9 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
743773
Testsuites[test_suite].run.ljust(10),
744774
Testsuites[test_suite].runsummary))
745775
summary_output.append(Testsuites[test_suite].runlink)
776+
summary_output.append("")
746777
logger.info("\n".join(summary_output))
778+
logger.info("Results and Configs logged at: %s" % log_dir)
747779

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

lib/helper.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
from .logger import logger_init
2424

25-
LOG_PATH = os.path.dirname(os.path.abspath(os.path.join(__file__, os.pardir)))
2625

27-
logger = logger_init(filepath=LOG_PATH).getlogger()
26+
def get_logger(logger_path):
27+
global logger
28+
logger = logger_init(filepath=logger_path).getlogger()
29+
return logger
2830

2931

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

130132

133+
def copy_file(source, destination):
134+
"""
135+
Copy source file to destination provided.
136+
If destination does not exist, creates one.
137+
If source file does not exist, logs error and returns.
138+
"""
139+
if not os.path.isdir(destination):
140+
os.makedirs(destination)
141+
if not os.path.isfile(source):
142+
logger.error("File %s not present" % source)
143+
return
144+
shutil.copy(source, destination)
145+
146+
131147
def get_install_cmd():
132148
"""
133149
Get the command to install, based on the distro
@@ -178,4 +194,4 @@ def remove_file(src, dest):
178194
d_file = os.path.join(dest, item)
179195
if os.path.exists(d_file):
180196
os.remove(d_file)
181-
logger.debug("%s file deleted" % d_file)
197+
logger.debug("%s file deleted" % d_file)

0 commit comments

Comments
 (0)