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
15 import functest.ci.tier_builder as tb
16 import functest.utils.clean_openstack as clean_os
17 import functest.utils.functest_logger as ft_logger
18 import functest.utils.functest_utils as ft_utils
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 result = ft_utils.execute_command(cmd, logger, exit_on_error=False)
83 logger.error("The test case '%s' failed. Cleaning and exiting."
95 logger.info("Running tier '%s'" % tier.get_name())
97 logger.debug("\n%s" % tier)
98 for test in tier.get_tests():
104 for tier in tiers.get_tiers():
105 summary += ("\n - %s. %s:\n\t %s"
108 tier.get_test_names()))
110 logger.info("Tiers to be executed:%s" % summary)
112 for tier in tiers.get_tiers():
120 CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
121 CI_SCENARIO = os.getenv('DEPLOY_SCENARIO')
123 file = FUNCTEST_REPO + "/ci/testcases.yaml"
124 _tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, file)
134 if _tiers.get_tier(args.test):
135 run_tier(_tiers.get_tier(args.test))
137 elif _tiers.get_test(args.test):
138 run_test(_tiers.get_test(args.test))
140 elif args.test == "all":
144 logger.error("Unknown test case or tier '%s', or not supported by "
145 "the given scenario '%s'."
146 % (args.test, CI_SCENARIO))
147 logger.debug("Available tiers are:\n\n%s"
154 if __name__ == '__main__':