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