X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=ci%2Frun_tests.py;h=5dba1819038fb3b55e863d3a2ac28dad9ec23a6d;hb=ff4884e24b60306c287d341ee057c106f2b5ba9e;hp=95bc98021b90e37ea613f0a879f505e4fa71adaa;hpb=bbf10c2ae8c2205c89065d8d57e3340d9b2efd40;p=functest.git diff --git a/ci/run_tests.py b/ci/run_tests.py index 95bc98021..5dba18190 100644 --- a/ci/run_tests.py +++ b/ci/run_tests.py @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env python # # Author: Jose Lausuch (jose.lausuch@ericsson.com) # @@ -10,11 +10,14 @@ import argparse import os +import re import sys import functest.ci.tier_builder as tb -import functest.utils.functest_logger as ft_logger import functest.utils.clean_openstack as clean_os +import functest.utils.functest_logger as ft_logger +import functest.utils.functest_utils as ft_utils +import functest.utils.openstack_utils as os_utils """ arguments """ @@ -31,7 +34,7 @@ args = parser.parse_args() """ logging configuration """ -logger = ft_logger.Logger("run_test").getLogger() +logger = ft_logger.Logger("run_tests").getLogger() """ global variables """ @@ -46,21 +49,24 @@ def print_separator(str, count=45): line = "" for i in range(0, count - 1): line += str - logger.info("%s" % line) +def source_rc_file(): + rc_file = os.getenv('creds') + if not os.path.isfile(rc_file): + logger.error("RC file %s does not exist..." % rc_file) + sys.exit(1) + logger.info("Sourcing the OpenStack RC file...") + os_utils.source_credentials(rc_file) + + def cleanup(): - print_separator("+") - logger.info("Cleaning OpenStack resources...") - print_separator("+") clean_os.main() - print_separator("") def run_test(test): test_name = test.get_name() - print_separator("") print_separator("=") logger.info("Running test case '%s'..." % test_name) print_separator("=") @@ -70,9 +76,16 @@ def run_test(test): flags += " -r" cmd = ("%s%s" % (EXEC_SCRIPT, flags)) - logger.debug("Executing command %s" % cmd) + logger.debug("Executing command '%s'" % cmd) + + result = ft_utils.execute_command(cmd, logger, exit_on_error=False) - print_separator("") + if result != 0: + logger.error("The test case '%s' failed. Cleaning and exiting." + % test_name) + if CLEAN_FLAG: + cleanup() + sys.exit(1) if CLEAN_FLAG: cleanup() @@ -88,8 +101,26 @@ def run_tier(tier): def run_all(tiers): - logger.debug("Tiers to be executed:\n\n%s" % tiers) + summary = "" + BUILD_TAG = os.getenv('BUILD_TAG') + if BUILD_TAG is not None and re.search("daily", BUILD_TAG) is not None: + CI_LOOP = "daily" + else: + CI_LOOP = "weekly" + + tiers_to_run = [] + for tier in tiers.get_tiers(): + if re.search(CI_LOOP, tier.get_ci_loop()) is not None: + tiers_to_run.append(tier) + summary += ("\n - %s. %s:\n\t %s" + % (tier.get_order(), + tier.get_name(), + tier.get_test_names())) + + logger.info("Tiers to be executed:%s" % summary) + + for tier in tiers_to_run: run_tier(tier) @@ -110,6 +141,7 @@ def main(): REPORT_FLAG = True if args.test: + source_rc_file() if _tiers.get_tier(args.test): run_tier(_tiers.get_tier(args.test))