aboutsummaryrefslogtreecommitdiffstats
path: root/functest/core
diff options
context:
space:
mode:
Diffstat (limited to 'functest/core')
-rw-r--r--functest/core/feature.py (renamed from functest/core/feature_base.py)12
-rw-r--r--functest/core/pytest_suite_runner.py8
-rw-r--r--functest/core/testcase.py (renamed from functest/core/testcase_base.py)65
-rw-r--r--functest/core/vnf_base.py34
4 files changed, 87 insertions, 32 deletions
diff --git a/functest/core/feature_base.py b/functest/core/feature.py
index 2bd1ec83..325c10d4 100644
--- a/functest/core/feature_base.py
+++ b/functest/core/feature.py
@@ -1,15 +1,15 @@
import time
-import testcase_base as base
+import testcase as base
import functest.utils.functest_utils as ft_utils
import functest.utils.functest_logger as ft_logger
from functest.utils.constants import CONST
-class FeatureBase(base.TestcaseBase):
+class Feature(base.TestCase):
def __init__(self, project='functest', case='', repo='', cmd=''):
- super(FeatureBase, self).__init__()
+ super(Feature, self).__init__()
self.project_name = project
self.case_name = case
self.cmd = cmd
@@ -26,7 +26,7 @@ class FeatureBase(base.TestcaseBase):
self.parse_results(ret)
self.log_results()
self.logger.info("Test result is stored in '%s'" % self.result_file)
- return base.TestcaseBase.EX_OK
+ return base.TestCase.EX_OK
def execute(self):
'''
@@ -42,13 +42,13 @@ class FeatureBase(base.TestcaseBase):
pass
def parse_results(self, ret):
- exit_code = base.TestcaseBase.EX_OK
+ exit_code = base.TestCase.EX_OK
if ret == 0:
self.logger.info("{} OK".format(self.project_name))
self.criteria = 'PASS'
else:
self.logger.info("{} FAILED".format(self.project_name))
- exit_code = base.TestcaseBase.EX_RUN_ERROR
+ exit_code = base.TestCase.EX_RUN_ERROR
self.criteria = "FAIL"
return exit_code
diff --git a/functest/core/pytest_suite_runner.py b/functest/core/pytest_suite_runner.py
index f0ae265a..4f777628 100644
--- a/functest/core/pytest_suite_runner.py
+++ b/functest/core/pytest_suite_runner.py
@@ -5,12 +5,12 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
-import testcase_base as base
+import testcase as base
import unittest
import time
-class PyTestSuiteRunner(base.TestcaseBase):
+class PyTestSuiteRunner(base.TestCase):
"""
This superclass is designed to execute pre-configured unittest.TestSuite()
objects
@@ -42,9 +42,9 @@ class PyTestSuiteRunner(base.TestcaseBase):
# a result can be PASS or FAIL
# But in this case it means that the Execution was OK
# we shall distinguish Execution Error from FAIL results
- # TestcaseBase.EX_RUN_ERROR means that the test case was not run
+ # TestCase.EX_RUN_ERROR means that the test case was not run
# not that it was run but the result was FAIL
- exit_code = base.TestcaseBase.EX_OK
+ exit_code = base.TestCase.EX_OK
if ((result.errors and len(result.errors) > 0)
or (result.failures and len(result.failures) > 0)):
self.logger.info("%s FAILED" % self.case_name)
diff --git a/functest/core/testcase_base.py b/functest/core/testcase.py
index 2848073f..b540cfb5 100644
--- a/functest/core/testcase_base.py
+++ b/functest/core/testcase.py
@@ -7,13 +7,18 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
+"""Define the parent class of Functest TestCase."""
+
import os
import functest.utils.functest_logger as ft_logger
import functest.utils.functest_utils as ft_utils
+__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
+
-class TestcaseBase(object):
+class TestCase(object):
+ """Parent class of Functest TestCase."""
EX_OK = os.EX_OK
EX_RUN_ERROR = os.EX_SOFTWARE
@@ -31,20 +36,66 @@ class TestcaseBase(object):
self.stop_time = ""
def check_criteria(self):
+ """Interpret the results of TestCase.
+
+ It allows getting the results of TestCase. It completes run()
+ which only returns the execution status.
+
+ It can be overriden if checking criteria is not suitable.
+
+ Returns:
+ TestCase.EX_OK if criteria is 'PASS'.
+ TestCase.EX_TESTCASE_FAILED otherwise.
+ """
try:
assert self.criteria
if self.criteria == 'PASS':
- return TestcaseBase.EX_OK
+ return TestCase.EX_OK
except AssertionError:
self.logger.error("Please run test before checking the results")
- return TestcaseBase.EX_TESTCASE_FAILED
+ return TestCase.EX_TESTCASE_FAILED
def run(self, **kwargs):
+ """Run TestCase.
+
+ It allows running TestCase and getting its execution
+ status.
+
+ The subclasses must override the default implementation which
+ is false on purpose. The only prerequisite is to set the
+ following attributes to push the results to DB:
+ * case_name,
+ * criteria,
+ * start_time,
+ * stop_time.
+
+ Args:
+ **kwargs: Arbitrary keyword arguments.
+
+ Returns:
+ TestCase.EX_RUN_ERROR.
+ """
# pylint: disable=unused-argument
self.logger.error("Run must be implemented")
- return TestcaseBase.EX_RUN_ERROR
+ return TestCase.EX_RUN_ERROR
def push_to_db(self):
+ """Push the results of TestCase to the DB.
+
+ It allows publishing the results and to check the status.
+
+ It could be overriden if the common implementation is not
+ suitable. The following attributes must be set before pushing
+ the results to DB:
+ * case_name,
+ * criteria,
+ * start_time,
+ * stop_time.
+
+ Returns:
+ TestCase.EX_OK if results were pushed to DB.
+ TestCase.EX_PUSH_TO_DB_ERROR otherwise.
+ """
try:
assert self.project_name
assert self.case_name
@@ -55,10 +106,10 @@ class TestcaseBase(object):
self.project_name, self.case_name, self.start_time,
self.stop_time, self.criteria, self.details):
self.logger.info("The results were successfully pushed to DB")
- return TestcaseBase.EX_OK
+ return TestCase.EX_OK
else:
self.logger.error("The results cannot be pushed to DB")
- return TestcaseBase.EX_PUSH_TO_DB_ERROR
+ return TestCase.EX_PUSH_TO_DB_ERROR
except Exception: # pylint: disable=broad-except
self.logger.exception("The results cannot be pushed to DB")
- return TestcaseBase.EX_PUSH_TO_DB_ERROR
+ return TestCase.EX_PUSH_TO_DB_ERROR
diff --git a/functest/core/vnf_base.py b/functest/core/vnf_base.py
index f5e86054..3f0adcc6 100644
--- a/functest/core/vnf_base.py
+++ b/functest/core/vnf_base.py
@@ -7,18 +7,17 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
-import time
-
import inspect
+import time
+import functest.core.testcase as base
+from functest.utils.constants import CONST
import functest.utils.functest_logger as ft_logger
-import functest.utils.openstack_utils as os_utils
import functest.utils.functest_utils as ft_utils
-import testcase_base as base
-from functest.utils.constants import CONST
+import functest.utils.openstack_utils as os_utils
-class VnfOnBoardingBase(base.TestcaseBase):
+class VnfOnBoardingBase(base.TestCase):
logger = ft_logger.Logger(__name__).getLogger()
@@ -29,7 +28,7 @@ class VnfOnBoardingBase(base.TestcaseBase):
self.case_name = case
self.cmd = cmd
self.details = {}
- self.data_dir = CONST.dir_functest_data
+ self.result_dir = CONST.dir_results
self.details['orchestrator'] = {}
self.details['vnf'] = {}
self.details['test_vnf'] = {}
@@ -39,14 +38,14 @@ class VnfOnBoardingBase(base.TestcaseBase):
'vnf_{}_tenant_name'.format(self.case_name))
self.tenant_description = CONST.__getattribute__(
'vnf_{}_tenant_description'.format(self.case_name))
- except:
+ except Exception:
# raise Exception("Unknown VNF case=" + self.case_name)
self.logger.error("Unknown VNF case={}".format(self.case_name))
try:
self.images = CONST.__getattribute__(
'vnf_{}_tenant_images'.format(self.case_name))
- except:
+ except Exception:
self.logger.warn("No tenant image defined for this VNF")
def execute(self):
@@ -58,7 +57,7 @@ class VnfOnBoardingBase(base.TestcaseBase):
except Exception:
self.logger.error("Error during VNF Onboarding environment" +
"creation", exc_info=True)
- return base.TestcaseBase.EX_TESTCASE_FAILED
+ return base.TestCase.EX_TESTCASE_FAILED
# Deploy orchestrator
try:
@@ -87,7 +86,7 @@ class VnfOnBoardingBase(base.TestcaseBase):
vnf_ready_time - orchestrator_ready_time, 1)
except Exception:
self.logger.error("Error during VNF deployment", exc_info=True)
- return base.TestcaseBase.EX_TESTCASE_FAILED
+ return base.TestCase.EX_TESTCASE_FAILED
# Test VNF
try:
@@ -100,7 +99,7 @@ class VnfOnBoardingBase(base.TestcaseBase):
test_vnf_done_time - vnf_ready_time, 1)
except Exception:
self.logger.error("Error when running VNF tests", exc_info=True)
- return base.TestcaseBase.EX_TESTCASE_FAILED
+ return base.TestCase.EX_TESTCASE_FAILED
# Clean the system
self.clean()
@@ -234,7 +233,12 @@ class VnfOnBoardingBase(base.TestcaseBase):
def step_failure(self, error_msg):
part = inspect.stack()[1][3]
- self.details[part]['status'] = 'FAIL'
- self.details[part]['result'] = error_msg
- self.logger.error("Step failure:{}".format(error_msg))
+ self.logger.error("Step '%s' failed: %s", part, error_msg)
+ try:
+ part_info = self.details[part]
+ except KeyError:
+ self.details[part] = {}
+ part_info = self.details[part]
+ part_info['status'] = 'FAIL'
+ part_info['result'] = error_msg
raise Exception(error_msg)