Merge "Set unlimited network and subnet quotas to fix CI"
[sdnvpn.git] / sdnvpn / test / functest / run_tests.py
1 #!/bin/python
2 #
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
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10
11 import argparse
12 import importlib
13 import os
14 import sys
15 import time
16 import yaml
17
18 import functest.utils.functest_logger as ft_logger
19 import functest.utils.functest_utils as ft_utils
20 from sdnvpn.lib import config as sdnvpn_config
21
22
23 parser = argparse.ArgumentParser()
24 parser.add_argument("-r", "--report",
25                     help="Create json result file",
26                     action="store_true")
27 args = parser.parse_args()
28
29 logger = ft_logger.Logger("sdnvpn-run-tests").getLogger()
30
31 COMMON_CONFIG = sdnvpn_config.CommonConfig()
32 TEST_DB_URL = COMMON_CONFIG.test_db
33
34
35 def push_results(testname, start_time, end_time, criteria, details):
36     logger.info("Push testcase '%s' results into the DB...\n" % testname)
37     ft_utils.push_results_to_db("sdnvpn",
38                                 testname,
39                                 start_time,
40                                 end_time,
41                                 criteria,
42                                 details)
43
44
45 def main():
46     # Workaround for https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-100
47     cmd_line = "neutron quota-update --subnet -1 --network -1"
48     logger.info("Setting subnet/net quota to unlimited : %s" % cmd_line)
49     cmd = os.popen(cmd_line)
50     output = cmd.read()
51     logger.debug(output)
52
53     with open(COMMON_CONFIG.config_file) as f:
54         config_yaml = yaml.safe_load(f)
55
56     testcases = config_yaml.get("testcases")
57     overall_status = "PASS"
58     for testcase in testcases:
59         if testcases[testcase]['enabled']:
60             test_name = testcase
61             test_descr = testcases[testcase]['description']
62             test_name_db = testcases[testcase]['testname_db']
63             title = ("Running '%s - %s'" %
64                      (test_name, test_descr))
65             logger.info(title)
66             logger.info("%s\n" % ("=" * len(title)))
67             t = importlib.import_module(testcase, package=None)
68             start_time = time.time()
69             result = t.main()
70             end_time = time.time()
71             if result < 0:
72                 status = "FAIL"
73                 overall_status = "FAIL"
74             else:
75                 status = result.get("status")
76                 details = result.get("details")
77                 logger.info("Results of test case '%s - %s':\n%s\n" %
78                             (test_name, test_descr, result))
79
80                 if status == "FAIL":
81                     overall_status = "FAIL"
82
83             if args.report:
84                 push_results(
85                     test_name_db, start_time, end_time, status, details)
86
87     if overall_status == "FAIL":
88         sys.exit(-1)
89
90     sys.exit(0)
91
92
93 if __name__ == '__main__':
94     main()