Update release notes with arm results
[functest.git] / ci / run_tests.py
index a024dd7..af8f51d 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python -u
 #
 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
 #
@@ -8,11 +8,13 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 #
 
-import argparse
 import datetime
 import os
 import re
 import sys
+
+import argparse
+
 import functest.ci.generate_report as generate_report
 import functest.ci.tier_builder as tb
 import functest.utils.functest_logger as ft_logger
@@ -20,7 +22,7 @@ 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
-
+from functest.testcases.Controllers.ODL.OpenDaylightTesting import ODLTestCases
 
 parser = argparse.ArgumentParser()
 parser.add_argument("-t", "--test", dest="test", action='store',
@@ -39,9 +41,7 @@ logger = ft_logger.Logger("run_tests").getLogger()
 
 
 """ global variables """
-REPOS_DIR = os.getenv('repos_dir')
-FUNCTEST_REPO = ("%s/functest/" % REPOS_DIR)
-EXEC_SCRIPT = ("%sci/exec_test.sh" % FUNCTEST_REPO)
+EXEC_SCRIPT = ("%s/ci/exec_test.sh" % ft_utils.FUNCTEST_REPO)
 CLEAN_FLAG = True
 REPORT_FLAG = False
 EXECUTED_TEST_CASES = []
@@ -75,6 +75,13 @@ def cleanup():
     os_clean.main()
 
 
+def update_test_info(test_name, result, duration):
+    for test in EXECUTED_TEST_CASES:
+        if test['test_name'] == test_name:
+            test.update({"result": result,
+                         "duration": duration})
+
+
 def run_test(test, tier_name):
     global OVERALL_RESULT, EXECUTED_TEST_CASES
     result_str = "PASS"
@@ -93,9 +100,15 @@ def run_test(test, tier_name):
     if REPORT_FLAG:
         flags += " -r"
 
-    cmd = ("%s%s" % (EXEC_SCRIPT, flags))
-    logger.debug("Executing command '%s'" % cmd)
-    result = ft_utils.execute_command(cmd, logger, exit_on_error=False)
+    if test_name == 'odl':
+        result = ODLTestCases.functest_run()
+        if result and REPORT_FLAG:
+            result = ODLTestCases.push_to_db()
+        result = not result
+    else:
+        cmd = ("%s%s" % (EXEC_SCRIPT, flags))
+        logger.debug("Executing command '%s'" % cmd)
+        result = ft_utils.execute_command(cmd, exit_on_error=False)
 
     if CLEAN_FLAG:
         cleanup()
@@ -109,16 +122,17 @@ def run_test(test, tier_name):
         OVERALL_RESULT = -1
         result_str = "FAIL"
 
-        if test.get_blocking():
-            logger.info("This test case is blocking. Exiting...")
+        if test.is_blocking():
+            if not args.test or args.test == "all":
+                logger.info("This test case is blocking. Aborting overall "
+                            "execution.")
+                # if it is a single test we don't print the whole results table
+                update_test_info(test_name, result_str, duration_str)
+                generate_report.main(EXECUTED_TEST_CASES)
+            logger.info("Execution exit value: %s" % OVERALL_RESULT)
             sys.exit(OVERALL_RESULT)
 
-    for test in EXECUTED_TEST_CASES:
-        if test['test_name'] == test_name:
-            test.update({"result": result_str,
-                         "duration": duration_str})
-
-    return result
+    update_test_info(test_name, result_str, duration_str)
 
 
 def run_tier(tier):
@@ -134,11 +148,7 @@ def run_tier(tier):
     print_separator("#")
     logger.debug("\n%s" % tier)
     for test in tests:
-        res = run_test(test, tier_name)
-        if res != 0:
-            return res
-
-    return 0
+        run_test(test, tier_name)
 
 
 def run_all(tiers):
@@ -163,12 +173,9 @@ def run_all(tiers):
     logger.info("Tests to be executed:%s" % summary)
     EXECUTED_TEST_CASES = generate_report.init(tiers_to_run)
     for tier in tiers_to_run:
-        res = run_tier(tier)
-        if res != 0:
-            return res
-    generate_report.main(EXECUTED_TEST_CASES)
+        run_tier(tier)
 
-    return 0
+    generate_report.main(EXECUTED_TEST_CASES)
 
 
 def main():
@@ -178,7 +185,7 @@ def main():
     CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
     CI_SCENARIO = os.getenv('DEPLOY_SCENARIO')
 
-    file = FUNCTEST_REPO + "/ci/testcases.yaml"
+    file = ft_utils.get_testcases_file()
     _tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, file)
 
     if args.noclean:
@@ -207,6 +214,7 @@ def main():
     else:
         run_all(_tiers)
 
+    logger.info("Execution exit value: %s" % OVERALL_RESULT)
     sys.exit(OVERALL_RESULT)
 
 if __name__ == '__main__':