Merge "Ignore rally_conf.json"
[functest-xtesting.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 import argparse
17 import os
18 import time
19
20 import functest.utils.functest_logger as ft_logger
21 import functest.utils.functest_utils as functest_utils
22
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 DOCTOR_REPO = \
33     functest_utils.get_functest_config('general.directories.dir_repo_doctor')
34 RESULTS_DIR = \
35     functest_utils.get_functest_config('general.directories.dir_results')
36
37 logger = ft_logger.Logger("doctor").getLogger()
38
39
40 def main():
41     exit_code = -1
42
43     # if the image name is explicitly set for the doctor suite, set it as
44     # enviroment variable
45     if 'doctor' in functest_yaml and 'image_name' in functest_yaml['doctor']:
46         os.environ["IMAGE_NAME"] = functest_yaml['doctor']['image_name']
47
48     cmd = 'cd %s/tests && ./run.sh' % DOCTOR_REPO
49     log_file = RESULTS_DIR + "/doctor.log"
50
51     start_time = time.time()
52
53     ret = functest_utils.execute_command(cmd,
54                                          info=True,
55                                          output_file=log_file)
56
57     stop_time = time.time()
58     duration = round(stop_time - start_time, 1)
59     if ret == 0:
60         logger.info("Doctor test case OK")
61         test_status = 'OK'
62         exit_code = 0
63     else:
64         logger.info("Doctor test case FAILED")
65         test_status = 'NOK'
66
67     details = {
68         'timestart': start_time,
69         'duration': duration,
70         'status': test_status,
71     }
72     status = "FAIL"
73     if details['status'] == "OK":
74         status = "PASS"
75     functest_utils.logger_test_results("Doctor",
76                                        "doctor-notification",
77                                        status, details)
78     if args.report:
79         functest_utils.push_results_to_db("doctor",
80                                           "doctor-notification",
81                                           start_time,
82                                           stop_time,
83                                           status,
84                                           details)
85         logger.info("Doctor results pushed to DB")
86
87     exit(exit_code)
88
89 if __name__ == '__main__':
90     main()