Merge "Update onos scenarios in the release notes for Colorado 2.0"
[functest.git] / functest / opnfv_tests / 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 ft_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
31 DOMINO_REPO = \
32     ft_utils.get_functest_config('general.directories.dir_repo_domino')
33 RESULTS_DIR = \
34     ft_utils.get_functest_config('general.directories.dir_results')
35
36 logger = ft_logger.Logger("domino").getLogger()
37
38
39 def main():
40     cmd = 'cd %s && ./tests/run_multinode.sh' % DOMINO_REPO
41     log_file = RESULTS_DIR + "/domino.log"
42     start_time = time.time()
43
44     ret = ft_utils.execute_command(cmd,
45                                    output_file=log_file)
46
47     stop_time = time.time()
48     duration = round(stop_time - start_time, 1)
49     if ret == 0 and duration > 1:
50         logger.info("domino OK")
51         test_status = 'OK'
52     elif ret == 0 and duration <= 1:
53         logger.info("domino TEST SKIPPED")
54         test_status = 'SKIPPED'
55     else:
56         logger.info("domino FAILED")
57         test_status = 'NOK'
58
59     details = {
60         'timestart': start_time,
61         'duration': duration,
62         'status': test_status,
63     }
64
65     status = "FAIL"
66     if details['status'] == "OK":
67         status = "PASS"
68     elif details['status'] == "SKIPPED":
69         status = "SKIP"
70
71     ft_utils.logger_test_results("Domino",
72                                  "domino-multinode",
73                                  status,
74                                  details)
75     if args.report:
76         if status is not "SKIP":
77             ft_utils.push_results_to_db("domino",
78                                         "domino-multinode",
79                                         start_time,
80                                         stop_time,
81                                         status,
82                                         details)
83             logger.info("Domino results pushed to DB")
84
85
86 if __name__ == '__main__':
87     main()