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