Merge "Fix Pep8 issues related to \"
[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 import functest.core.testcase_base as testcase_base
23 import functest.utils.functest_constants as ft_constants
24 import functest.utils.functest_logger as ft_logger
25 import functest.utils.functest_utils as ft_utils
26
27
28 class DominoCases(testcase_base.TestcaseBase):
29     DOMINO_REPO = ft_constants.DOMINO_REPO_DIR
30     RESULTS_DIR = ft_constants.FUNCTEST_RESULTS_DIR
31     logger = ft_logger.Logger("domino").getLogger()
32
33     def __init__(self):
34         super(DominoCases, self).__init__()
35         self.project_name = "domino"
36         self.case_name = "domino-multinode"
37
38     def main(self, **kwargs):
39         cmd = 'cd %s && ./tests/run_multinode.sh' % self.DOMINO_REPO
40         log_file = os.path.join(self.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         if ret == 0:
48             self.logger.info("domino OK")
49             status = 'PASS'
50         else:
51             self.logger.info("domino FAILED")
52             status = "FAIL"
53
54         # report status only if tests run (FAIL OR PASS)
55         self.criteria = status
56         self.start_time = start_time
57         self.stop_time = stop_time
58         self.details = {}
59
60     def run(self):
61         kwargs = {}
62         return self.main(**kwargs)
63
64 if __name__ == '__main__':
65     parser = argparse.ArgumentParser()
66     parser.add_argument("-r", "--report",
67                         help="Create json result file",
68                         action="store_true")
69     args = vars(parser.parse_args())
70     domino = DominoCases()
71     try:
72         result = domino.main(**args)
73         if result != testcase_base.TestcaseBase.EX_OK:
74             sys.exit(result)
75         if args['report']:
76             sys.exit(domino.push_to_db())
77     except Exception:
78         sys.exit(testcase_base.TestcaseBase.EX_RUN_ERROR)