Print all the Parser test output to a log file
[functest.git] / testcases / features / copper.py
1 #!/usr/bin/python
2 #
3 # Copyright 2016 AT&T Intellectual Property, Inc
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 import functest.utils.functest_logger as ft_logger
22 import functest.utils.functest_utils as functest_utils
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 functest_yaml = functest_utils.get_functest_yaml()
31
32 dirs = functest_yaml.get('general').get('directories')
33 COPPER_REPO = dirs.get('dir_repo_copper')
34
35 logger = ft_logger.Logger("copper").getLogger()
36
37
38 def main():
39     cmd = "%s/tests/run.sh %s/tests" % (COPPER_REPO, COPPER_REPO)
40
41     start_time = time.time()
42
43     ret_val = functest_utils.execute_command(cmd, logger, exit_on_error=False)
44
45     stop_time = time.time()
46     duration = round(stop_time - start_time, 1)
47     if ret_val == 0:
48         logger.info("COPPER PASSED")
49         test_status = 'PASS'
50     else:
51         logger.info("COPPER FAILED")
52         test_status = 'FAIL'
53
54     details = {
55         'timestart': start_time,
56         'duration': duration,
57         'status': test_status,
58     }
59     functest_utils.logger_test_results(logger, "Copper",
60                                        "copper-notification",
61                                        details['status'], details)
62     try:
63         if args.report:
64             functest_utils.push_results_to_db("copper",
65                                               "copper-notification",
66                                               logger,
67                                               start_time,
68                                               stop_time,
69                                               details['status'],
70                                               details)
71             logger.info("COPPER results pushed to DB")
72     except:
73         logger.error("Error pushing results into Database '%s'"
74                      % sys.exc_info()[0])
75
76     if ret_val != 0:
77         sys.exit(-1)
78
79     sys.exit(0)
80
81 if __name__ == '__main__':
82     main()