Add suffix '_DIR' to some constants that point to directories
[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 # 0.4: refactoring to match Test abstraction class
16
17 import argparse
18 import os
19 import sys
20 import time
21
22 from functest.core import TestCasesBase
23 import functest.utils.functest_logger as ft_logger
24 import functest.utils.functest_utils as ft_utils
25 import functest.utils.functest_constants as ft_constants
26
27
28 class DominoTests(TestCasesBase.TestCasesBase):
29     logger = ft_logger.Logger("domino").getLogger()
30
31     def __init__(self):
32         super(DominoTests, self).__init__()
33         self.project_name = "domino"
34         self.case_name = "domino-multinode"
35
36     def main(self, **kwargs):
37         cmd = ('cd %s && ./tests/run_multinode.sh' %
38                ft_constants.DOMINO_REPO_DIR)
39         log_file = os.path.join(
40             ft_constants.FUNCTEST_RESULTS_DIR, "domino.log")
41         start_time = time.time()
42
43         ret = ft_utils.execute_command(cmd,
44                                        output_file=log_file)
45
46         stop_time = time.time()
47         duration = round(stop_time - start_time, 1)
48         if ret == 0 and duration > 1:
49             self.logger.info("domino OK")
50             status = 'PASS'
51         elif ret == 0 and duration <= 1:
52             self.logger.info("domino TEST SKIPPED")
53             status = 'SKIP'
54         else:
55             self.logger.info("domino FAILED")
56             status = "FAIL"
57
58         # report status only if tests run (FAIL OR PASS)
59         if status is not "SKIP":
60             self.criteria = status
61             self.start_time = start_time
62             self.stop_time = stop_time
63             self.details = {}
64
65     def run(self):
66         kwargs = {}
67         return self.main(**kwargs)
68
69
70 if __name__ == '__main__':
71     parser = argparse.ArgumentParser()
72     parser.add_argument("-r", "--report",
73                         help="Create json result file",
74                         action="store_true")
75     args = vars(parser.parse_args())
76     domino = DominoTests()
77     try:
78         result = domino.main(**args)
79         if result != TestCasesBase.TestCasesBase.EX_OK:
80             sys.exit(result)
81         if args['report']:
82             sys.exit(domino.push_to_db())
83     except Exception:
84         sys.exit(TestCasesBase.TestCasesBase.EX_RUN_ERROR)