Merge "Remove force_tenant_isolation from Cinder tests"
diff --git a/tempest/api/volume/admin/test_volume_quotas.py b/tempest/api/volume/admin/test_volume_quotas.py
index 6f9daa8..e546bff 100644
--- a/tempest/api/volume/admin/test_volume_quotas.py
+++ b/tempest/api/volume/admin/test_volume_quotas.py
@@ -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 @@
 
 
 class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
-    force_tenant_isolation = True
-
     credentials = ['primary', 'alt', 'admin']
 
     def setUp(self):
@@ -45,6 +41,19 @@
         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 @@
     @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 @@
             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 @@
             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 @@
                          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
diff --git a/tempest/api/volume/admin/test_volume_quotas_negative.py b/tempest/api/volume/admin/test_volume_quotas_negative.py
index d127b5f..f50f336 100644
--- a/tempest/api/volume/admin/test_volume_quotas_negative.py
+++ b/tempest/api/volume/admin/test_volume_quotas_negative.py
@@ -19,10 +19,11 @@
 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 @@
     @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)
diff --git a/tempest/api/volume/admin/test_volume_snapshot_quotas_negative.py b/tempest/api/volume/admin/test_volume_snapshot_quotas_negative.py
index 0f4e90f..74eb792 100644
--- a/tempest/api/volume/admin/test_volume_snapshot_quotas_negative.py
+++ b/tempest/api/volume/admin/test_volume_snapshot_quotas_negative.py
@@ -19,10 +19,11 @@
 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 @@
     @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)
diff --git a/tempest/api/volume/test_volume_absolute_limits.py b/tempest/api/volume/test_volume_absolute_limits.py
index 4018468..00a3375 100644
--- a/tempest/api/volume/test_volume_absolute_limits.py
+++ b/tempest/api/volume/test_volume_absolute_limits.py
@@ -17,7 +17,6 @@
 from tempest import config
 from tempest.lib import decorators
 
-
 CONF = config.CONF
 
 
@@ -32,9 +31,16 @@
     @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