X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=ci%2Frun_tests.py;h=1947938389193f9a54649195312d750f7ef62d7e;hb=a7d390f6a5d05cb632d933c03f170b5bc25be534;hp=ca7ff2b5ae6722d93af4ee5261e528d5752ade2f;hpb=934a16a7766a5f06b046d882eee408a725b03139;p=functest.git diff --git a/ci/run_tests.py b/ci/run_tests.py index ca7ff2b5a..194793838 100755 --- a/ci/run_tests.py +++ b/ci/run_tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python -u # # Author: Jose Lausuch (jose.lausuch@ericsson.com) # @@ -8,11 +8,12 @@ # http://www.apache.org/licenses/LICENSE-2.0 # -import argparse import datetime import os import re import sys + +import argparse import functest.ci.generate_report as generate_report import functest.ci.tier_builder as tb import functest.utils.functest_logger as ft_logger @@ -20,7 +21,8 @@ import functest.utils.functest_utils as ft_utils import functest.utils.openstack_clean as os_clean import functest.utils.openstack_snapshot as os_snapshot import functest.utils.openstack_utils as os_utils - +from functest.testcases.Controllers.ODL.OpenDaylightTesting import ODLTestCases +from functest.utils.functest_utils import FUNCTEST_REPO as FUNCTEST_REPO parser = argparse.ArgumentParser() parser.add_argument("-t", "--test", dest="test", action='store', @@ -39,9 +41,7 @@ logger = ft_logger.Logger("run_tests").getLogger() """ global variables """ -REPOS_DIR = os.getenv('repos_dir') -FUNCTEST_REPO = ("%s/functest/" % REPOS_DIR) -EXEC_SCRIPT = ("%sci/exec_test.sh" % FUNCTEST_REPO) +EXEC_SCRIPT = ("%s/ci/exec_test.sh" % FUNCTEST_REPO) CLEAN_FLAG = True REPORT_FLAG = False EXECUTED_TEST_CASES = [] @@ -75,6 +75,13 @@ def cleanup(): os_clean.main() +def update_test_info(test_name, result, duration): + for test in EXECUTED_TEST_CASES: + if test['test_name'] == test_name: + test.update({"result": result, + "duration": duration}) + + def run_test(test, tier_name): global OVERALL_RESULT, EXECUTED_TEST_CASES result_str = "PASS" @@ -93,9 +100,15 @@ def run_test(test, tier_name): if REPORT_FLAG: flags += " -r" - cmd = ("%s%s" % (EXEC_SCRIPT, flags)) - logger.debug("Executing command '%s'" % cmd) - result = ft_utils.execute_command(cmd, logger, exit_on_error=False) + if test_name == 'odl': + result = ODLTestCases.functest_run() + if result and REPORT_FLAG: + result = ODLTestCases.push_to_db() + result = not result + else: + cmd = ("%s%s" % (EXEC_SCRIPT, flags)) + logger.debug("Executing command '%s'" % cmd) + result = ft_utils.execute_command(cmd, exit_on_error=False) if CLEAN_FLAG: cleanup() @@ -104,22 +117,22 @@ def run_test(test, tier_name): duration_str = ("%02d:%02d" % divmod(duration, 60)) logger.info("Test execution time: %s" % duration_str) - result = 0 if result != 0: logger.error("The test case '%s' failed. " % test_name) OVERALL_RESULT = -1 result_str = "FAIL" - if test.get_blocking(): - logger.info("This test case is blocking. Exiting...") + if test.is_blocking(): + if not args.test or args.test == "all": + logger.info("This test case is blocking. Aborting overall " + "execution.") + # if it is a single test we don't print the whole results table + update_test_info(test_name, result_str, duration_str) + generate_report.main(EXECUTED_TEST_CASES) + logger.info("Execution exit value: %s" % OVERALL_RESULT) sys.exit(OVERALL_RESULT) - for test in EXECUTED_TEST_CASES: - if test['test_name'] == test_name: - test.update({"result": result_str, - "duration": duration_str}) - - return result + update_test_info(test_name, result_str, duration_str) def run_tier(tier): @@ -135,11 +148,7 @@ def run_tier(tier): print_separator("#") logger.debug("\n%s" % tier) for test in tests: - res = run_test(test, tier_name) - if res != 0: - return res - - return 0 + run_test(test, tier_name) def run_all(tiers): @@ -164,12 +173,9 @@ def run_all(tiers): logger.info("Tests to be executed:%s" % summary) EXECUTED_TEST_CASES = generate_report.init(tiers_to_run) for tier in tiers_to_run: - res = run_tier(tier) - if res != 0: - return res - generate_report.main(EXECUTED_TEST_CASES) + run_tier(tier) - return 0 + generate_report.main(EXECUTED_TEST_CASES) def main(): @@ -179,7 +185,7 @@ def main(): CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') CI_SCENARIO = os.getenv('DEPLOY_SCENARIO') - file = FUNCTEST_REPO + "/ci/testcases.yaml" + file = ft_utils.get_testcases_file() _tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, file) if args.noclean: @@ -194,7 +200,7 @@ def main(): run_tier(_tiers.get_tier(args.test)) elif _tiers.get_test(args.test): - run_test(_tiers.get_test(args.test)) + run_test(_tiers.get_test(args.test), _tiers.get_tier(args.test)) elif args.test == "all": run_all(_tiers) @@ -208,6 +214,7 @@ def main(): else: run_all(_tiers) + logger.info("Execution exit value: %s" % OVERALL_RESULT) sys.exit(OVERALL_RESULT) if __name__ == '__main__':