Move identity_utils to common.identity
identity_utils is an helper used to obtain a cred_client object by some tempest tests; in an effort of keeping the interface in test.py to the minimum required, moving that helper to tempest.common.identity, so that it can still be used by a few tempest tests but we don't have to support it as a stable interface. Change-Id: I6692bcf2b02d3d023a1db0dd0255b17e7a869a5e
This commit is contained in:
parent
ba712ac26c
commit
e1ed695996
@ -17,6 +17,7 @@ from oslo_log import log as logging
|
|||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
|
|
||||||
from tempest.api.compute import base
|
from tempest.api.compute import base
|
||||||
|
from tempest.common import identity
|
||||||
from tempest.common import tempest_fixtures as fixtures
|
from tempest.common import tempest_fixtures as fixtures
|
||||||
from tempest.lib.common.utils import data_utils
|
from tempest.lib.common.utils import data_utils
|
||||||
from tempest.lib import decorators
|
from tempest.lib import decorators
|
||||||
@ -93,10 +94,11 @@ class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest):
|
|||||||
# Verify that GET shows the updated quota set of project
|
# Verify that GET shows the updated quota set of project
|
||||||
project_name = data_utils.rand_name('cpu_quota_project')
|
project_name = data_utils.rand_name('cpu_quota_project')
|
||||||
project_desc = project_name + '-desc'
|
project_desc = project_name + '-desc'
|
||||||
project = self.identity_utils.create_project(name=project_name,
|
project = identity.identity_utils(self.os_admin).create_project(
|
||||||
description=project_desc)
|
name=project_name, description=project_desc)
|
||||||
project_id = project['id']
|
project_id = project['id']
|
||||||
self.addCleanup(self.identity_utils.delete_project, project_id)
|
self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
|
||||||
|
project_id)
|
||||||
|
|
||||||
self.adm_client.update_quota_set(project_id, ram='5120')
|
self.adm_client.update_quota_set(project_id, ram='5120')
|
||||||
quota_set = self.adm_client.show_quota_set(project_id)['quota_set']
|
quota_set = self.adm_client.show_quota_set(project_id)['quota_set']
|
||||||
@ -106,12 +108,12 @@ class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest):
|
|||||||
user_name = data_utils.rand_name('cpu_quota_user')
|
user_name = data_utils.rand_name('cpu_quota_user')
|
||||||
password = data_utils.rand_password()
|
password = data_utils.rand_password()
|
||||||
email = user_name + '@testmail.tm'
|
email = user_name + '@testmail.tm'
|
||||||
user = self.identity_utils.create_user(username=user_name,
|
user = identity.identity_utils(self.os_admin).create_user(
|
||||||
password=password,
|
username=user_name, password=password, project=project,
|
||||||
project=project,
|
|
||||||
email=email)
|
email=email)
|
||||||
user_id = user['id']
|
user_id = user['id']
|
||||||
self.addCleanup(self.identity_utils.delete_user, user_id)
|
self.addCleanup(identity.identity_utils(self.os_admin).delete_user,
|
||||||
|
user_id)
|
||||||
|
|
||||||
self.adm_client.update_quota_set(project_id,
|
self.adm_client.update_quota_set(project_id,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
@ -125,10 +127,11 @@ class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest):
|
|||||||
# Admin can delete the resource quota set for a project
|
# Admin can delete the resource quota set for a project
|
||||||
project_name = data_utils.rand_name('ram_quota_project')
|
project_name = data_utils.rand_name('ram_quota_project')
|
||||||
project_desc = project_name + '-desc'
|
project_desc = project_name + '-desc'
|
||||||
project = self.identity_utils.create_project(name=project_name,
|
project = identity.identity_utils(self.os_admin).create_project(
|
||||||
description=project_desc)
|
name=project_name, description=project_desc)
|
||||||
project_id = project['id']
|
project_id = project['id']
|
||||||
self.addCleanup(self.identity_utils.delete_project, project_id)
|
self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
|
||||||
|
project_id)
|
||||||
quota_set_default = (self.adm_client.show_quota_set(project_id)
|
quota_set_default = (self.adm_client.show_quota_set(project_id)
|
||||||
['quota_set'])
|
['quota_set'])
|
||||||
ram_default = quota_set_default['ram']
|
ram_default = quota_set_default['ram']
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from tempest.api.network import base
|
from tempest.api.network import base
|
||||||
|
from tempest.common import identity
|
||||||
from tempest.common import utils
|
from tempest.common import utils
|
||||||
from tempest.lib.common.utils import data_utils
|
from tempest.lib.common.utils import data_utils
|
||||||
from tempest.lib.common.utils import test_utils
|
from tempest.lib.common.utils import test_utils
|
||||||
@ -46,10 +47,11 @@ class QuotasTest(base.BaseAdminNetworkTest):
|
|||||||
# Add a project to conduct the test
|
# Add a project to conduct the test
|
||||||
project = data_utils.rand_name('test_project_')
|
project = data_utils.rand_name('test_project_')
|
||||||
description = data_utils.rand_name('desc_')
|
description = data_utils.rand_name('desc_')
|
||||||
project = self.identity_utils.create_project(name=project,
|
project = identity.identity_utils(self.os_admin).create_project(
|
||||||
description=description)
|
name=project, description=description)
|
||||||
project_id = project['id']
|
project_id = project['id']
|
||||||
self.addCleanup(self.identity_utils.delete_project, project_id)
|
self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
|
||||||
|
project_id)
|
||||||
|
|
||||||
# Change quotas for project
|
# Change quotas for project
|
||||||
quota_set = self.admin_quotas_client.update_quotas(
|
quota_set = self.admin_quotas_client.update_quotas(
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from tempest.api.network import base
|
from tempest.api.network import base
|
||||||
|
from tempest.common import identity
|
||||||
from tempest.common import utils
|
from tempest.common import utils
|
||||||
from tempest import config
|
from tempest import config
|
||||||
from tempest.lib.common.utils import data_utils
|
from tempest.lib.common.utils import data_utils
|
||||||
@ -66,10 +67,11 @@ class RoutersAdminTest(base.BaseAdminNetworkTest):
|
|||||||
# Test creating router from admin user setting project_id.
|
# Test creating router from admin user setting project_id.
|
||||||
project = data_utils.rand_name('test_tenant_')
|
project = data_utils.rand_name('test_tenant_')
|
||||||
description = data_utils.rand_name('desc_')
|
description = data_utils.rand_name('desc_')
|
||||||
project = self.identity_utils.create_project(name=project,
|
project = identity.identity_utils(self.os_admin).create_project(
|
||||||
description=description)
|
name=project, description=description)
|
||||||
project_id = project['id']
|
project_id = project['id']
|
||||||
self.addCleanup(self.identity_utils.delete_project, project_id)
|
self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
|
||||||
|
project_id)
|
||||||
|
|
||||||
name = data_utils.rand_name('router-')
|
name = data_utils.rand_name('router-')
|
||||||
create_body = self.admin_routers_client.create_router(
|
create_body = self.admin_routers_client.create_router(
|
||||||
|
@ -19,6 +19,7 @@ from oslo_log import log as logging
|
|||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
|
|
||||||
from tempest.api.volume import base
|
from tempest.api.volume import base
|
||||||
|
from tempest.common import identity
|
||||||
from tempest.common import tempest_fixtures as fixtures
|
from tempest.common import tempest_fixtures as fixtures
|
||||||
from tempest.lib.common.utils import data_utils
|
from tempest.lib.common.utils import data_utils
|
||||||
from tempest.lib import decorators
|
from tempest.lib import decorators
|
||||||
@ -92,9 +93,10 @@ class VolumeQuotaClassesTest(base.BaseVolumeAdminTest):
|
|||||||
# Verify a new project's default quotas.
|
# Verify a new project's default quotas.
|
||||||
project_name = data_utils.rand_name('quota_class_tenant')
|
project_name = data_utils.rand_name('quota_class_tenant')
|
||||||
description = data_utils.rand_name('desc_')
|
description = data_utils.rand_name('desc_')
|
||||||
project_id = self.identity_utils.create_project(
|
project_id = identity.identity_utils(self.os_admin).create_project(
|
||||||
name=project_name, description=description)['id']
|
name=project_name, description=description)['id']
|
||||||
self.addCleanup(self.identity_utils.delete_project, project_id)
|
self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
|
||||||
|
project_id)
|
||||||
default_quotas = self.admin_quotas_client.show_default_quota_set(
|
default_quotas = self.admin_quotas_client.show_default_quota_set(
|
||||||
project_id)['quota_set']
|
project_id)['quota_set']
|
||||||
self.assertThat(default_quotas.items(),
|
self.assertThat(default_quotas.items(),
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from tempest.api.volume import base
|
from tempest.api.volume import base
|
||||||
|
from tempest.common import identity
|
||||||
from tempest.common import tempest_fixtures as fixtures
|
from tempest.common import tempest_fixtures as fixtures
|
||||||
from tempest.common import waiters
|
from tempest.common import waiters
|
||||||
from tempest.lib.common.utils import data_utils
|
from tempest.lib.common.utils import data_utils
|
||||||
@ -117,10 +118,11 @@ class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
|
|||||||
# Admin can delete the resource quota set for a project
|
# Admin can delete the resource quota set for a project
|
||||||
project_name = data_utils.rand_name('quota_tenant')
|
project_name = data_utils.rand_name('quota_tenant')
|
||||||
description = data_utils.rand_name('desc_')
|
description = data_utils.rand_name('desc_')
|
||||||
project = self.identity_utils.create_project(project_name,
|
project = identity.identity_utils(self.os_admin).create_project(
|
||||||
description=description)
|
project_name, description=description)
|
||||||
project_id = project['id']
|
project_id = project['id']
|
||||||
self.addCleanup(self.identity_utils.delete_project, project_id)
|
self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
|
||||||
|
project_id)
|
||||||
quota_set_default = self.admin_quotas_client.show_default_quota_set(
|
quota_set_default = self.admin_quotas_client.show_default_quota_set(
|
||||||
project_id)['quota_set']
|
project_id)['quota_set']
|
||||||
volume_default = quota_set_default['volumes']
|
volume_default = quota_set_default['volumes']
|
||||||
|
@ -13,8 +13,12 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from tempest import config
|
||||||
|
from tempest.lib.common import cred_client
|
||||||
from tempest.lib import exceptions as lib_exc
|
from tempest.lib import exceptions as lib_exc
|
||||||
|
|
||||||
|
CONF = config.CONF
|
||||||
|
|
||||||
|
|
||||||
def get_tenant_by_name(client, tenant_name):
|
def get_tenant_by_name(client, tenant_name):
|
||||||
tenants = client.list_tenants()['tenants']
|
tenants = client.list_tenants()['tenants']
|
||||||
@ -30,3 +34,37 @@ def get_user_by_username(client, tenant_id, username):
|
|||||||
if user['name'] == username:
|
if user['name'] == username:
|
||||||
return user
|
return user
|
||||||
raise lib_exc.NotFound('No such user(%s) in %s' % (username, users))
|
raise lib_exc.NotFound('No such user(%s) in %s' % (username, users))
|
||||||
|
|
||||||
|
|
||||||
|
def identity_utils(clients):
|
||||||
|
"""A client that abstracts v2 and v3 identity operations.
|
||||||
|
|
||||||
|
This can be used for creating and tearing down projects in tests. It
|
||||||
|
should not be used for testing identity features.
|
||||||
|
|
||||||
|
:param clients: a client manager.
|
||||||
|
:return
|
||||||
|
"""
|
||||||
|
if CONF.identity.auth_version == 'v2':
|
||||||
|
client = clients.identity_client
|
||||||
|
users_client = clients.users_client
|
||||||
|
project_client = clients.tenants_client
|
||||||
|
roles_client = clients.roles_client
|
||||||
|
domains_client = None
|
||||||
|
else:
|
||||||
|
client = clients.identity_v3_client
|
||||||
|
users_client = clients.users_v3_client
|
||||||
|
project_client = clients.projects_client
|
||||||
|
roles_client = clients.roles_v3_client
|
||||||
|
domains_client = clients.domains_client
|
||||||
|
|
||||||
|
try:
|
||||||
|
domain = client.auth_provider.credentials.project_domain_name
|
||||||
|
except AttributeError:
|
||||||
|
domain = CONF.auth.default_credentials_domain_name
|
||||||
|
|
||||||
|
return cred_client.get_creds_client(client, project_client,
|
||||||
|
users_client,
|
||||||
|
roles_client,
|
||||||
|
domains_client,
|
||||||
|
project_domain_name=domain)
|
||||||
|
@ -27,7 +27,6 @@ from tempest import clients
|
|||||||
from tempest.common import credentials_factory as credentials
|
from tempest.common import credentials_factory as credentials
|
||||||
from tempest.common import utils
|
from tempest.common import utils
|
||||||
from tempest import config
|
from tempest import config
|
||||||
from tempest.lib.common import cred_client
|
|
||||||
from tempest.lib.common import fixed_network
|
from tempest.lib.common import fixed_network
|
||||||
from tempest.lib.common import validation_resources as vr
|
from tempest.lib.common import validation_resources as vr
|
||||||
from tempest.lib import decorators
|
from tempest.lib import decorators
|
||||||
@ -612,37 +611,6 @@ class BaseTestCase(testtools.testcase.WithAttributes,
|
|||||||
def credentials_provider(self):
|
def credentials_provider(self):
|
||||||
return self._get_credentials_provider()
|
return self._get_credentials_provider()
|
||||||
|
|
||||||
@property
|
|
||||||
def identity_utils(self):
|
|
||||||
"""A client that abstracts v2 and v3 identity operations.
|
|
||||||
|
|
||||||
This can be used for creating and tearing down projects in tests. It
|
|
||||||
should not be used for testing identity features.
|
|
||||||
"""
|
|
||||||
if CONF.identity.auth_version == 'v2':
|
|
||||||
client = self.os_admin.identity_client
|
|
||||||
users_client = self.os_admin.users_client
|
|
||||||
project_client = self.os_admin.tenants_client
|
|
||||||
roles_client = self.os_admin.roles_client
|
|
||||||
domains_client = None
|
|
||||||
else:
|
|
||||||
client = self.os_admin.identity_v3_client
|
|
||||||
users_client = self.os_admin.users_v3_client
|
|
||||||
project_client = self.os_admin.projects_client
|
|
||||||
roles_client = self.os_admin.roles_v3_client
|
|
||||||
domains_client = self.os_admin.domains_client
|
|
||||||
|
|
||||||
try:
|
|
||||||
domain = client.auth_provider.credentials.project_domain_name
|
|
||||||
except AttributeError:
|
|
||||||
domain = 'Default'
|
|
||||||
|
|
||||||
return cred_client.get_creds_client(client, project_client,
|
|
||||||
users_client,
|
|
||||||
roles_client,
|
|
||||||
domains_client,
|
|
||||||
project_domain_name=domain)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_identity_version(cls):
|
def get_identity_version(cls):
|
||||||
"""Returns the identity version used by the test class"""
|
"""Returns the identity version used by the test class"""
|
||||||
|
Loading…
Reference in New Issue
Block a user