03ad4a2affa304c00c57b8edb6b78cd498fc1eb9
[functest.git] / testcases / features / domino.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 # 0.3: add report flag to push results when needed
15 #
16
17 import argparse
18 import os
19 import time
20 import yaml
21
22 import functest.utils.functest_logger as ft_logger
23 import functest.utils.functest_utils as functest_utils
24
25 parser = argparse.ArgumentParser()
26
27 parser.add_argument("-r", "--report",
28                     help="Create json result file",
29                     action="store_true")
30 args = parser.parse_args()
31
32 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
33     functest_yaml = yaml.safe_load(f)
34
35 dirs = functest_yaml.get('general').get('directories')
36 FUNCTEST_REPO = dirs.get('dir_repo_functest')
37 DOMINO_REPO = dirs.get('dir_repo_domino')
38
39 logger = ft_logger.Logger("domino").getLogger()
40
41
42 def main():
43     cmd = 'cd %s && ./tests/run_multinode.sh' % DOMINO_REPO
44     start_time = time.time()
45
46     ret = functest_utils.execute_command(cmd, logger, exit_on_error=False)
47
48     stop_time = time.time()
49     duration = round(stop_time - start_time, 1)
50     if ret == 0 and duration > 1:
51         logger.info("domino OK")
52         test_status = 'OK'
53     elif ret == 0 and duration <= 1:
54         logger.info("domino TEST SKIPPED")
55         test_status = 'SKIPPED'
56     else:
57         logger.info("domino FAILED")
58         test_status = 'NOK'
59
60     details = {
61         'timestart': start_time,
62         'duration': duration,
63         'status': test_status,
64     }
65
66     status = "FAIL"
67     if details['status'] == "OK":
68         status = "PASS"
69     elif details['status'] == "SKIPPED":
70         status = "SKIP"
71
72     functest_utils.logger_test_results(logger, "Domino",
73                                        "domino-multinode",
74                                        status, details)
75     if args.report:
76         if status is not "SKIP":
77             functest_utils.push_results_to_db("domino",
78                                               "domino-multinode",
79                                               logger,
80                                               start_time,
81                                               stop_time,
82                                               status,
83                                               details)
84             logger.info("Domino results pushed to DB")
85
86
87 if __name__ == '__main__':
88     main()