Create a private shared network for Rally
[functest.git] / ci / run_tests.py
index 95bc980..f30e7b9 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env python
 #
 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
 #
@@ -13,8 +13,10 @@ import os
 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 +33,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 +48,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 +75,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)
 
-    print_separator("")
+    result = ft_utils.execute_command(cmd, logger, exit_on_error=False)
+
+    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,7 +100,15 @@ def run_tier(tier):
 
 
 def run_all(tiers):
-    logger.debug("Tiers to be executed:\n\n%s" % tiers)
+    summary = ""
+    for tier in tiers.get_tiers():
+        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.get_tiers():
         run_tier(tier)
 
@@ -110,6 +130,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))