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_test").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):
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)
66 logger.info("Cleaning OpenStack resources...")
73 test_name = test.get_name()
76 logger.info("Running test case '%s'..." % test_name)
78 logger.debug("\n%s" % test)
79 flags = (" -t %s" % (test_name))
83 cmd = ("%s%s" % (EXEC_SCRIPT, flags))
84 logger.debug("Executing command '%s'" % cmd)
87 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
89 while p.poll() is None:
90 line = p.stdout.readline().rstrip()
94 logger.error("The command '%s' failed. Cleaning and exiting." % cmd)
106 logger.info("Running tier '%s'" % tier.get_name())
108 logger.debug("\n%s" % tier)
109 for test in tier.get_tests():
114 logger.debug("Tiers to be executed:")
115 for tier in tiers.get_tiers():
116 logger.info("\n - %s. %s:\n\t%s"
117 % (tier.get_order(), tier.get_name(), tier.get_tests()))
119 for tier in tiers.get_tiers():
127 CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
128 CI_SCENARIO = os.getenv('DEPLOY_SCENARIO')
130 file = FUNCTEST_REPO + "/ci/testcases.yaml"
131 _tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, file)
141 if _tiers.get_tier(args.test):
142 run_tier(_tiers.get_tier(args.test))
144 elif _tiers.get_test(args.test):
145 run_test(_tiers.get_test(args.test))
147 elif args.test == "all":
151 logger.error("Unknown test case or tier '%s', or not supported by "
152 "the given scenario '%s'."
153 % (args.test, CI_SCENARIO))
154 logger.debug("Available tiers are:\n\n%s"
161 if __name__ == '__main__':