Update Xtesting to 0.98
[functest.git] / features / copper.py
1 #!/usr/bin/python\r
2 #\r
3 # Copyright 2016 AT&T Intellectual Property, Inc\r
4 #\r
5 # Licensed under the Apache License, Version 2.0 (the "License");\r
6 # you may not use this file except in compliance with the License.\r
7 # You may obtain a copy of the License at\r
8 #\r
9 # http://www.apache.org/licenses/LICENSE-2.0\r
10 #\r
11 # Unless required by applicable law or agreed to in writing, software\r
12 # distributed under the License is distributed on an "AS IS" BASIS,\r
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 # See the License for the specific language governing permissions and\r
15 # limitations under the License.\r
16 #\r
17 import argparse\r
18 import os\r
19 import sys\r
20 import time\r
21 import functest.utils.functest_logger as ft_logger\r
22 import functest.utils.functest_utils as functest_utils\r
23 import yaml\r
24 \r
25 parser = argparse.ArgumentParser()\r
26 parser.add_argument("-r", "--report",\r
27                     help="Create json result file",\r
28                     action="store_true")\r
29 args = parser.parse_args()\r
30 \r
31 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:\r
32     functest_yaml = yaml.safe_load(f)\r
33 \r
34 dirs = functest_yaml.get('general').get('directories')\r
35 FUNCTEST_REPO = dirs.get('dir_repo_functest')\r
36 COPPER_REPO = dirs.get('dir_repo_copper')\r
37 \r
38 logger = ft_logger.Logger("copper").getLogger()\r
39 \r
40 \r
41 def main():\r
42     cmd = "%s/tests/run.sh %s/tests" % (COPPER_REPO, COPPER_REPO)\r
43 \r
44     start_time = time.time()\r
45 \r
46     ret_val = functest_utils.execute_command(cmd, logger, exit_on_error=False)\r
47 \r
48     stop_time = time.time()\r
49     duration = round(stop_time - start_time, 1)\r
50     if ret_val == 0:\r
51         logger.info("COPPER PASSED")\r
52         test_status = 'PASS'\r
53     else:\r
54         logger.info("COPPER FAILED")\r
55         test_status = 'FAIL'\r
56 \r
57     details = {\r
58         'timestart': start_time,\r
59         'duration': duration,\r
60         'status': test_status,\r
61     }\r
62     functest_utils.logger_test_results(logger, "Copper",\r
63                                        "copper-notification",\r
64                                        details['status'], details)\r
65     try:\r
66         if args.report:\r
67             functest_utils.push_results_to_db("copper",\r
68                                               "copper-notification",\r
69                                               logger,\r
70                                               start_time,\r
71                                               stop_time,\r
72                                               details['status'],\r
73                                               details)\r
74             logger.info("COPPER results pushed to DB")\r
75     except:\r
76         logger.error("Error pushing results into Database '%s'"\r
77                      % sys.exc_info()[0])\r
78 \r
79     if ret_val != 0:\r
80         sys.exit(-1)\r
81 \r
82     sys.exit(0)\r
83 \r
84 if __name__ == '__main__':\r
85     main()\r