Set unlimited port quotas
[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     # and SDNVPN-126
48     cmd_line = "neutron quota-update --subnet -1 --network -1 --port -1"
49     logger.info("Setting subnet/net quota to unlimited : %s" % cmd_line)
50     cmd = os.popen(cmd_line)
51     output = cmd.read()
52     logger.debug(output)
53
54     # Workaround for https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-115
55     cmd_line = "nova quota-class-update --instances -1 default"
56     logger.info("Setting instances quota to unlimited : %s" % cmd_line)
57     cmd = os.popen(cmd_line)
58     output = cmd.read()
59     logger.debug(output)
60
61     with open(COMMON_CONFIG.config_file) as f:
62         config_yaml = yaml.safe_load(f)
63
64     testcases = config_yaml.get("testcases")
65     overall_status = "PASS"
66     for testcase in testcases:
67         if testcases[testcase]['enabled']:
68             test_name = testcase
69             test_descr = testcases[testcase]['description']
70             test_name_db = testcases[testcase]['testname_db']
71             title = ("Running '%s - %s'" %
72                      (test_name, test_descr))
73             logger.info(title)
74             logger.info("%s\n" % ("=" * len(title)))
75             t = importlib.import_module(testcase, package=None)
76             start_time = time.time()
77             result = t.main()
78             end_time = time.time()
79             if result < 0:
80                 status = "FAIL"
81                 overall_status = "FAIL"
82             else:
83                 status = result.get("status")
84                 details = result.get("details")
85                 logger.info("Results of test case '%s - %s':\n%s\n" %
86                             (test_name, test_descr, result))
87
88                 if status == "FAIL":
89                     overall_status = "FAIL"
90
91             if args.report:
92                 push_results(
93                     test_name_db, start_time, end_time, status, details)
94
95     if overall_status == "FAIL":
96         sys.exit(-1)
97
98     sys.exit(0)
99
100
101 if __name__ == '__main__':
102     main()