Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 45 additions & 14 deletions avocado-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import binascii
from shutil import copyfile

from lib.logger import logger_init
from lib import helper

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

Expand Down Expand Up @@ -97,9 +95,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 @@ -271,6 +268,7 @@ def install_optional_plugin(plugin):
pass



def create_config(logdir):
"""
Create the local avocado config file
Expand Down Expand Up @@ -349,7 +347,6 @@ def bootstrap(enable_kvm=False):
os.makedirs(postscipt_dir)
helper.copy_dir_file(postscipt, postscipt_dir)


def run_test(testsuite, avocado_bin):
"""
To run given testsuite
Expand Down Expand Up @@ -403,6 +400,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 All @@ -418,7 +435,6 @@ def env_clean():
if os.path.isdir(postscipt_dir):
helper.remove_file(postscipt, postscipt_dir)


def edit_mux_file(test_config_name, mux_file_path, tmp_mux_path):
"""
Edit the mux file with input given in input config file.
Expand Down Expand Up @@ -611,6 +627,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
outputdir = os.path.join(outputdir, "results")
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)

if helper.get_machine_type() == 'pHyp':
args.enable_kvm = False
if args.run_suite:
Expand All @@ -628,13 +659,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 @@ -709,6 +733,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 @@ -720,6 +745,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 @@ -744,7 +773,9 @@ def parse_test_config(test_config_file, avocado_bin, enable_kvm):
Testsuites[test_suite].run.ljust(10),
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
20 changes: 18 additions & 2 deletions lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

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 @@ -128,6 +130,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