485af0e14822fb7c042cb5fc4718cf859724a9d8
[functest.git] / testcases / vnf / RNC / parser.py
1 #!/usr/bin/python
2 #
3 # Copyright 2016 ZTE Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 import os
18 import time
19 import yaml
20
21 import functest.utils.functest_logger as ft_logger
22 import functest.utils.functest_utils as functest_utils
23
24 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
25     functest_yaml = yaml.safe_load(f)
26
27 dirs = functest_yaml.get('general').get('directories')
28 FUNCTEST_REPO = dirs.get('dir_repo_functest')
29 PARSER_REPO = dirs.get('dir_repo_parser')
30
31 logger = ft_logger.Logger("parser").getLogger()
32
33
34 def main():
35     EXIT_CODE = -1
36     project = 'parser'
37     case_name = 'parser-basics'
38     cmd = 'cd %s/tests && ./functest_run.sh' % PARSER_REPO
39     start_time = time.time()
40
41     ret = functest_utils.execute_command(cmd, logger, exit_on_error=False)
42
43     stop_time = time.time()
44     duration = round(stop_time - start_time, 1)
45     if ret == 0:
46         EXIT_CODE = 0
47         logger.info("parser OK")
48         test_status = 'OK'
49     else:
50         logger.info("parser FAILED")
51         test_status = 'NOK'
52
53     details = {
54         'timestart': start_time,
55         'duration': duration,
56         'status': test_status,
57     }
58
59     status = "FAIL"
60     if details['status'] == "OK":
61         status = "PASS"
62
63     functest_utils.logger_test_results(logger,
64                                        project,
65                                        case_name,
66                                        status,
67                                        details)
68
69     functest_utils.push_results_to_db(project,
70                                       case_name,
71                                       logger,
72                                       start_time,
73                                       stop_time,
74                                       status,
75                                       details)
76     exit(EXIT_CODE)
77
78 if __name__ == '__main__':
79     main()