X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=functest%2Fcore%2Fvnf.py;h=856e62b5a4d6b63ae0f8abc9a91a7a024bee93f8;hb=45fdfedc5b5573926c53264ff5eb3e48a43345d9;hp=0589b5d2a1ae50deb23d26a008ef8d20263b71ca;hpb=e7ab53553d719b0fb35b4a74cd0bbc9572c7a48d;p=functest.git diff --git a/functest/core/vnf.py b/functest/core/vnf.py index 0589b5d2a..856e62b5a 100644 --- a/functest/core/vnf.py +++ b/functest/core/vnf.py @@ -11,10 +11,15 @@ import logging import time +import uuid import functest.core.testcase as base from functest.utils.constants import CONST -import functest.utils.openstack_utils as os_utils +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 __author__ = ("Morgan Richomme , " "Valentin Boucher ") @@ -43,27 +48,26 @@ class VnfOnBoarding(base.TestCase): def __init__(self, **kwargs): super(VnfOnBoarding, self).__init__(**kwargs) - self.tenant_created = False - self.user_created = False self.tenant_name = CONST.__getattribute__( 'vnf_{}_tenant_name'.format(self.case_name)) - self.tenant_description = CONST.__getattribute__( - 'vnf_{}_tenant_description'.format(self.case_name)) + self.snaps_creds = {} + self.created_object = [] + self.os_project = None def run(self, **kwargs): """ Run of the VNF test case: - * Deploy an orchestrator if needed (e.g. heat, cloudify, ONAP), + * Deploy an orchestrator if needed (e.g. heat, cloudify, ONAP,...), * Deploy the VNF, * Perform tests on the VNF A VNF test case is successfull when the 3 steps are PASS If one of the step is FAIL, the test case is FAIL - Returns: - TestCase.EX_OK if result is 'PASS'. - TestCase.EX_TESTCASE_FAILED otherwise. + Returns: + TestCase.EX_OK if result is 'PASS'. + TestCase.EX_TESTCASE_FAILED otherwise. """ self.start_time = time.time() @@ -78,8 +82,10 @@ class VnfOnBoarding(base.TestCase): return base.TestCase.EX_OK else: self.result = 0 + self.stop_time = time.time() return base.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 @@ -96,20 +102,35 @@ 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, self.tenant_description) - admin_creds = os_utils.get_credentials() - keystone_client = os_utils.get_keystone_client() - self.tenant_created = os_utils.get_or_create_tenant_for_vnf( - keystone_client, self.tenant_name, self.tenant_description) - self.user_created = os_utils.get_or_create_user_for_vnf( - keystone_client, self.tenant_name) - creds = admin_creds.copy() - creds.update({ - "tenant": self.tenant_name, - "username": self.tenant_name, - "password": self.tenant_name - }) + self.tenant_name, tenant_description) + snaps_creds = openstack_tests.get_credentials( + os_env_file=CONST.__getattribute__('openstack_creds')) + + project_creator = OpenStackProject( + snaps_creds, + ProjectConfig( + name=self.tenant_name, + description=tenant_description + )) + project_creator.create() + self.created_object.append(project_creator) + self.os_project = project_creator + + user_creator = OpenStackUser( + snaps_creds, + UserConfig( + name=self.tenant_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 except Exception: # pylint: disable=broad-except self.__logger.exception("Exception raised during VNF preparation") @@ -119,9 +140,8 @@ class VnfOnBoarding(base.TestCase): """ Deploy an orchestrator (optional). - If function overwritten - raise orchestratorDeploymentException if error during orchestrator - deployment + If this method is overriden then raise orchestratorDeploymentException + if error during orchestrator deployment """ self.__logger.info("Deploy orchestrator (if necessary)") return True @@ -134,10 +154,8 @@ class VnfOnBoarding(base.TestCase): The details section MAY be updated in the vnf test cases. The deployment can be executed via a specific orchestrator - or using nuild-in orchestrators such as: - - * heat, openbaton, cloudify (available on all scenario), - * open-o (on open-o scenarios) + or using build-in orchestrators such as heat, OpenBaton, cloudify, + juju, onap, ... Returns: True if the VNF is properly deployed @@ -181,8 +199,9 @@ class VnfOnBoarding(base.TestCase): * the tenant """ self.__logger.info("test cleaning") - keystone_client = os_utils.get_keystone_client() - if self.tenant_created: - os_utils.delete_tenant(keystone_client, self.tenant_name) - if self.user_created: - os_utils.delete_user(keystone_client, self.tenant_name) + self.__logger.info('Remove the cloudify manager OS object ..') + for creator in reversed(self.created_object): + try: + creator.clean() + except Exception as exc: # pylint: disable=broad-except + self.__logger.error('Unexpected error cleaning - %s', exc)