file/dir renaming for consistency
[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 from functest.core import TestCasesBase
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(TestCasesBase.TestCasesBase):
24     SDNVPN_REPO = ft_constants.SDNVPN_REPO_DIR
25     SDNVPN_REPO_TESTS = os.path.join(SDNVPN_REPO, "tests/functest")
26     RESULTS_DIR = ft_constants.FUNCTEST_RESULTS_DIR
27     logger = ft_logger.Logger("sdnvpn").getLogger()
28
29     def __init__(self):
30         super(SdnVpnTests, self).__init__()
31         self.project_name = "sdnvpn"
32         self.case_name = "bgpvpn"
33
34     def main(self, **kwargs):
35         os.chdir(self.SDNVPN_REPO_TESTS)
36         cmd = 'run_tests.py'
37         log_file = os.path.join(self.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         duration = round(stop_time - start_time, 1)
45         if ret == 0 and duration > 1:
46             self.logger.info("%s OK" % self.case_name)
47             status = 'PASS'
48         elif ret == 0 and duration <= 1:
49             self.logger.info("%s TEST SKIPPED" % self.case_name)
50             status = 'SKIP'
51         else:
52             self.logger.info("%s FAILED" % self.case_name)
53             status = "FAIL"
54
55         # report status only if tests run (FAIL OR PASS)
56         if status is not "SKIP":
57             self.criteria = status
58             self.start_time = start_time
59             self.stop_time = stop_time
60             self.details = {}
61
62     def run(self):
63         kwargs = {}
64         return self.main(**kwargs)
65
66 if __name__ == '__main__':
67     parser = argparse.ArgumentParser()
68     parser.add_argument("-r", "--report",
69                         help="Create json result file",
70                         action="store_true")
71     args = vars(parser.parse_args())
72     sdnvpn = SdnVpnTests()
73     try:
74         result = sdnvpn.main(**args)
75         if result != TestCasesBase.TestCasesBase.EX_OK:
76             sys.exit(result)
77         if args['report']:
78             sys.exit(sdnvpn.push_to_db())
79     except Exception:
80         sys.exit(TestCasesBase.TestCasesBase.EX_RUN_ERROR)