Merge "Refactor SFC testcase" into stable/colorado
[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 time
18
19 import argparse
20 import functest.utils.functest_logger as ft_logger
21 import functest.utils.functest_utils as functest_utils
22
23 parser = argparse.ArgumentParser()
24 parser.add_argument("-r", "--report",
25                     help="Create json result file",
26                     action="store_true")
27 args = parser.parse_args()
28
29 functest_yaml = functest_utils.get_functest_yaml()
30
31 dirs = functest_yaml.get('general').get('directories')
32 PARSER_REPO = dirs.get('dir_repo_parser')
33
34 logger = ft_logger.Logger("parser").getLogger()
35
36
37 def main():
38     project = 'parser'
39     case_name = 'parser-basics'
40     cmd = 'cd %s/tests && ./functest_run.sh' % PARSER_REPO
41
42     start_time = time.time()
43     ret = functest_utils.execute_command(cmd,
44                                          logger,
45                                          info=True,
46                                          exit_on_error=False)
47     stop_time = time.time()
48
49     status, details = functest_utils.check_test_result(project,
50                                                        ret,
51                                                        start_time,
52                                                        stop_time)
53
54     functest_utils.logger_test_results(logger,
55                                        project,
56                                        case_name,
57                                        status,
58                                        details)
59
60     if args.report:
61         logger.debug("Report Parser Results to DB......")
62         functest_utils.push_results_to_db(project,
63                                           case_name,
64                                           logger,
65                                           start_time,
66                                           stop_time,
67                                           status,
68                                           details)
69     exit(ret)
70
71 if __name__ == '__main__':
72     main()