Merge "Unified way to provide configurations and env variables(proposal 1)"
[functest.git] / functest / opnfv_tests / features / sdnvpn.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2016 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
12 import argparse
13 import os
14 import sys
15 import time
16
17 import functest.core.testcase_base as testcase_base
18 import functest.utils.functest_constants as ft_constants
19 import functest.utils.functest_logger as ft_logger
20 import functest.utils.functest_utils as ft_utils
21
22
23 class SdnVpnTests(testcase_base.TestcaseBase):
24     SDNVPN_REPO_TESTS = os.path.join(
25         ft_constants.SDNVPN_REPO_DIR, "tests/functest")
26     logger = ft_logger.Logger("sdnvpn").getLogger()
27
28     def __init__(self):
29         super(SdnVpnTests, self).__init__()
30         self.project_name = "sdnvpn"
31         self.case_name = "bgpvpn"
32
33     def main(self, **kwargs):
34         os.chdir(self.SDNVPN_REPO_TESTS)
35         cmd = 'run_tests.py'
36         log_file = os.path.join(
37             ft_constants.FUNCTEST_RESULTS_DIR, "sdnvpn.log")
38         start_time = time.time()
39
40         ret = ft_utils.execute_command(cmd,
41                                        output_file=log_file)
42
43         stop_time = time.time()
44         if ret == 0:
45             self.logger.info("%s OK" % self.case_name)
46             status = 'PASS'
47         else:
48             self.logger.info("%s FAILED" % self.case_name)
49             status = "FAIL"
50
51         # report status only if tests run (FAIL OR PASS)
52         self.criteria = status
53         self.start_time = start_time
54         self.stop_time = stop_time
55         self.details = {}
56
57     def run(self):
58         kwargs = {}
59         return self.main(**kwargs)
60
61
62 if __name__ == '__main__':
63     parser = argparse.ArgumentParser()
64     parser.add_argument("-r", "--report",
65                         help="Create json result file",
66                         action="store_true")
67     args = vars(parser.parse_args())
68     sdnvpn = SdnVpnTests()
69     try:
70         result = sdnvpn.main(**args)
71         if result != testcase_base.TestcaseBase.EX_OK:
72             sys.exit(result)
73         if args['report']:
74             sys.exit(sdnvpn.push_to_db())
75     except Exception:
76         sys.exit(testcase_base.TestcaseBase.EX_RUN_ERROR)