Skip to content

Commit

Permalink
Log all config files for reference
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
narasimhan-v committed Apr 26, 2020
1 parent d14a603 commit 50fcf02
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 15 deletions.
56 changes: 44 additions & 12 deletions avocado-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
DATA_DIR = "%s/data" % BASE_PATH
LOG_DIR = "%s/results" % BASE_PATH

logger = logger_init(filepath=BASE_PATH).getlogger()


class TestSuite():
guest_add_args = ""
Expand Down Expand Up @@ -93,9 +91,8 @@ def config(self):
os.system(cmd)
self.conf = cfg
elif self.type == 'host':
local_cfg = "%s/%s/%s.cfg" % (TEST_CONF_PATH,
self.type,
self.shortname)
local_cfg = "%s/%s.cfg" % (TEST_CONF_PATH,
self.conf.replace('_', '/', 1))
if not os.path.isfile(local_cfg):
return self.conf
self.conf = local_cfg
Expand Down Expand Up @@ -384,6 +381,26 @@ def run_test(testsuite, avocado_bin):
return


def log_files(test_list, log_dir):
"""
Log the test config files, input file, norun config files, command line.
"""
with open(os.path.join(log_dir, "command.txt"), "w") as fp:
fp.write(" ".join(sys.argv))
fp.write("\n")

no_run_tests = os.path.join(log_dir, "no_run_tests")
helper.copy_file(NORUNTEST_PATH, no_run_tests)

config_path = os.path.join(log_dir, "test_configs")
for test in test_list:
helper.copy_file(Testsuites[test].config(), config_path)

if args.inputfile:
input_file = os.path.join(log_dir, "input_file")
helper.copy_file(args.inputfile, input_file)


def env_clean():
"""
Clean/uninstall avocado and autotest
Expand Down Expand Up @@ -587,6 +604,21 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
default=False, help='enable bootstrap kvm tests')

args = parser.parse_args()

if args.outputdir:
# Check if it is valid path
if not os.path.isdir(os.path.abspath(args.outputdir)):
raise ValueError("No output dir")
outputdir = args.outputdir
else:
outputdir = BASE_PATH
timeObj = time.localtime(time.time())
log_dir = os.path.join(outputdir, "%d-%d-%d_%d_%d_%d" % (timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year,
timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec))
os.makedirs(log_dir)
logger = helper.get_logger(log_dir)
outputdir = os.path.join(log_dir, "results")

if helper.get_machine_type() == 'pHyp':
args.enable_kvm = False
if args.run_suite:
Expand All @@ -604,13 +636,6 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
additional_args = args.add_args
if args.verbose:
additional_args += ' --show-job-log'
if args.outputdir:
# Check if it valid path
if not os.path.isdir(os.path.abspath(args.outputdir)):
raise ValueError("No output dir")
outputdir = os.path.join(args.outputdir, 'results')
else:
outputdir = os.path.join(BASE_PATH, 'results')

additional_args += ' --job-results-dir %s' % outputdir
bootstraped = False
Expand Down Expand Up @@ -685,6 +710,7 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
outputdir, args.vt_type,
test['test'], test['mux'],
test['args'])
Testsuites[test_suite_name].conf = test_suite
Testsuites_list.append(test_suite_name)

if 'guest' in test_suite:
Expand All @@ -696,6 +722,10 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
Testsuites[test_suite].runstatus("Cant_Run",
"Config file not present")
continue

# Log config files
log_files(Testsuites_list, log_dir)

# Run Tests
for test_suite in Testsuites_list:
if not Testsuites[test_suite].run == "Cant_Run":
Expand All @@ -711,7 +741,9 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
Testsuites[test_suite].run,
Testsuites[test_suite].runsummary))
summary_output.append(Testsuites[test_suite].runlink)
summary_output.append("")
logger.info("\n".join(summary_output))
logger.info("Results and Configs logged at: %s" % log_dir)

if os.path.isdir("/tmp/mux/"):
logger.info("Removing temporary mux dir")
Expand Down
21 changes: 18 additions & 3 deletions lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

from .logger import logger_init

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

logger = logger_init(filepath=LOG_PATH).getlogger()
def get_logger(logger_path):
global logger
logger = logger_init(filepath=logger_path).getlogger()
return logger


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


def copy_file(source, destination):
"""
Copy source file to destination provided.
If destination does not exist, creates one.
If source file does not exist, logs error and returns.
"""
if not os.path.isdir(destination):
os.makedirs(destination)
if not os.path.isfile(source):
logger.error("File %s not present" % source)
return
shutil.copy(source, destination)


def get_install_cmd():
"""
Get the command to install, based on the distro
Expand Down

0 comments on commit 50fcf02

Please sign in to comment.