X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=ci%2Frun_tests.py;h=b3728ce9f98fa60c6b770101f9cb4812bac501eb;hb=76a691ab6bba6bf0eca9e04ebb5632647ccf8ba6;hp=106214400a2653d0a54d74625954dd5ec2436877;hpb=fa36ceb257c34874fa9169ee5757ec16c8207df6;p=functest.git diff --git a/ci/run_tests.py b/ci/run_tests.py old mode 100644 new mode 100755 index 106214400..b3728ce9f --- 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,16 +10,17 @@ import argparse import os -import subprocess +import re import sys import functest.ci.tier_builder as tb -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_clean as os_clean +import functest.utils.openstack_snapshot as os_snapshot import functest.utils.openstack_utils as os_utils -""" arguments """ parser = argparse.ArgumentParser() parser.add_argument("-t", "--test", dest="test", action='store', help="Test case or tier (group of tests) to be executed. " @@ -33,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 """ @@ -48,7 +49,6 @@ def print_separator(str, count=45): line = "" for i in range(0, count - 1): line += str - logger.info("%s" % line) @@ -61,37 +61,36 @@ def source_rc_file(): os_utils.source_credentials(rc_file) +def generate_os_snapshot(): + os_snapshot.main() + + def cleanup(): - print_separator("+") - logger.info("Cleaning OpenStack resources...") - print_separator("+") - clean_os.main() - print_separator("") + os_clean.main() def run_test(test): test_name = test.get_name() - print_separator("") print_separator("=") logger.info("Running test case '%s'..." % test_name) print_separator("=") logger.debug("\n%s" % test) + + if CLEAN_FLAG: + generate_os_snapshot() + flags = (" -t %s" % (test_name)) if REPORT_FLAG: flags += " -r" cmd = ("%s%s" % (EXEC_SCRIPT, flags)) logger.debug("Executing command '%s'" % cmd) - print_separator("") - - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) - while p.poll() is None: - line = p.stdout.readline().rstrip() - logger.debug(line) + result = ft_utils.execute_command(cmd, logger, exit_on_error=False) - if p != 0: - logger.error("The command '%s' failed. Cleaning and exiting." % cmd) + if result != 0: + logger.error("The test case '%s' failed. Cleaning and exiting." + % test_name) if CLEAN_FLAG: cleanup() sys.exit(1) @@ -100,7 +99,6 @@ def run_test(test): cleanup() - def run_tier(tier): print_separator("#") logger.info("Running tier '%s'" % tier.get_name()) @@ -111,12 +109,26 @@ def run_tier(tier): def run_all(tiers): - logger.debug("Tiers to be executed:") - for tier in tiers.get_tiers(): - logger.info("\n - %s. %s:\n\t%s" - % (tier.get_order(), tier.get_name(), tier.get_tests())) + 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)