summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjose.lausuch <jose.lausuch@ericsson.com>2016-12-24 18:29:37 +0100
committerhelenyao <yaohelan@huawei.com>2016-12-25 22:04:14 -0500
commitb45170e25650a1671a461a2d5d3cf5883e4e5081 (patch)
treef35b8b6bc10905856ce51b59c6a70071aa432cb1
parent8f36219f66c7319488c14a46514060e1c84734d2 (diff)
Adapt create_tenant and create_user to keystone v3
JIRA: FUNCTEST-670 Change-Id: I5bb288be2dd5cee1776930ca94d1acad82f50160 Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
-rwxr-xr-xfunctest/utils/openstack_utils.py37
1 files changed, 28 insertions, 9 deletions
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py
index 38a30cb33..e0add0cd2 100755
--- a/functest/utils/openstack_utils.py
+++ b/functest/utils/openstack_utils.py
@@ -173,8 +173,8 @@ def get_session(other_creds={}):
def get_keystone_client_version():
api_version = os.getenv('OS_IDENTITY_API_VERSION')
if api_version is not None:
- logger.info("OS_IDENTITY_API_VERSION is set in env as '%s'",
- api_version)
+ logger.debug("OS_IDENTITY_API_VERSION is set in env as '%s'",
+ api_version)
return api_version
return DEFAULT_API_VERSION
@@ -1302,9 +1302,16 @@ def get_role_id(keystone_client, role_name):
def create_tenant(keystone_client, tenant_name, tenant_description):
try:
- tenant = keystone_client.tenants.create(tenant_name,
- tenant_description,
- enabled=True)
+ if get_keystone_client_version() == '2':
+ tenant = keystone_client.tenants.create(tenant_name,
+ tenant_description,
+ enabled=True)
+ else:
+ tenant = keystone_client.projects.create(
+ name=tenant_name,
+ description=tenant_description,
+ domain="default",
+ enabled=True)
return tenant.id
except Exception, e:
logger.error("Error [create_tenant(keystone_client, '%s', '%s')]: %s"
@@ -1315,9 +1322,18 @@ def create_tenant(keystone_client, tenant_name, tenant_description):
def create_user(keystone_client, user_name, user_password,
user_email, tenant_id):
try:
- user = keystone_client.users.create(user_name, user_password,
- user_email, tenant_id,
- enabled=True)
+ if get_keystone_client_version() == '2':
+ user = keystone_client.users.create(user_name,
+ user_password,
+ user_email,
+ tenant_id,
+ enabled=True)
+ else:
+ user = keystone_client.users.create(name=user_name,
+ password=user_password,
+ email=user_email,
+ project_id=tenant_id,
+ enabled=True)
return user.id
except Exception, e:
logger.error("Error [create_user(keystone_client, '%s', '%s', '%s'"
@@ -1338,7 +1354,10 @@ def add_role_user(keystone_client, user_id, role_id, tenant_id):
def delete_tenant(keystone_client, tenant_id):
try:
- keystone_client.tenants.delete(tenant_id)
+ if get_keystone_client_version() == '2':
+ keystone_client.tenants.delete(tenant_id)
+ else:
+ keystone_client.projects.delete(tenant_id)
return True
except Exception, e:
logger.error("Error [delete_tenant(keystone_client, '%s')]: %s"