From b3916af1754e02bb952b431a36c70b0c3aee9a0a Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Sun, 1 Jul 2018 11:11:33 +0200 Subject: Create Member role if required MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seems there is no common role configuration between OPNFV installers. Then it creates/removes the expected role if required. Change-Id: I38a92e2522a401f46a59813b9e9443a11d6c7060 Signed-off-by: Cédric Ollivier --- functest/core/tenantnetwork.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/functest/core/tenantnetwork.py b/functest/core/tenantnetwork.py index bf14f4126..ea69fcba6 100644 --- a/functest/core/tenantnetwork.py +++ b/functest/core/tenantnetwork.py @@ -36,6 +36,7 @@ class NewProject(object): # pylint: disable=too-many-instance-attributes __logger = logging.getLogger(__name__) + default_member = "Member" def __init__(self, cloud, case_name, guid): self.cloud = None @@ -46,6 +47,7 @@ class NewProject(object): self.user = None self.password = None self.domain = None + self.role = None def create(self): """Create projects/users""" @@ -66,8 +68,14 @@ class NewProject(object): password=self.password, domain_id=self.domain.id) self.__logger.debug("user: %s", self.user) + try: + assert self.orig_cloud.get_role(self.default_member) + except Exception: # pylint: disable=broad-except + self.__logger.info("Creating default role %s", self.default_member) + self.role = self.orig_cloud.create_role(self.default_member) + self.__logger.debug("role: %s", self.role) self.orig_cloud.grant_role( - "Member", user=self.user.id, project=self.project.id, + self.default_member, user=self.user.id, project=self.project.id, domain=self.domain.id) osconfig = os_client_config.config.OpenStackConfig() osconfig.cloud_config[ @@ -87,6 +95,8 @@ class NewProject(object): assert self.project.id self.orig_cloud.delete_user(self.user.id) self.orig_cloud.delete_project(self.project.id) + if self.role: + self.orig_cloud.delete_role(self.role.id) except Exception: # pylint: disable=broad-except self.__logger.exception("Cannot clean all ressources") -- cgit 1.2.3-korg