Merge "Added 60 sec delay before launching instances in healthcheck"
[functest.git] / ci / run_tests.py
index 95bc980..5dba181 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env python
 #
 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
 #
 
 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))