Adapt functest testcase to APi refactoring
[functest.git] / testcases / features / doctor.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2015 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # 0.1: This script boots the VM1 and allocates IP address from Nova
11 # Later, the VM2 boots then execute cloud-init to ping VM1.
12 # After successful ping, both the VMs are deleted.
13 # 0.2: measure test duration and publish results under json format
14 #
15 #
16
17 import os
18 import time
19 import yaml
20
21 import functest.utils.functest_logger as ft_logger
22 import functest.utils.functest_utils as functest_utils
23
24 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
25     functest_yaml = yaml.safe_load(f)
26
27 dirs = functest_yaml.get('general').get('directories')
28 FUNCTEST_REPO = dirs.get('dir_repo_functest')
29 DOCTOR_REPO = dirs.get('dir_repo_doctor')
30 TEST_DB_URL = functest_yaml.get('results').get('test_db_url')
31
32 logger = ft_logger.Logger("doctor").getLogger()
33
34
35 def main():
36     cmd = 'cd %s/tests && ./run.sh' % DOCTOR_REPO
37     start_time = time.time()
38
39     ret = functest_utils.execute_command(cmd, logger, exit_on_error=False)
40
41     stop_time = time.time()
42     duration = round(end_time_ts - start_time, 1)
43     if ret:
44         logger.info("doctor OK")
45         test_status = 'OK'
46     else:
47         logger.info("doctor FAILED")
48         test_status = 'NOK'
49
50     details = {
51         'timestart': start_time,
52         'duration': duration,
53         'status': test_status,
54     }
55     pod_name = functest_utils.get_pod_name(logger)
56     scenario = functest_utils.get_scenario(logger)
57     version = functest_utils.get_version(logger)
58     build_tag = functest_utils.get_build_tag(logger)
59
60     status = "failed"
61     if details['status'] == "OK":
62         status = "passed"
63
64     logger.info("Pushing Doctor results: TEST_DB_URL=%(db)s pod_name=%(pod)s "
65                 "version=%(v)s scenario=%(s)s criteria=%(c)s details=%(d)s" % {
66                     'db': TEST_DB_URL,
67                     'pod': pod_name,
68                     'v': version,
69                     's': scenario,
70                     'c': status,
71                     'b': build_tag,
72                     'd': details,
73                 })
74     functest_utils.push_results_to_db("doctor",
75                                       "doctor-notification",
76                                       logger,
77                                       start_time,
78                                       stop_time,
79                                       status,
80                                       details)
81
82 if __name__ == '__main__':
83     main()