Redirect dominio's output to a log file
[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 time
19
20 import functest.utils.functest_logger as ft_logger
21 import functest.utils.functest_utils as functest_utils
22
23 parser = argparse.ArgumentParser()
24
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 dirs = functest_yaml.get('general').get('directories')
33 DOMINO_REPO = dirs.get('dir_repo_domino')
34 RESULTS_DIR = functest_utils.get_parameter_from_yaml(
35     'general.directories.dir_results')
36
37 logger = ft_logger.Logger("domino").getLogger()
38
39
40 def main():
41     cmd = 'cd %s && ./tests/run_multinode.sh' % DOMINO_REPO
42     log_file = RESULTS_DIR + "/domino.log"
43     start_time = time.time()
44
45     ret = functest_utils.execute_command(cmd,
46                                          exit_on_error=False,
47                                          output_file=log_file)
48
49     stop_time = time.time()
50     duration = round(stop_time - start_time, 1)
51     if ret == 0 and duration > 1:
52         logger.info("domino OK")
53         test_status = 'OK'
54     elif ret == 0 and duration <= 1:
55         logger.info("domino TEST SKIPPED")
56         test_status = 'SKIPPED'
57     else:
58         logger.info("domino FAILED")
59         test_status = 'NOK'
60
61     details = {
62         'timestart': start_time,
63         'duration': duration,
64         'status': test_status,
65     }
66
67     status = "FAIL"
68     if details['status'] == "OK":
69         status = "PASS"
70     elif details['status'] == "SKIPPED":
71         status = "SKIP"
72
73     functest_utils.logger_test_results(logger, "Domino",
74                                        "domino-multinode",
75                                        status, details)
76     if args.report:
77         if status is not "SKIP":
78             functest_utils.push_results_to_db("domino",
79                                               "domino-multinode",
80                                               logger,
81                                               start_time,
82                                               stop_time,
83                                               status,
84                                               details)
85             logger.info("Domino results pushed to DB")
86
87
88 if __name__ == '__main__':
89     main()