3 # Copyright (c) 2017 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
20 import functest.utils.functest_utils as ft_utils
21 from sdnvpn.lib import config as sdnvpn_config
22 from sdnvpn.lib.gather_logs import gather_logs
24 logger = logging.getLogger('sdnvpn-run-tests')
26 COMMON_CONFIG = sdnvpn_config.CommonConfig()
27 TEST_DB_URL = COMMON_CONFIG.test_db
30 def push_results(testname, start_time, end_time, criteria, details):
31 logger.info("Push testcase '%s' results into the DB...\n" % testname)
32 ft_utils.push_results_to_db("sdnvpn",
40 def main(report=False):
41 # Workaround for https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-100
43 cmd_line = "neutron quota-update --subnet -1 --network -1 --port -1"
44 logger.info("Setting subnet/net quota to unlimited : %s" % cmd_line)
45 cmd = os.popen(cmd_line)
49 # Workaround for https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-115
50 cmd_line = "nova quota-class-update --instances -1 default"
51 logger.info("Setting instances quota to unlimited : %s" % cmd_line)
52 cmd = os.popen(cmd_line)
56 with open(COMMON_CONFIG.config_file) as f:
57 config_yaml = yaml.safe_load(f)
59 testcases = config_yaml.get("testcases")
60 overall_status = "PASS"
61 for testcase in testcases:
62 if testcases[testcase]['enabled']:
64 test_descr = testcases[testcase]['description']
65 test_name_db = testcases[testcase]['testname_db']
66 title = ("Running '%s - %s'" %
67 (test_name, test_descr))
69 logger.info("%s\n" % ("=" * len(title)))
70 t = importlib.import_module(testcase, package=None)
71 start_time = time.time()
74 except Exception as ex:
76 logger.info("Caught Exception in %s: %s Trace: %s" %
77 (test_name, ex, traceback.format_exc()))
78 end_time = time.time()
81 overall_status = "FAIL"
82 logger.info("Testcase %s failed" % test_name)
84 status = result.get("status")
85 details = result.get("details")
86 logger.info("Results of test case '%s - %s':\n%s\n" %
87 (test_name, test_descr, result))
90 overall_status = "FAIL"
94 test_name_db, start_time, end_time, status, details)
97 gather_logs('overall')
98 except Exception as ex:
99 logger.error(('Something went wrong in the Log gathering.'
101 % ex, traceback.format_exc())
102 if overall_status == "FAIL":
108 if __name__ == '__main__':
109 logging.basicConfig(level=logging.INFO)
110 parser = argparse.ArgumentParser()
111 parser.add_argument("-r", "--report",
112 help="Create json result file",
114 args = parser.parse_args()
115 main(report=args.report)