From 0e12e2e5ac8f1ae46a1c19436675da5075ea8f44 Mon Sep 17 00:00:00 2001 From: boucherv Date: Thu, 20 Apr 2017 16:20:57 +0200 Subject: [VNF_base] Support existing tenant and user Support existing tenant and user with a get_or_create_tenant method. If the tenant and user already exist it only get the id of those JIRA: FUNCTEST-799 Change-Id: Id5daf2904592e42199471bdd3547e861e6db6e32 Signed-off-by: boucherv --- functest/utils/openstack_utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'functest/utils/openstack_utils.py') diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py index 4663f7ba..929a761e 100644 --- a/functest/utils/openstack_utils.py +++ b/functest/utils/openstack_utils.py @@ -1394,6 +1394,15 @@ def create_tenant(keystone_client, tenant_name, tenant_description): return None +def get_or_create_tenant(keystone_client, tenant_name, tenant_description): + tenant_id = get_tenant_id(keystone_client, tenant_name) + if not tenant_id: + tenant_id = create_tenant(keystone_client, tenant_name, + tenant_description) + + return tenant_id + + def create_user(keystone_client, user_name, user_password, user_email, tenant_id): try: @@ -1417,6 +1426,15 @@ def create_user(keystone_client, user_name, user_password, return None +def get_or_create_user(keystone_client, user_name, user_password, + tenant_id, user_email=None): + user_id = get_user_id(keystone_client, user_name) + if not user_id: + user_id = create_user(keystone_client, user_name, user_password, + user_email, tenant_id) + return user_id + + def add_role_user(keystone_client, user_id, role_id, tenant_id): try: if is_keystone_v3(): -- cgit 1.2.3-korg