From e4e78c6e30132c17266648e8f212694e4f7fc695 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Fri, 9 Feb 2018 10:14:37 +0100 Subject: Unlink vnf from constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It generates a default description which all testcases can easily override. Change-Id: I81b97c394cf064088767cc934295602f01a7f739 Signed-off-by: Cédric Ollivier --- functest/core/vnf.py | 50 +++++++++++++++++------------------- functest/tests/unit/core/test_vnf.py | 16 +++--------- 2 files changed, 28 insertions(+), 38 deletions(-) (limited to 'functest') diff --git a/functest/core/vnf.py b/functest/core/vnf.py index 0e2e3013..0da8f6db 100644 --- a/functest/core/vnf.py +++ b/functest/core/vnf.py @@ -13,14 +13,14 @@ import logging import time import uuid -import functest.core.testcase as base -from functest.utils.constants import CONST from snaps.config.user import UserConfig from snaps.config.project import ProjectConfig from snaps.openstack.create_user import OpenStackUser from snaps.openstack.create_project import OpenStackProject from snaps.openstack.tests import openstack_tests +from functest.core import testcase + __author__ = ("Morgan Richomme , " "Valentin Boucher ") @@ -41,18 +41,22 @@ class VnfTestException(Exception): """Raise when VNF cannot be tested.""" -class VnfOnBoarding(base.TestCase): +class VnfOnBoarding(testcase.TestCase): + # pylint: disable=too-many-instance-attributes """Base model for VNF test cases.""" __logger = logging.getLogger(__name__) + env_file = "/home/opnfv/functest/conf/env_file" def __init__(self, **kwargs): super(VnfOnBoarding, self).__init__(**kwargs) - self.tenant_name = CONST.__getattribute__( - 'vnf_{}_tenant_name'.format(self.case_name)) + self.user_name = self.case_name + self.tenant_name = self.case_name self.snaps_creds = {} self.created_object = [] self.os_project = None + self.tenant_description = "Created by OPNFV Functest: {}".format( + self.case_name) def run(self, **kwargs): """ @@ -79,15 +83,14 @@ class VnfOnBoarding(base.TestCase): self.stop_time = time.time() # Calculation with different weight depending on the steps TODO self.result = 100 - return base.TestCase.EX_OK - else: - self.result = 0 - self.stop_time = time.time() - return base.TestCase.EX_TESTCASE_FAILED + return testcase.TestCase.EX_OK + self.result = 0 + self.stop_time = time.time() + return testcase.TestCase.EX_TESTCASE_FAILED except Exception: # pylint: disable=broad-except self.stop_time = time.time() self.__logger.exception("Exception on VNF testing") - return base.TestCase.EX_TESTCASE_FAILED + return testcase.TestCase.EX_TESTCASE_FAILED def prepare(self): """ @@ -102,36 +105,31 @@ class VnfOnBoarding(base.TestCase): Raise VnfPreparationException in case of problem """ try: - tenant_description = CONST.__getattribute__( - 'vnf_{}_tenant_description'.format(self.case_name)) - self.__logger.info("Prepare VNF: %s, description: %s", - self.tenant_name, tenant_description) + self.__logger.info( + "Prepare VNF: %s, description: %s", self.tenant_name, + self.tenant_description) snaps_creds = openstack_tests.get_credentials( - os_env_file=CONST.__getattribute__('env_file')) + os_env_file=self.env_file) - project_creator = OpenStackProject( + self.os_project = OpenStackProject( snaps_creds, ProjectConfig( name=self.tenant_name, - description=tenant_description + description=self.tenant_description )) - project_creator.create() - self.created_object.append(project_creator) - self.os_project = project_creator - + self.os_project.create() + self.created_object.append(self.os_project) user_creator = OpenStackUser( snaps_creds, UserConfig( - name=self.tenant_name, + name=self.user_name, password=str(uuid.uuid4()), roles={'admin': self.tenant_name})) - user_creator.create() self.created_object.append(user_creator) - self.snaps_creds = user_creator.get_os_creds(self.tenant_name) - return base.TestCase.EX_OK + return testcase.TestCase.EX_OK except Exception: # pylint: disable=broad-except self.__logger.exception("Exception raised during VNF preparation") raise VnfPreparationException diff --git a/functest/tests/unit/core/test_vnf.py b/functest/tests/unit/core/test_vnf.py index 112ce53b..16a60902 100644 --- a/functest/tests/unit/core/test_vnf.py +++ b/functest/tests/unit/core/test_vnf.py @@ -16,7 +16,6 @@ import mock from functest.core import vnf from functest.core import testcase -from functest.utils import constants from snaps.openstack.os_credentials import OSCreds @@ -29,9 +28,6 @@ class VnfBaseTesting(unittest.TestCase): tenant_description = 'description' def setUp(self): - constants.CONST.__setattr__("vnf_foo_tenant_name", self.tenant_name) - constants.CONST.__setattr__( - "vnf_foo_tenant_description", self.tenant_description) self.test = vnf.VnfOnBoarding(project='functest', case_name='foo') def test_run_deploy_orch_exc(self): @@ -117,8 +113,7 @@ class VnfBaseTesting(unittest.TestCase): def test_prepare_exc1(self, *args): with self.assertRaises(Exception): self.test.prepare() - args[0].assert_called_with( - os_env_file=constants.CONST.__getattribute__('env_file')) + args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file) args[1].assert_not_called() args[2].assert_not_called() @@ -128,8 +123,7 @@ class VnfBaseTesting(unittest.TestCase): def test_prepare_exc2(self, *args): with self.assertRaises(Exception): self.test.prepare() - args[0].assert_called_with( - os_env_file=constants.CONST.__getattribute__('env_file')) + args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file) args[1].assert_called_with(mock.ANY, mock.ANY) args[2].assert_not_called() @@ -139,8 +133,7 @@ class VnfBaseTesting(unittest.TestCase): def test_prepare_exc3(self, *args): with self.assertRaises(Exception): self.test.prepare() - args[0].assert_called_with( - os_env_file=constants.CONST.__getattribute__('env_file')) + args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file) args[1].assert_called_with(mock.ANY, mock.ANY) args[2].assert_called_with(mock.ANY, mock.ANY) @@ -149,8 +142,7 @@ class VnfBaseTesting(unittest.TestCase): @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials') def test_prepare_default(self, *args): self.assertEqual(self.test.prepare(), testcase.TestCase.EX_OK) - args[0].assert_called_with( - os_env_file=constants.CONST.__getattribute__('env_file')) + args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file) args[1].assert_called_with(mock.ANY, mock.ANY) args[2].assert_called_with(mock.ANY, mock.ANY) -- cgit 1.2.3-korg