Remove force_tenant_isolation from Cinder tests

The force_tenant_isolation flag was hard-coded to true in four of the
volume test classes. This flag, when set to true, forces Tempest to
create projects and users dynamically, which is a big problem if your
cluster has an immutable user source such as LDAP. Furthermore, if
the user wants to run these tests against a pre-defined user accounts
file, it is not possible without removing the hard-coded flag.

This change removes the hard-coded flag from the Cinder volume test
files that have it. Also, in the cases where there is a resource_setup
function defined and it changed the quota set on the primary project,
this change adds the code in resource_setup to save the original quota
values and the addClassResourceCleanup code to revert those changes
back to their original quota values, just in case the pre-provisioned
accounts (account.yaml) are used rather than dynamic credentials. And
because the AbsoluteLimitsTests class tests no longer need forced
tenant isolation, the class is changed to inherit from BaseVolumeTest
instead of BaseVolumeAdminTest, and the resource_setup() is changed
to save the current limits for comparison in the test case (for the
case where pre-provisioned account volume limits were modified from
their default values).

This change has been tested using dynamic user and project creation and
also with pre-provisioned credentials (accounts.yaml), and all tests
work both ways, depending on how its configured in etc/tempest.conf.
There are no resource leaks or quota-related side effects either way.

Closes-Bug: #1734776
Change-Id: I903be7bef81f162685ed448ba0d19901dca00bf1
This commit is contained in:
Cliff Parsons 2017-11-27 16:05:32 -06:00 committed by Cliff Parsons
parent 418a674e2a
commit c460c429f2
4 changed files with 73 additions and 39 deletions

View File

@ -13,10 +13,8 @@
# under the License.
from tempest.api.volume import base
from tempest.common import identity
from tempest.common import tempest_fixtures as fixtures
from tempest.common import waiters
from tempest.lib.common.utils import data_utils
from tempest.lib import decorators
QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes', 'backups',
@ -25,8 +23,6 @@ QUOTA_USAGE_KEYS = ['reserved', 'limit', 'in_use']
class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
force_tenant_isolation = True
credentials = ['primary', 'alt', 'admin']
def setUp(self):
@ -45,6 +41,19 @@ class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
cls.transfer_client = cls.os_primary.volume_transfers_v2_client
cls.alt_transfer_client = cls.os_alt.volume_transfers_v2_client
@classmethod
def resource_setup(cls):
super(BaseVolumeQuotasAdminTestJSON, cls).resource_setup()
# Save the current set of quotas so that some tests may use it
# to restore the quotas to their original values after they are
# done.
cls.original_quota_set = (cls.admin_quotas_client.show_quota_set(
cls.demo_tenant_id)['quota_set'])
cls.cleanup_quota_set = dict(
(k, v) for k, v in cls.original_quota_set.items()
if k in QUOTA_KEYS)
@decorators.idempotent_id('59eada70-403c-4cef-a2a3-a8ce2f1b07a0')
def test_list_quotas(self):
quotas = (self.admin_quotas_client.show_quota_set(self.demo_tenant_id)
@ -62,8 +71,6 @@ class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
@decorators.idempotent_id('3d45c99e-cc42-4424-a56e-5cbd212b63a6')
def test_update_all_quota_resources_for_tenant(self):
# Admin can update all the resource quota limits for a tenant
default_quota_set = self.admin_quotas_client.show_default_quota_set(
self.demo_tenant_id)['quota_set']
new_quota_set = {'gigabytes': 1009,
'volumes': 11,
'snapshots': 11,
@ -76,11 +83,9 @@ class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
self.demo_tenant_id,
**new_quota_set)['quota_set']
cleanup_quota_set = dict(
(k, v) for k, v in default_quota_set.items()
if k in QUOTA_KEYS)
self.addCleanup(self.admin_quotas_client.update_quota_set,
self.demo_tenant_id, **cleanup_quota_set)
self.demo_tenant_id, **self.cleanup_quota_set)
# test that the specific values we set are actually in
# the final result. There is nothing here that ensures there
# would be no other values in there.
@ -96,6 +101,25 @@ class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
for usage_key in QUOTA_USAGE_KEYS:
self.assertIn(usage_key, quota_usage[key])
@decorators.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3')
def test_delete_quota(self):
# Admin can delete the resource quota set for a project
self.addCleanup(self.admin_quotas_client.update_quota_set,
self.demo_tenant_id, **self.cleanup_quota_set)
quota_set_default = self.admin_quotas_client.show_default_quota_set(
self.demo_tenant_id)['quota_set']
volume_default = quota_set_default['volumes']
self.admin_quotas_client.update_quota_set(
self.demo_tenant_id, volumes=(volume_default + 5))
self.admin_quotas_client.delete_quota_set(self.demo_tenant_id)
quota_set_new = (self.admin_quotas_client.show_quota_set(
self.demo_tenant_id)['quota_set'])
self.assertEqual(volume_default, quota_set_new['volumes'])
@decorators.idempotent_id('ae8b6091-48ad-4bfa-a188-bbf5cc02115f')
def test_quota_usage(self):
quota_usage = self.admin_quotas_client.show_quota_set(
@ -115,28 +139,6 @@ class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
volume["size"],
new_quota_usage['gigabytes']['in_use'])
@decorators.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3')
def test_delete_quota(self):
# Admin can delete the resource quota set for a project
project_name = data_utils.rand_name('quota_tenant')
description = data_utils.rand_name('desc_')
project = identity.identity_utils(self.os_admin).create_project(
project_name, description=description)
project_id = 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(
project_id)['quota_set']
volume_default = quota_set_default['volumes']
self.admin_quotas_client.update_quota_set(
project_id, volumes=(volume_default + 5))
self.admin_quotas_client.delete_quota_set(project_id)
quota_set_new = (self.admin_quotas_client.show_quota_set(project_id)
['quota_set'])
self.assertEqual(volume_default, quota_set_new['volumes'])
@decorators.idempotent_id('8911036f-9d54-4720-80cc-a1c9796a8805')
def test_quota_usage_after_volume_transfer(self):
# Create a volume for transfer

View File

@ -19,10 +19,11 @@ from tempest.lib import decorators
from tempest.lib import exceptions as lib_exc
CONF = config.CONF
QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes', 'backups',
'backup_gigabytes', 'per_volume_gigabytes']
class BaseVolumeQuotasNegativeTestJSON(base.BaseVolumeAdminTest):
force_tenant_isolation = True
@classmethod
def setup_credentials(cls):
@ -32,11 +33,23 @@ class BaseVolumeQuotasNegativeTestJSON(base.BaseVolumeAdminTest):
@classmethod
def resource_setup(cls):
super(BaseVolumeQuotasNegativeTestJSON, cls).resource_setup()
# Save the current set of quotas, then set up the cleanup method
# to restore the quotas to their original values after the tests
# from this class are done. This is needed just in case Tempest is
# configured to use pre-provisioned projects/user accounts.
cls.original_quota_set = (cls.admin_quotas_client.show_quota_set(
cls.demo_tenant_id)['quota_set'])
cls.cleanup_quota_set = dict(
(k, v) for k, v in cls.original_quota_set.items()
if k in QUOTA_KEYS)
cls.addClassResourceCleanup(cls.admin_quotas_client.update_quota_set,
cls.demo_tenant_id,
**cls.cleanup_quota_set)
cls.shared_quota_set = {'gigabytes': 2 * CONF.volume.volume_size,
'volumes': 1}
# NOTE(gfidente): no need to restore original quota set
# after the tests as they only work with dynamic credentials.
cls.admin_quotas_client.update_quota_set(
cls.demo_tenant_id,
**cls.shared_quota_set)

View File

@ -19,10 +19,11 @@ from tempest.lib import decorators
from tempest.lib import exceptions as lib_exc
CONF = config.CONF
QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes', 'backups',
'backup_gigabytes', 'per_volume_gigabytes']
class VolumeSnapshotQuotasNegativeTestJSON(base.BaseVolumeAdminTest):
force_tenant_isolation = True
@classmethod
def skip_checks(cls):
@ -38,12 +39,24 @@ class VolumeSnapshotQuotasNegativeTestJSON(base.BaseVolumeAdminTest):
@classmethod
def resource_setup(cls):
super(VolumeSnapshotQuotasNegativeTestJSON, cls).resource_setup()
# Save the current set of quotas, then set up the cleanup method
# to restore the quotas to their original values after the tests
# from this class are done. This is needed just in case Tempest is
# configured to use pre-provisioned projects/user accounts.
cls.original_quota_set = (cls.admin_quotas_client.show_quota_set(
cls.demo_tenant_id)['quota_set'])
cls.cleanup_quota_set = dict(
(k, v) for k, v in cls.original_quota_set.items()
if k in QUOTA_KEYS)
cls.addClassResourceCleanup(cls.admin_quotas_client.update_quota_set,
cls.demo_tenant_id,
**cls.cleanup_quota_set)
cls.default_volume_size = CONF.volume.volume_size
cls.shared_quota_set = {'gigabytes': 3 * cls.default_volume_size,
'volumes': 1, 'snapshots': 1}
# NOTE(gfidente): no need to restore original quota set
# after the tests as they only work with tenant isolation.
cls.admin_quotas_client.update_quota_set(
cls.demo_tenant_id,
**cls.shared_quota_set)

View File

@ -17,7 +17,6 @@ from tempest.api.volume import base
from tempest import config
from tempest.lib import decorators
CONF = config.CONF
@ -32,9 +31,16 @@ class AbsoluteLimitsTests(base.BaseVolumeAdminTest): # noqa
@classmethod
def resource_setup(cls):
super(AbsoluteLimitsTests, cls).resource_setup()
# Create a shared volume for tests
cls.volume = cls.create_volume()
@classmethod
def skip_checks(cls):
super(AbsoluteLimitsTests, cls).skip_checks()
if not CONF.auth.use_dynamic_credentials:
raise cls.skipException("Must use dynamic credentials.")
@decorators.idempotent_id('8e943f53-e9d6-4272-b2e9-adcf2f7c29ad')
def test_get_volume_absolute_limits(self):
# get volume limit for a tenant