Revert "write sdnvpn test result into db"
[sdnvpn.git] / sdnvpn / test / functest / run_sdnvpn_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 importlib
12 import logging
13 import os
14 import sys
15 import time
16 import traceback
17 import yaml
18
19 from functest.core import testcase
20 from sdnvpn.lib import config as sdnvpn_config
21 from sdnvpn.lib.gather_logs import gather_logs
22
23 COMMON_CONFIG = sdnvpn_config.CommonConfig()
24
25
26 class SdnvpnFunctest(testcase.TestCase):
27
28     __logger = logging.getLogger(__name__)
29
30     def run(self):
31         self.start_time = time.time()
32
33         cmd_line = "neutron quota-update --subnet -1 --network -1 --port -1"
34         self.__logger.info("Setting subnet/net quota to unlimited : %s"
35                            % cmd_line)
36         cmd = os.popen(cmd_line)
37         output = cmd.read()
38         self.__logger.debug(output)
39
40         # Workaround for
41         # https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-115
42         cmd_line = "nova quota-class-update --instances -1 default"
43         self.__logger.info("Setting instances quota to unlimited : %s"
44                            % cmd_line)
45         cmd = os.popen(cmd_line)
46         output = cmd.read()
47         self.__logger.debug(output)
48
49         with open(COMMON_CONFIG.config_file) as f:
50             config_yaml = yaml.safe_load(f)
51
52         testcases = config_yaml.get("testcases")
53         overall_status = "PASS"
54         for tc in testcases:
55             if testcases[tc]['enabled']:
56                 test_name = tc
57                 test_descr = testcases[tc]['description']
58                 title = ("Running '%s - %s'" %
59                          (test_name, test_descr))
60                 self.__logger.info(title)
61                 self.__logger.info("%s\n" % ("=" * len(title)))
62                 t = importlib.import_module(test_name, package=None)
63                 try:
64                     result = t.main()
65                 except Exception as ex:
66                     result = -1
67                     self.__logger.info("Caught Exception in %s: %s Trace: %s"
68                                        % (test_name, ex,
69                                           traceback.format_exc()))
70                 if result < 0:
71                     status = "FAIL"
72                     overall_status = "FAIL"
73                     self.__logger.info("Testcase %s failed" % test_name)
74                 else:
75                     status = result.get("status")
76                     self.details.update(
77                         {test_name: {'status': status,
78                                      'details': result.get("details")}})
79                     self.__logger.info("Results of test case '%s - %s':\n%s\n"
80                                        % (test_name, test_descr, result))
81
82                     if status == "FAIL":
83                         overall_status = "FAIL"
84
85         self.stop_time = time.time()
86
87         try:
88             gather_logs('overall')
89         except Exception as ex:
90             self.__logger.error(('Something went wrong in the Log gathering.'
91                                  'Ex: %s, Trace: %s')
92                                 % (ex, traceback.format_exc()))
93
94         if overall_status == "PASS":
95             self.result = 100
96             return testcase.TestCase.EX_OK
97
98         return testcase.TestCase.EX_RUN_ERROR
99
100
101 if __name__ == '__main__':
102     logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s'
103                         '- %(levelname)s - %(message)s')
104     SDNVPN = SdnvpnFunctest()
105     sys.exit(SDNVPN.run())