2626import binascii
2727from shutil import copyfile
2828
29- from lib .logger import logger_init
3029from lib import helper
3130
3231BASE_PATH = os .path .dirname (os .path .abspath (__file__ ))
4746TEST_DIR = "%s/tests" % BASE_PATH
4847DATA_DIR = "%s/data" % BASE_PATH
4948LOG_DIR = "%s/results" % BASE_PATH
50- logger = logger_init (filepath = BASE_PATH ).getlogger ()
5149prescript_dir = CONFIGFILE .get ('script-dir' , 'prescriptdir' )
5250postscipt_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+
274272def 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-
353350def 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+
406423def 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-
422438def 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" )
0 commit comments