aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2016-10-12 15:07:03 +0200
committerJose Lausuch <jose.lausuch@ericsson.com>2016-10-18 14:04:20 +0000
commit2aa78bdb5b21ac54b2f1183001c7466e59952c29 (patch)
tree1a59d96aeb745296abade415ebb12a05ac204aee
parentd04a2af1d4864014492702a8a48bf1171cae6bcb (diff)
Use importlib to load testcases
It modifies run_tests.py to dynamically execute testcases and then removes the test condition about odl. It also induces that the modules and the related classes must be defined in ci/testcases.yaml. JIRA: FUNCTEST-353 Change-Id: I6ad67b70624aac6bf805c9bde4dfef7c9fbd5c00 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rwxr-xr-xci/run_tests.py40
-rw-r--r--ci/testcases.yaml3
-rw-r--r--utils/functest_utils.py11
3 files changed, 45 insertions, 9 deletions
diff --git a/ci/run_tests.py b/ci/run_tests.py
index 834a29bfe..f30062f75 100755
--- a/ci/run_tests.py
+++ b/ci/run_tests.py
@@ -9,6 +9,7 @@
#
import datetime
+import importlib
import os
import re
import sys
@@ -23,7 +24,6 @@ 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
-import functest.testcases.Controllers.ODL.OpenDaylightTesting as odl_test
parser = argparse.ArgumentParser()
@@ -84,6 +84,19 @@ def update_test_info(test_name, result, duration):
"duration": duration})
+def get_run_dict_if_defined(testname):
+ try:
+ dict = ft_utils.get_dict_by_test(testname)
+ if not dict:
+ logger.error("Cannot get {}'s config options".format(testname))
+ elif 'run' in dict:
+ return dict['run']
+ return None
+ except Exception:
+ logger.exception("Cannot get {}'s config options".format(testname))
+ return None
+
+
def run_test(test, tier_name):
global OVERALL_RESULT, EXECUTED_TEST_CASES
result_str = "PASS"
@@ -102,14 +115,27 @@ def run_test(test, tier_name):
if REPORT_FLAG:
flags += " -r"
- if test_name == 'odl':
- odl = odl_test.ODLTestCases()
- result = odl.run()
- if result == TestCasesBase.TestCasesBase.EX_OK and REPORT_FLAG:
- result = odl.push_to_db()
+ result = TestCasesBase.TestCasesBase.EX_RUN_ERROR
+ run_dict = get_run_dict_if_defined(test_name)
+ if run_dict:
+ try:
+ module = importlib.import_module(run_dict['module'])
+ cls = getattr(module, run_dict['class'])
+ test_case = cls()
+ result = test_case.run()
+ if result == TestCasesBase.TestCasesBase.EX_OK and REPORT_FLAG:
+ result = test_case.push_to_db()
+ except ImportError:
+ logger.exception("Cannot import module {}".format(
+ run_dict['module']))
+ except AttributeError:
+ logger.exception("Cannot get class {}".format(
+ run_dict['class']))
else:
cmd = ("%s%s" % (EXEC_SCRIPT, flags))
- logger.debug("Executing command '%s'" % cmd)
+ logger.info("Executing command {} because {} "
+ "doesn't implement the new framework".format(
+ cmd, test_name))
result = ft_utils.execute_command(cmd)
if CLEAN_FLAG:
diff --git a/ci/testcases.yaml b/ci/testcases.yaml
index 02b69ec8b..22509e611 100644
--- a/ci/testcases.yaml
+++ b/ci/testcases.yaml
@@ -92,6 +92,9 @@ tiers:
dependencies:
installer: ''
scenario: 'odl'
+ run:
+ module: 'functest.testcases.Controllers.ODL.OpenDaylightTesting'
+ class: 'ODLTestCases'
-
name: onos
diff --git a/utils/functest_utils.py b/utils/functest_utils.py
index ef865bedf..41b6485d9 100644
--- a/utils/functest_utils.py
+++ b/utils/functest_utils.py
@@ -341,19 +341,26 @@ def get_deployment_dir():
return deployment_dir
-def get_criteria_by_test(testname):
+def get_dict_by_test(testname):
with open(get_testcases_file()) as f:
testcases_yaml = yaml.safe_load(f)
for dic_tier in testcases_yaml.get("tiers"):
for dic_testcase in dic_tier['testcases']:
if dic_testcase['name'] == testname:
- return dic_testcase['criteria']
+ return dic_testcase
logger.error('Project %s is not defined in testcases.yaml' % testname)
return None
+def get_criteria_by_test(testname):
+ dict = get_dict_by_test(testname)
+ if dict:
+ return dict['criteria']
+ return None
+
+
# ----------------------------------------------------------
#
# YAML UTILS