Merge "Corrected project lead"
[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 sys
20 import yaml
21
22
23 with open('/home/opnfv/functest/conf/config_functest.yaml') as f:
24     functest_yaml = yaml.safe_load(f)
25
26 dirs = functest_yaml.get('general').get('directories')
27 FUNCTEST_REPO = dirs.get('dir_repo_functest')
28 DOCTOR_REPO = dirs.get('dir_repo_doctor')
29 TEST_DB_URL = functest_yaml.get('results').get('test_db_url')
30
31 sys.path.append('%s/testcases' % FUNCTEST_REPO)
32 import functest_utils
33
34
35 def main():
36     cmd = 'cd %s/tests && ./run.sh' % DOCTOR_REPO
37     start_time_ts = time.time()
38
39     ret = functest_utils.execute_command(cmd, exit_on_error=False)
40
41     end_time_ts = time.time()
42     duration = round(end_time_ts - start_time_ts, 1)
43     if ret:
44         test_status = 'OK'
45     else:
46         test_status = 'NOK'
47
48     details = {
49         'timestart': start_time_ts,
50         'duration': duration,
51         'status': test_status,
52     }
53     pod_name = functest_utils.get_pod_name()
54     git_version = functest_utils.get_git_branch(DOCTOR_REPO)
55     functest_utils.push_results_to_db(TEST_DB_URL,
56                                       'doctor-notification',
57                                       None,
58                                       pod_name,
59                                       git_version,
60                                       details)
61
62
63 if __name__ == '__main__':
64     main()