X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=sdnvpn%2Ftest%2Ffunctest%2Frun_tests.py;h=1bffe67a7ec0e540865d4368b524813b89132a80;hb=45df38fe0cd7a604827a5cde6ad6480971b0456b;hp=1130759814c8f8a76279690f20d5160def93c409;hpb=a720669923b555f348235076369479bb13571978;p=sdnvpn.git diff --git a/sdnvpn/test/functest/run_tests.py b/sdnvpn/test/functest/run_tests.py index 1130759..1bffe67 100644 --- a/sdnvpn/test/functest/run_tests.py +++ b/sdnvpn/test/functest/run_tests.py @@ -10,23 +10,18 @@ import argparse import importlib +import logging import os import sys import time +import traceback import yaml -import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils from sdnvpn.lib import config as sdnvpn_config +from sdnvpn.lib.gather_logs import gather_logs - -parser = argparse.ArgumentParser() -parser.add_argument("-r", "--report", - help="Create json result file", - action="store_true") -args = parser.parse_args() - -logger = ft_logger.Logger("sdnvpn-run-tests").getLogger() +logger = logging.getLogger('sdnvpn-run-tests') COMMON_CONFIG = sdnvpn_config.CommonConfig() TEST_DB_URL = COMMON_CONFIG.test_db @@ -42,7 +37,7 @@ def push_results(testname, start_time, end_time, criteria, details): details) -def main(): +def main(report=False): # Workaround for https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-100 # and SDNVPN-126 cmd_line = "neutron quota-update --subnet -1 --network -1 --port -1" @@ -74,11 +69,17 @@ def main(): logger.info("%s\n" % ("=" * len(title))) t = importlib.import_module(testcase, package=None) start_time = time.time() - result = t.main() + try: + result = t.main() + except Exception as ex: + result = -1 + logger.info("Caught Exception in %s: %s Trace: %s" % + (test_name, ex, traceback.format_exc())) end_time = time.time() if result < 0: status = "FAIL" overall_status = "FAIL" + logger.info("Testcase %s failed" % test_name) else: status = result.get("status") details = result.get("details") @@ -88,10 +89,16 @@ def main(): if status == "FAIL": overall_status = "FAIL" - if args.report: + if report: push_results( test_name_db, start_time, end_time, status, details) + try: + gather_logs('overall') + except Exception as ex: + logger.error(('Something went wrong in the Log gathering.' + 'Ex: Trace: %s') + % ex, traceback.format_exc()) if overall_status == "FAIL": sys.exit(-1) @@ -99,4 +106,10 @@ def main(): if __name__ == '__main__': - main() + logging.basicConfig(level=logging.INFO) + parser = argparse.ArgumentParser() + parser.add_argument("-r", "--report", + help="Create json result file", + action="store_true") + args = parser.parse_args() + main(report=args.report)