Add suffix '_DIR' to some constants that point to directories
[functest.git] / functest / opnfv_tests / 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 sys
19 import time
20
21 import argparse
22
23 import functest.core.TestCasesBase as base
24 import functest.utils.functest_constants as ft_constants
25 import functest.utils.functest_logger as ft_logger
26 import functest.utils.functest_utils as ft_utils
27
28
29 class Parser(base.TestCasesBase):
30
31     def __init__(self):
32         super(Parser, self).__init__()
33         self.project_name = "parser"
34         self.case_name = "parser-basics"
35         self.logger = ft_logger.Logger("parser").getLogger()
36         self.log_file = os.path.join(
37             ft_constants.FUNCTEST_RESULTS_DIR,  "parser.log")
38
39     def run(self, **kwargs):
40         cmd = 'cd %s/tests && ./functest_run.sh' % ft_constants.PARSER_REPO_DIR
41
42         self.start_time = time.time()
43         ret = ft_utils.execute_command(cmd,
44                                        info=True,
45                                        output_file=self.log_file)
46         self.stop_time = time.time()
47
48         self.criteria, details = ft_utils.check_test_result(self.project_name,
49                                                             ret,
50                                                             self.start_time,
51                                                             self.stop_time)
52
53         ft_utils.logger_test_results(self.project_name,
54                                      self.case_name,
55                                      self.criteria,
56                                      details)
57
58         return ret
59
60     @staticmethod
61     def get_conf(parameter):
62         return ft_utils.get_functest_config(parameter)
63
64
65 if __name__ == '__main__':
66     args_parser = argparse.ArgumentParser()
67     args_parser.add_argument("-r", "--report",
68                              help="Create json result file",
69                              action="store_true")
70     args = vars(args_parser.parse_args())
71     parser = Parser()
72     try:
73         result = parser.run(**args)
74         if result != base.TestCasesBase.EX_OK:
75             sys.exit(result)
76         if args['report']:
77             sys.exit(parser.push_to_db())
78     except Exception:
79         sys.exit(base.TestCasesBase.EX_RUN_ERROR)