aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerena Feng <feng.xiaowei@zte.com.cn>2016-12-26 03:38:01 +0000
committerGerrit Code Review <gerrit@opnfv.org>2016-12-26 03:38:01 +0000
commit73125b92af78c337bdabef399c4a03057c7a04ee (patch)
tree510746b82f8c11560c9261ac56614e1bf8a2ca78
parent264814da718fcab0abf83e36fd1c3b960db16fd7 (diff)
parentb45170e25650a1671a461a2d5d3cf5883e4e5081 (diff)
Merge "Adapt create_tenant and create_user to keystone v3"
-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"