From 49a7e57f112d855b0609721b6082b15a94417380 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Tue, 23 May 2017 20:58:42 +0200 Subject: Define create_snapshot() and clean() in TestCase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They replace the former calls in run_tests which are not suitable for all test cases. Now any test case can define how to clean its resources. If the snapshot cannot be created, the test case is considered as failed. Only a message is printed if any failure during cleaning. It also defines a new class called OSGCTestCase useful for test cases which don't clean their OpenStack resources. All test cases located in opnfv_tests/openstack inherit from it to keep the global behavior unchanged. It also deletes exit instructions in openstack_clean and openstack_snapshot, removes clean flags in testcases.yaml and updates the related utils. All Docs are modified as well. JIRA: FUNCTEST-438 Change-Id: I8938e6255708012380389763a24059ace4ce45d8 Signed-off-by: Cédric Ollivier --- functest/core/testcase.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'functest/core') diff --git a/functest/core/testcase.py b/functest/core/testcase.py index 43161525..50ca2ce4 100644 --- a/functest/core/testcase.py +++ b/functest/core/testcase.py @@ -15,6 +15,8 @@ import os import prettytable import functest.utils.functest_utils as ft_utils +import functest.utils.openstack_clean as os_clean +import functest.utils.openstack_snapshot as os_snapshot __author__ = "Cedric Ollivier " @@ -176,3 +178,51 @@ class TestCase(object): except Exception: # pylint: disable=broad-except self.__logger.exception("The results cannot be pushed to DB") return TestCase.EX_PUSH_TO_DB_ERROR + + def create_snapshot(self): # pylint: disable=no-self-use + """Save the testing environement before running test. + + It can be overriden if resources must be listed running the + test case. + + Returns: + TestCase.EX_OK + """ + return TestCase.EX_OK + + def clean(self): + """Clean the resources. + + It can be overriden if resources must be deleted after + running the test case. + """ + + +class OSGCTestCase(TestCase): + """Model for single test case which requires an OpenStack Garbage + Collector.""" + + __logger = logging.getLogger(__name__) + + def create_snapshot(self): + """Create a snapshot listing the OpenStack resources. + + Returns: + TestCase.EX_OK if os_snapshot.main() returns 0. + TestCase.EX_RUN_ERROR otherwise. + """ + try: + assert os_snapshot.main() == 0 + self.__logger.info("OpenStack resources snapshot created") + return TestCase.EX_OK + except Exception: # pylint: disable=broad-except + self.__logger.exception("Cannot create the snapshot") + return TestCase.EX_RUN_ERROR + + def clean(self): + """Clean the OpenStack resources.""" + try: + assert os_clean.main() == 0 + self.__logger.info("OpenStack resources cleaned") + except Exception: # pylint: disable=broad-except + self.__logger.exception("Cannot clean the OpenStack resources") -- cgit 1.2.3-korg