Merge "add parser to feature tier to make it run daily"
[functest.git] / testcases / vnf / vRNC / 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 import argparse
21
22 import functest.utils.functest_logger as ft_logger
23 import functest.utils.functest_utils as functest_utils
24
25 parser = argparse.ArgumentParser()
26 parser.add_argument("-r", "--report",
27                     help="Create json result file",
28                     action="store_true")
29 args = parser.parse_args()
30
31 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
32     functest_yaml = yaml.safe_load(f)
33
34 dirs = functest_yaml.get('general').get('directories')
35 FUNCTEST_REPO = dirs.get('dir_repo_functest')
36 PARSER_REPO = dirs.get('dir_repo_parser')
37
38 logger = ft_logger.Logger("parser").getLogger()
39
40
41 def main():
42     project = 'parser'
43     case_name = 'parser-basics'
44     cmd = 'cd %s/tests && ./functest_run.sh' % PARSER_REPO
45
46     start_time = time.time()
47     ret = functest_utils.execute_command(cmd, logger, exit_on_error=False)
48     stop_time = time.time()
49
50     status, details = functest_utils.check_test_result(project,
51                                                        ret,
52                                                        start_time,
53                                                        stop_time)
54
55     functest_utils.logger_test_results(logger,
56                                        project,
57                                        case_name,
58                                        status,
59                                        details)
60
61     if args.report:
62         logger.debug("Report Parser Results to DB......")
63         functest_utils.push_results_to_db(project,
64                                           case_name,
65                                           logger,
66                                           start_time,
67                                           stop_time,
68                                           status,
69                                           details)
70     exit(ret)
71
72 if __name__ == '__main__':
73     main()