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.functest_logger as ft_logger
18 import functest.utils.functest_utils as ft_utils
19 import functest.utils.openstack_clean as os_clean
20 import functest.utils.openstack_snapshot as os_snapshot
21 import functest.utils.openstack_utils as os_utils
24 parser = argparse.ArgumentParser()
25 parser.add_argument("-t", "--test", dest="test", action='store',
26 help="Test case or tier (group of tests) to be executed. "
27 "It will run all the test if not specified.")
28 parser.add_argument("-n", "--noclean", help="Do not clean OpenStack resources"
29 " after running each test (default=false).",
31 parser.add_argument("-r", "--report", help="Push results to database "
32 "(default=false).", action="store_true")
33 args = parser.parse_args()
36 """ logging configuration """
37 logger = ft_logger.Logger("run_tests").getLogger()
40 """ global variables """
41 REPOS_DIR = os.getenv('repos_dir')
42 FUNCTEST_REPO = ("%s/functest/" % REPOS_DIR)
43 EXEC_SCRIPT = ("%sci/exec_test.sh" % FUNCTEST_REPO)
48 def print_separator(str, count=45):
50 for i in range(0, count - 1):
52 logger.info("%s" % line)
56 rc_file = os.getenv('creds')
57 if not os.path.isfile(rc_file):
58 logger.error("RC file %s does not exist..." % rc_file)
60 logger.info("Sourcing the OpenStack RC file...")
61 os_utils.source_credentials(rc_file)
64 def generate_os_snapshot():
73 test_name = test.get_name()
75 logger.info("Running test case '%s'..." % test_name)
77 logger.debug("\n%s" % test)
80 generate_os_snapshot()
82 flags = (" -t %s" % (test_name))
86 cmd = ("%s%s" % (EXEC_SCRIPT, flags))
87 logger.debug("Executing command '%s'" % cmd)
89 result = ft_utils.execute_command(cmd, logger, exit_on_error=False)
92 logger.error("The test case '%s' failed. Cleaning and exiting."
104 logger.info("Running tier '%s'" % tier.get_name())
106 logger.debug("\n%s" % tier)
107 for test in tier.get_tests():
113 BUILD_TAG = os.getenv('BUILD_TAG')
114 if BUILD_TAG is not None and re.search("daily", BUILD_TAG) is not None:
121 for tier in tiers.get_tiers():
122 if re.search(CI_LOOP, tier.get_ci_loop()) is not None:
123 tiers_to_run.append(tier)
124 summary += ("\n - %s. %s:\n\t %s"
127 tier.get_test_names()))
129 logger.info("Tiers to be executed:%s" % summary)
131 for tier in tiers_to_run:
139 CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
140 CI_SCENARIO = os.getenv('DEPLOY_SCENARIO')
142 file = FUNCTEST_REPO + "/ci/testcases.yaml"
143 _tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, file)
153 if _tiers.get_tier(args.test):
154 run_tier(_tiers.get_tier(args.test))
156 elif _tiers.get_test(args.test):
157 run_test(_tiers.get_test(args.test))
159 elif args.test == "all":
163 logger.error("Unknown test case or tier '%s', or not supported by "
164 "the given scenario '%s'."
165 % (args.test, CI_SCENARIO))
166 logger.debug("Available tiers are:\n\n%s"
173 if __name__ == '__main__':