delete useless FUNCTEST_REPO variable
[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 argparse
18 import os
19 import sys
20 import time
21 import functest.utils.functest_logger as ft_logger
22 import functest.utils.functest_utils as functest_utils
23 import yaml
24
25 parser = argparse.ArgumentParser()
26 parser.add_argument("-r", "--report",
27                     help="Create json result file",
28                     action="store_true")
29 args = parser.parse_args()
30
31 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
32     functest_yaml = yaml.safe_load(f)
33
34 dirs = functest_yaml.get('general').get('directories')
35 COPPER_REPO = dirs.get('dir_repo_copper')
36
37 logger = ft_logger.Logger("copper").getLogger()
38
39
40 def main():
41     cmd = "%s/tests/run.sh %s/tests" % (COPPER_REPO, COPPER_REPO)
42
43     start_time = time.time()
44
45     ret_val = functest_utils.execute_command(cmd, logger, exit_on_error=False)
46
47     stop_time = time.time()
48     duration = round(stop_time - start_time, 1)
49     if ret_val == 0:
50         logger.info("COPPER PASSED")
51         test_status = 'PASS'
52     else:
53         logger.info("COPPER FAILED")
54         test_status = 'FAIL'
55
56     details = {
57         'timestart': start_time,
58         'duration': duration,
59         'status': test_status,
60     }
61     functest_utils.logger_test_results(logger, "Copper",
62                                        "copper-notification",
63                                        details['status'], details)
64     try:
65         if args.report:
66             functest_utils.push_results_to_db("copper",
67                                               "copper-notification",
68                                               logger,
69                                               start_time,
70                                               stop_time,
71                                               details['status'],
72                                               details)
73             logger.info("COPPER results pushed to DB")
74     except:
75         logger.error("Error pushing results into Database '%s'"
76                      % sys.exc_info()[0])
77
78     if ret_val != 0:
79         sys.exit(-1)
80
81     sys.exit(0)
82
83 if __name__ == '__main__':
84     main()