aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhelenyao <yaohelan@huawei.com>2016-12-26 01:44:54 -0500
committerhelenyao <yaohelan@huawei.com>2016-12-26 02:06:32 -0500
commit9a9a247166e5818ba16bc19d90d926a006216db1 (patch)
tree70f948d7bf7bf77f7054cea93c3b29d5b9f34979
parent73125b92af78c337bdabef399c4a03057c7a04ee (diff)
Enable the tenant related features
JIRA: FUNCTEST-670 The tenant related features were enabled for OpenStack snapshot and cleanup. Change-Id: Ie9a4012c0d29f57ed5a14139ccb5f8e29b6000dd Signed-off-by: helenyao <yaohelan@huawei.com>
-rwxr-xr-xfunctest/utils/openstack_clean.py8
-rwxr-xr-xfunctest/utils/openstack_snapshot.py2
-rwxr-xr-xfunctest/utils/openstack_utils.py57
3 files changed, 36 insertions, 31 deletions
diff --git a/functest/utils/openstack_clean.py b/functest/utils/openstack_clean.py
index b1ad9664e..15a8f33d5 100755
--- a/functest/utils/openstack_clean.py
+++ b/functest/utils/openstack_clean.py
@@ -397,7 +397,7 @@ def main():
default_security_groups = snapshot_yaml.get('secgroups')
default_floatingips = snapshot_yaml.get('floatingips')
default_users = snapshot_yaml.get('users')
- # default_tenants = snapshot_yaml.get('tenants')
+ default_tenants = snapshot_yaml.get('tenants')
if not os_utils.check_credentials():
logger.error("Please source the openrc credentials and run "
@@ -418,10 +418,8 @@ def main():
separator()
remove_users(keystone_client, default_users)
separator()
- # TODO (Helen) tenant does not exist in V3
- # need to figure our anohter general verification point
- # remove_tenants(keystone_client, default_tenants)
- # separator()
+ remove_tenants(keystone_client, default_tenants)
+ separator()
if __name__ == '__main__':
diff --git a/functest/utils/openstack_snapshot.py b/functest/utils/openstack_snapshot.py
index c59492cfd..e64030f75 100755
--- a/functest/utils/openstack_snapshot.py
+++ b/functest/utils/openstack_snapshot.py
@@ -150,7 +150,7 @@ def main():
snapshot.update(get_security_groups(neutron_client))
snapshot.update(get_floatinips(nova_client))
snapshot.update(get_users(keystone_client))
- # snapshot.update(get_tenants(keystone_client))
+ snapshot.update(get_tenants(keystone_client))
with open(OS_SNAPSHOT_FILE, 'w+') as yaml_file:
yaml_file.write(yaml.safe_dump(snapshot, default_flow_style=False))
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py
index e0add0cd2..64f18504d 100755
--- a/functest/utils/openstack_utils.py
+++ b/functest/utils/openstack_utils.py
@@ -52,14 +52,13 @@ def is_keystone_v3():
def get_rc_env_vars():
- keystone_v3 = is_keystone_v3()
env_vars = ['OS_AUTH_URL', 'OS_USERNAME', 'OS_PASSWORD']
- if keystone_v3 is False:
- env_vars.extend(['OS_TENANT_NAME'])
- else:
+ if is_keystone_v3():
env_vars.extend(['OS_PROJECT_NAME',
'OS_USER_DOMAIN_NAME',
'OS_PROJECT_DOMAIN_NAME'])
+ else:
+ env_vars.extend(['OS_TENANT_NAME'])
return env_vars
@@ -173,8 +172,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.debug("OS_IDENTITY_API_VERSION is set in env as '%s'",
- api_version)
+ logger.info("OS_IDENTITY_API_VERSION is set in env as '%s'",
+ api_version)
return api_version
return DEFAULT_API_VERSION
@@ -1254,7 +1253,10 @@ def delete_volume_type(cinder_client, volume_type):
# *********************************************
def get_tenants(keystone_client):
try:
- tenants = keystone_client.tenants.list()
+ if is_keystone_v3():
+ tenants = keystone_client.projects.list()
+ else:
+ tenants = keystone_client.tenants.list()
return tenants
except Exception, e:
logger.error("Error [get_tenants(keystone_client)]: %s" % e)
@@ -1271,7 +1273,7 @@ def get_users(keystone_client):
def get_tenant_id(keystone_client, tenant_name):
- tenants = keystone_client.tenants.list()
+ tenants = get_tenants(keystone_client)
id = ''
for t in tenants:
if t.name == tenant_name:
@@ -1281,7 +1283,7 @@ def get_tenant_id(keystone_client, tenant_name):
def get_user_id(keystone_client, user_name):
- users = keystone_client.users.list()
+ users = get_users(keystone_client)
id = ''
for u in users:
if u.name == user_name:
@@ -1302,16 +1304,16 @@ def get_role_id(keystone_client, role_name):
def create_tenant(keystone_client, tenant_name, tenant_description):
try:
- if get_keystone_client_version() == '2':
- tenant = keystone_client.tenants.create(tenant_name,
- tenant_description,
- enabled=True)
- else:
+ if is_keystone_v3():
tenant = keystone_client.projects.create(
name=tenant_name,
description=tenant_description,
domain="default",
enabled=True)
+ else:
+ tenant = keystone_client.tenants.create(tenant_name,
+ tenant_description,
+ enabled=True)
return tenant.id
except Exception, e:
logger.error("Error [create_tenant(keystone_client, '%s', '%s')]: %s"
@@ -1322,18 +1324,18 @@ def create_tenant(keystone_client, tenant_name, tenant_description):
def create_user(keystone_client, user_name, user_password,
user_email, tenant_id):
try:
- if get_keystone_client_version() == '2':
- user = keystone_client.users.create(user_name,
- user_password,
- user_email,
- tenant_id,
- enabled=True)
- else:
+ if is_keystone_v3():
user = keystone_client.users.create(name=user_name,
password=user_password,
email=user_email,
project_id=tenant_id,
enabled=True)
+ else:
+ user = keystone_client.users.create(user_name,
+ user_password,
+ user_email,
+ tenant_id,
+ enabled=True)
return user.id
except Exception, e:
logger.error("Error [create_user(keystone_client, '%s', '%s', '%s'"
@@ -1344,7 +1346,12 @@ def create_user(keystone_client, user_name, user_password,
def add_role_user(keystone_client, user_id, role_id, tenant_id):
try:
- keystone_client.roles.add_user_role(user_id, role_id, tenant_id)
+ if is_keystone_v3():
+ keystone_client.roles.grant(role=role_id,
+ user=user_id,
+ project=tenant_id)
+ else:
+ keystone_client.roles.add_user_role(user_id, role_id, tenant_id)
return True
except Exception, e:
logger.error("Error [add_role_user(keystone_client, '%s', '%s'"
@@ -1354,10 +1361,10 @@ def add_role_user(keystone_client, user_id, role_id, tenant_id):
def delete_tenant(keystone_client, tenant_id):
try:
- if get_keystone_client_version() == '2':
- keystone_client.tenants.delete(tenant_id)
- else:
+ if is_keystone_v3():
keystone_client.projects.delete(tenant_id)
+ else:
+ keystone_client.tenants.delete(tenant_id)
return True
except Exception, e:
logger.error("Error [delete_tenant(keystone_client, '%s')]: %s"