Add isolated tenants for admin compute tests
This adds support for isolated credentials on admin tests. Previously
the admin tests just ran with the admin username, password, and
tenant from the config file. This changes that behavior by getting
isolated credentials for the admin base test class and then adding
the create user to the admin role.
This may fix a race condition uncovered by the testr runs.
Possibly part of: bp speed-up-tempest
Change-Id: I74339662ab769e005cb79b2d741a04640c5546ce
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index 095be7c..a38dcd1 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -101,7 +101,7 @@
)
@classmethod
- def _get_isolated_creds(cls):
+ def _get_isolated_creds(cls, admin=False):
"""
Creates a new set of user/tenant/password credentials for a
**regular** user of the Compute API so that a test case can
@@ -152,6 +152,18 @@
# that the various clients will use.
cls.isolated_creds.append((user, tenant))
+ # Assign admin role if this is for admin creds
+ if admin:
+ _, roles = admin_client.list_roles()
+ role = None
+ try:
+ _, roles = admin_client.list_roles()
+ role = next(r for r in roles if r['name'] == 'admin')
+ except StopIteration:
+ msg = "No admin role found"
+ raise exceptions.NotFound(msg)
+ admin_client.assign_user_role(tenant['id'], user['id'], role['id'])
+
return username, tenant_name, password
@classmethod
@@ -266,10 +278,16 @@
admin_username = cls.config.compute_admin.username
admin_password = cls.config.compute_admin.password
admin_tenant = cls.config.compute_admin.tenant_name
-
if not (admin_username and admin_password and admin_tenant):
msg = ("Missing Compute Admin API credentials "
"in configuration.")
raise cls.skipException(msg)
-
- cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
+ if cls.config.compute.allow_tenant_isolation:
+ creds = cls._get_isolated_creds(admin=True)
+ admin_username, admin_tenant_name, admin_password = creds
+ cls.os_adm = clients.Manager(username=admin_username,
+ password=admin_password,
+ tenant_name=admin_tenant_name,
+ interface=cls._interface)
+ else:
+ cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)