Print all the Parser test output to a log file
[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 import time
17
18 import argparse
19 import functest.utils.functest_logger as ft_logger
20 import functest.utils.functest_utils as functest_utils
21
22 parser = argparse.ArgumentParser()
23 parser.add_argument("-r", "--report",
24                     help="Create json result file",
25                     action="store_true")
26 args = parser.parse_args()
27
28 functest_yaml = functest_utils.get_functest_yaml()
29
30 dirs = functest_yaml.get('general').get('directories')
31 DOCTOR_REPO = dirs.get('dir_repo_doctor')
32
33 logger = ft_logger.Logger("doctor").getLogger()
34
35
36 def main():
37     exit_code = -1
38     cmd = 'cd %s/tests && ./run.sh' % DOCTOR_REPO
39     start_time = time.time()
40
41     ret = functest_utils.execute_command(cmd, logger, info=True,
42                                          exit_on_error=False)
43
44     stop_time = time.time()
45     duration = round(stop_time - start_time, 1)
46     if ret == 0:
47         logger.info("doctor OK")
48         test_status = 'OK'
49         exit_code = 0
50     else:
51         logger.info("doctor FAILED")
52         test_status = 'NOK'
53
54     details = {
55         'timestart': start_time,
56         'duration': duration,
57         'status': test_status,
58     }
59     status = "FAIL"
60     if details['status'] == "OK":
61         status = "PASS"
62     functest_utils.logger_test_results(logger, "Doctor",
63                                        "doctor-notification",
64                                        status, details)
65     if args.report:
66         functest_utils.push_results_to_db("doctor",
67                                           "doctor-notification",
68                                           logger,
69                                           start_time,
70                                           stop_time,
71                                           status,
72                                           details)
73         logger.info("Doctor results pushed to DB")
74
75     exit(exit_code)
76
77 if __name__ == '__main__':
78     main()