aboutsummaryrefslogtreecommitdiffstats
path: root/functest/utils/openstack_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'functest/utils/openstack_utils.py')
-rwxr-xr-xfunctest/utils/openstack_utils.py96
1 files changed, 66 insertions, 30 deletions
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py
index ec784121..64f18504 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
@@ -86,7 +85,7 @@ def get_env_cred_dict():
return env_cred_dict
-def get_credentials():
+def get_credentials(other_creds={}):
"""Returns a creds dictionary filled with parsed from env
"""
creds = {}
@@ -99,6 +98,16 @@ def get_credentials():
else:
creds_key = env_cred_dict.get(envvar)
creds.update({creds_key: os.getenv(envvar)})
+
+ if 'tenant' in other_creds.keys():
+ if is_keystone_v3():
+ tenant = 'project_name'
+ else:
+ tenant = 'tenant_name'
+ other_creds[tenant] = other_creds.pop('tenant')
+
+ creds.update(other_creds)
+
return creds
@@ -138,9 +147,9 @@ def get_credentials_for_rally():
return rally_conf
-def get_session_auth():
+def get_session_auth(other_creds={}):
loader = loading.get_plugin_loader('password')
- creds = get_credentials()
+ creds = get_credentials(other_creds)
auth = loader.load_from_options(**creds)
return auth
@@ -152,8 +161,8 @@ def get_endpoint(service_type, endpoint_type='publicURL'):
endpoint_type=endpoint_type)
-def get_session():
- auth = get_session_auth()
+def get_session(other_creds={}):
+ auth = get_session_auth(other_creds)
return session.Session(auth=auth)
@@ -169,8 +178,8 @@ def get_keystone_client_version():
return DEFAULT_API_VERSION
-def get_keystone_client():
- sess = get_session()
+def get_keystone_client(other_creds={}):
+ sess = get_session(other_creds)
return keystoneclient.Client(get_keystone_client_version(), session=sess)
@@ -183,8 +192,8 @@ def get_nova_client_version():
return DEFAULT_API_VERSION
-def get_nova_client():
- sess = get_session()
+def get_nova_client(other_creds={}):
+ sess = get_session(other_creds)
return novaclient.Client(get_nova_client_version(), session=sess)
@@ -197,8 +206,8 @@ def get_cinder_client_version():
return DEFAULT_API_VERSION
-def get_cinder_client():
- sess = get_session()
+def get_cinder_client(other_creds={}):
+ sess = get_session(other_creds)
return cinderclient.Client(get_cinder_client_version(), session=sess)
@@ -211,8 +220,8 @@ def get_neutron_client_version():
return DEFAULT_API_VERSION
-def get_neutron_client():
- sess = get_session()
+def get_neutron_client(other_creds={}):
+ sess = get_session(other_creds)
return neutronclient.Client(get_neutron_client_version(), session=sess)
@@ -224,8 +233,8 @@ def get_glance_client_version():
return DEFAULT_API_VERSION
-def get_glance_client():
- sess = get_session()
+def get_glance_client(other_creds={}):
+ sess = get_session(other_creds)
return glanceclient.Client(get_glance_client_version(), session=sess)
@@ -1244,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)
@@ -1261,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:
@@ -1271,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:
@@ -1292,9 +1304,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 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"
@@ -1305,9 +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:
- user = keystone_client.users.create(user_name, user_password,
- user_email, tenant_id,
- enabled=True)
+ 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'"
@@ -1318,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'"
@@ -1328,7 +1361,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 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"