Merge "Fix tacker client dependencies installation"
[functest.git] / testcases / 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 \r
18 import os\r
19 import time\r
20 import yaml\r
21 \r
22 import functest.utils.functest_logger as ft_logger\r
23 import functest.utils.functest_utils as functest_utils\r
24 \r
25 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:\r
26     functest_yaml = yaml.safe_load(f)\r
27 \r
28 dirs = functest_yaml.get('general').get('directories')\r
29 FUNCTEST_REPO = dirs.get('dir_repo_functest')\r
30 COPPER_REPO = dirs.get('dir_repo_copper')\r
31 TEST_DB_URL = functest_yaml.get('results').get('test_db_url')\r
32 \r
33 logger = ft_logger.Logger("copper").getLogger()\r
34 \r
35 \r
36 def main():\r
37     cmd = ('%s/tests/run.sh' % COPPER_REPO)\r
38     start_time = time.time()\r
39 \r
40     ret = functest_utils.execute_command(cmd, logger, exit_on_error=False)\r
41 \r
42     stop_time = time.time()\r
43     duration = round(stop_time - start_time, 1)\r
44     if ret == 0:\r
45         logger.info("COPPER PASSED")\r
46         test_status = 'PASS'\r
47     else:\r
48         logger.info("COPPER FAILED")\r
49         test_status = 'FAIL'\r
50 \r
51     details = {\r
52         'timestart': start_time,\r
53         'duration': duration,\r
54         'status': test_status,\r
55     }\r
56     pod_name = functest_utils.get_pod_name(logger)\r
57     scenario = functest_utils.get_scenario(logger)\r
58     version = functest_utils.get_version(logger)\r
59     build_tag = functest_utils.get_build_tag(logger)\r
60 \r
61     logger.info("Pushing COPPER results: TEST_DB_URL=%(db)s pod_name=%(pod)s "\r
62                 "version=%(v)s scenario=%(s)s criteria=%(c)s details=%(d)s" % {\r
63                     'db': TEST_DB_URL,\r
64                     'pod': pod_name,\r
65                     'v': version,\r
66                     's': scenario,\r
67                     'c': details['status'],\r
68                     'b': build_tag,\r
69                     'd': details,\r
70                 })\r
71     functest_utils.push_results_to_db("COPPER",\r
72                                       "COPPER-notification",\r
73                                       logger,\r
74                                       start_time,\r
75                                       stop_time,\r
76                                       details['status'],\r
77                                       details)\r
78 \r
79 if __name__ == '__main__':\r
80     main()\r