3 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
16 import functest.ci.tier_builder as tb
17 import functest.utils.clean_openstack as clean_os
18 import functest.utils.functest_logger as ft_logger
19 import functest.utils.openstack_utils as os_utils
23 parser = argparse.ArgumentParser()
24 parser.add_argument("-t", "--test", dest="test", action='store',
25 help="Test case or tier (group of tests) to be executed. "
26 "It will run all the test if not specified.")
27 parser.add_argument("-n", "--noclean", help="Do not clean OpenStack resources"
28 " after running each test (default=false).",
30 parser.add_argument("-r", "--report", help="Push results to database "
31 "(default=false).", action="store_true")
32 args = parser.parse_args()
35 """ logging configuration """
36 logger = ft_logger.Logger("run_tests").getLogger()
39 """ global variables """
40 REPOS_DIR = os.getenv('repos_dir')
41 FUNCTEST_REPO = ("%s/functest/" % REPOS_DIR)
42 EXEC_SCRIPT = ("%sci/exec_test.sh" % FUNCTEST_REPO)
47 def print_separator(str, count=45):
49 for i in range(0, count - 1):
51 logger.info("%s" % line)
55 rc_file = os.getenv('creds')
56 if not os.path.isfile(rc_file):
57 logger.error("RC file %s does not exist..." % rc_file)
59 logger.info("Sourcing the OpenStack RC file...")
60 os_utils.source_credentials(rc_file)
68 test_name = test.get_name()
70 logger.info("Running test case '%s'..." % test_name)
72 logger.debug("\n%s" % test)
73 flags = (" -t %s" % (test_name))
77 cmd = ("%s%s" % (EXEC_SCRIPT, flags))
78 logger.debug("Executing command '%s'" % cmd)
80 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
82 while p.poll() is None:
83 line = p.stdout.readline().rstrip()
87 logger.error("The test case '%s' failed. Cleaning and exiting."
99 logger.info("Running tier '%s'" % tier.get_name())
101 logger.debug("\n%s" % tier)
102 for test in tier.get_tests():
108 for tier in tiers.get_tiers():
109 summary += ("\n - %s. %s:\n\t %s"
112 tier.get_test_names()))
114 logger.info("Tiers to be executed:%s" % summary)
116 for tier in tiers.get_tiers():
124 CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
125 CI_SCENARIO = os.getenv('DEPLOY_SCENARIO')
127 file = FUNCTEST_REPO + "/ci/testcases.yaml"
128 _tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, file)
138 if _tiers.get_tier(args.test):
139 run_tier(_tiers.get_tier(args.test))
141 elif _tiers.get_test(args.test):
142 run_test(_tiers.get_test(args.test))
144 elif args.test == "all":
148 logger.error("Unknown test case or tier '%s', or not supported by "
149 "the given scenario '%s'."
150 % (args.test, CI_SCENARIO))
151 logger.debug("Available tiers are:\n\n%s"
158 if __name__ == '__main__':