Skip to content

Commit 99df300

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 ced6ca8 commit 99df300

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed

avocado-setup.py

Lines changed: 45 additions & 14 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
@@ -271,6 +268,7 @@ def install_optional_plugin(plugin):
271268
pass
272269

273270

271+
274272
def create_config(logdir):
275273
"""
276274
Create the local avocado config file
@@ -349,7 +347,6 @@ def bootstrap(enable_kvm=False):
349347
os.makedirs(postscipt_dir)
350348
helper.copy_dir_file(postscipt, postscipt_dir)
351349

352-
353350
def run_test(testsuite, avocado_bin):
354351
"""
355352
To run given testsuite
@@ -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
@@ -418,7 +435,6 @@ def env_clean():
418435
if os.path.isdir(postscipt_dir):
419436
helper.remove_file(postscipt, postscipt_dir)
420437

421-
422438
def edit_mux_file(test_config_name, mux_file_path, tmp_mux_path):
423439
"""
424440
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):
611627
default=False, help='enable bootstrap kvm tests')
612628

613629
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(outputdir, "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+
614645
if helper.get_machine_type() == 'pHyp':
615646
args.enable_kvm = False
616647
if args.run_suite:
@@ -628,13 +659,6 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
628659
additional_args = args.add_args
629660
if args.verbose:
630661
additional_args += ' --show-job-log'
631-
if args.outputdir:
632-
# Check if it valid path
633-
if not os.path.isdir(os.path.abspath(args.outputdir)):
634-
raise ValueError("No output dir")
635-
outputdir = os.path.join(args.outputdir, 'results')
636-
else:
637-
outputdir = os.path.join(BASE_PATH, 'results')
638662

639663
additional_args += ' --job-results-dir %s' % outputdir
640664
bootstraped = False
@@ -709,6 +733,7 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
709733
outputdir, args.vt_type,
710734
test['test'], test['mux'],
711735
test['args'])
736+
Testsuites[test_suite_name].conf = test_suite
712737
Testsuites_list.append(test_suite_name)
713738

714739
if 'guest' in test_suite:
@@ -720,6 +745,10 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
720745
Testsuites[test_suite].runstatus("Cant_Run",
721746
"Config file not present")
722747
continue
748+
749+
# Log config files
750+
log_files(Testsuites_list, log_dir)
751+
723752
# Run Tests
724753
for test_suite in Testsuites_list:
725754
if not Testsuites[test_suite].run == "Cant_Run":
@@ -744,7 +773,9 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
744773
Testsuites[test_suite].run.ljust(10),
745774
Testsuites[test_suite].runsummary))
746775
summary_output.append(Testsuites[test_suite].runlink)
776+
summary_output.append("")
747777
logger.info("\n".join(summary_output))
778+
logger.info("Results and Configs logged at: %s" % log_dir)
748779

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

lib/helper.py

Lines changed: 18 additions & 2 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

0 commit comments

Comments
 (0)