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