Split resource_setup for volume tests

Split up the resource_setup method for all the volume tests, as per the
latest spec.

Partially-implements bp:resource-cleanup

Change-Id: I37a0a3a66a99d00e72a788d7e45d5e85475944d9
diff --git a/tempest/api/volume/admin/test_multi_backend.py b/tempest/api/volume/admin/test_multi_backend.py
index 245161a..32cdb01 100644
--- a/tempest/api/volume/admin/test_multi_backend.py
+++ b/tempest/api/volume/admin/test_multi_backend.py
@@ -24,11 +24,16 @@
 class VolumeMultiBackendV2Test(base.BaseVolumeAdminTest):
 
     @classmethod
-    def resource_setup(cls):
-        super(VolumeMultiBackendV2Test, cls).resource_setup()
+    def skip_checks(cls):
+        super(VolumeMultiBackendV2Test, cls).skip_checks()
+
         if not CONF.volume_feature_enabled.multi_backend:
             raise cls.skipException("Cinder multi-backend feature disabled")
 
+    @classmethod
+    def resource_setup(cls):
+        super(VolumeMultiBackendV2Test, cls).resource_setup()
+
         cls.backend1_name = CONF.volume.backend1_name
         cls.backend2_name = CONF.volume.backend2_name
 
diff --git a/tempest/api/volume/admin/test_snapshots_actions.py b/tempest/api/volume/admin/test_snapshots_actions.py
index e7d9d7b..a4b4e3e 100644
--- a/tempest/api/volume/admin/test_snapshots_actions.py
+++ b/tempest/api/volume/admin/test_snapshots_actions.py
@@ -21,9 +21,13 @@
 class SnapshotsActionsV2Test(base.BaseVolumeAdminTest):
 
     @classmethod
+    def setup_clients(cls):
+        super(SnapshotsActionsV2Test, cls).setup_clients()
+        cls.client = cls.snapshots_client
+
+    @classmethod
     def resource_setup(cls):
         super(SnapshotsActionsV2Test, cls).resource_setup()
-        cls.client = cls.snapshots_client
 
         # Create a test shared volume for tests
         vol_name = data_utils.rand_name(cls.__name__ + '-Volume-')
diff --git a/tempest/api/volume/admin/test_volume_quotas.py b/tempest/api/volume/admin/test_volume_quotas.py
index 2a30b54..f41a97e 100644
--- a/tempest/api/volume/admin/test_volume_quotas.py
+++ b/tempest/api/volume/admin/test_volume_quotas.py
@@ -26,8 +26,8 @@
     force_tenant_isolation = True
 
     @classmethod
-    def resource_setup(cls):
-        super(BaseVolumeQuotasAdminV2TestJSON, cls).resource_setup()
+    def setup_credentials(cls):
+        super(BaseVolumeQuotasAdminV2TestJSON, cls).setup_credentials()
         cls.demo_tenant_id = cls.isolated_creds.get_primary_creds().tenant_id
 
     @test.attr(type='gate')
diff --git a/tempest/api/volume/admin/test_volume_quotas_negative.py b/tempest/api/volume/admin/test_volume_quotas_negative.py
index f972457..e37d8f2 100644
--- a/tempest/api/volume/admin/test_volume_quotas_negative.py
+++ b/tempest/api/volume/admin/test_volume_quotas_negative.py
@@ -23,10 +23,14 @@
     force_tenant_isolation = True
 
     @classmethod
+    def setup_credentials(cls):
+        super(BaseVolumeQuotasNegativeV2TestJSON, cls).setup_credentials()
+        cls.demo_user = cls.isolated_creds.get_primary_creds()
+        cls.demo_tenant_id = cls.demo_user.tenant_id
+
+    @classmethod
     def resource_setup(cls):
         super(BaseVolumeQuotasNegativeV2TestJSON, cls).resource_setup()
-        demo_user = cls.isolated_creds.get_primary_creds()
-        cls.demo_tenant_id = demo_user.tenant_id
         cls.shared_quota_set = {'gigabytes': 3, 'volumes': 1, 'snapshots': 1}
 
         # NOTE(gfidente): no need to restore original quota set
diff --git a/tempest/api/volume/admin/test_volumes_actions.py b/tempest/api/volume/admin/test_volumes_actions.py
index 439dd35..fb16872 100644
--- a/tempest/api/volume/admin/test_volumes_actions.py
+++ b/tempest/api/volume/admin/test_volumes_actions.py
@@ -21,9 +21,13 @@
 class VolumesActionsV2Test(base.BaseVolumeAdminTest):
 
     @classmethod
+    def setup_clients(cls):
+        super(VolumesActionsV2Test, cls).setup_clients()
+        cls.client = cls.volumes_client
+
+    @classmethod
     def resource_setup(cls):
         super(VolumesActionsV2Test, cls).resource_setup()
-        cls.client = cls.volumes_client
 
         # Create a test shared volume for tests
         vol_name = utils.rand_name(cls.__name__ + '-Volume-')
diff --git a/tempest/api/volume/admin/test_volumes_backup.py b/tempest/api/volume/admin/test_volumes_backup.py
index d572893..4db9f7e 100644
--- a/tempest/api/volume/admin/test_volumes_backup.py
+++ b/tempest/api/volume/admin/test_volumes_backup.py
@@ -26,12 +26,15 @@
 class VolumesBackupsV2Test(base.BaseVolumeAdminTest):
 
     @classmethod
-    def resource_setup(cls):
-        super(VolumesBackupsV2Test, cls).resource_setup()
-
+    def skip_checks(cls):
+        super(VolumesBackupsV2Test, cls).skip_checks()
         if not CONF.volume_feature_enabled.backup:
             raise cls.skipException("Cinder backup feature disabled")
 
+    @classmethod
+    def resource_setup(cls):
+        super(VolumesBackupsV2Test, cls).resource_setup()
+
         cls.volume = cls.create_volume()
 
     @test.attr(type='smoke')
diff --git a/tempest/api/volume/base.py b/tempest/api/volume/base.py
index 2489b79..c672607 100644
--- a/tempest/api/volume/base.py
+++ b/tempest/api/volume/base.py
@@ -33,28 +33,37 @@
     _api_version = 2
 
     @classmethod
-    def resource_setup(cls):
-        cls.set_network_resources()
-        super(BaseVolumeTest, cls).resource_setup()
+    def skip_checks(cls):
+        super(BaseVolumeTest, cls).skip_checks()
 
         if not CONF.service_available.cinder:
             skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
             raise cls.skipException(skip_msg)
-
-        cls.os = cls.get_client_manager()
-
-        cls.servers_client = cls.os.servers_client
-        cls.image_ref = CONF.compute.image_ref
-        cls.flavor_ref = CONF.compute.flavor_ref
-        cls.build_interval = CONF.volume.build_interval
-        cls.build_timeout = CONF.volume.build_timeout
-        cls.snapshots = []
-        cls.volumes = []
-
         if cls._api_version == 1:
             if not CONF.volume_feature_enabled.api_v1:
                 msg = "Volume API v1 is disabled"
                 raise cls.skipException(msg)
+        elif cls._api_version == 2:
+            if not CONF.volume_feature_enabled.api_v2:
+                msg = "Volume API v2 is disabled"
+                raise cls.skipException(msg)
+        else:
+            msg = ("Invalid Cinder API version (%s)" % cls._api_version)
+            raise exceptions.InvalidConfiguration(message=msg)
+
+    @classmethod
+    def setup_credentials(cls):
+        cls.set_network_resources()
+        super(BaseVolumeTest, cls).setup_credentials()
+        cls.os = cls.get_client_manager()
+
+    @classmethod
+    def setup_clients(cls):
+        super(BaseVolumeTest, cls).setup_clients()
+
+        cls.servers_client = cls.os.servers_client
+
+        if cls._api_version == 1:
             cls.snapshots_client = cls.os.snapshots_client
             cls.volumes_client = cls.os.volumes_client
             cls.backups_client = cls.os.backups_client
@@ -62,27 +71,33 @@
             cls.volumes_extension_client = cls.os.volumes_extension_client
             cls.availability_zone_client = (
                 cls.os.volume_availability_zone_client)
-            # Special fields and resp code for cinder v1
-            cls.special_fields = {'name_field': 'display_name',
-                                  'descrip_field': 'display_description'}
-
-        elif cls._api_version == 2:
-            if not CONF.volume_feature_enabled.api_v2:
-                msg = "Volume API v2 is disabled"
-                raise cls.skipException(msg)
+        else:
             cls.snapshots_client = cls.os.snapshots_v2_client
             cls.volumes_client = cls.os.volumes_v2_client
             cls.volumes_extension_client = cls.os.volumes_v2_extension_client
             cls.availability_zone_client = (
                 cls.os.volume_v2_availability_zone_client)
+
+    @classmethod
+    def resource_setup(cls):
+        super(BaseVolumeTest, cls).resource_setup()
+
+        cls.snapshots = []
+        cls.volumes = []
+        cls.image_ref = CONF.compute.image_ref
+        cls.flavor_ref = CONF.compute.flavor_ref
+        cls.build_interval = CONF.volume.build_interval
+        cls.build_timeout = CONF.volume.build_timeout
+
+        if cls._api_version == 1:
+            # Special fields and resp code for cinder v1
+            cls.special_fields = {'name_field': 'display_name',
+                                  'descrip_field': 'display_description'}
+        else:
             # Special fields and resp code for cinder v2
             cls.special_fields = {'name_field': 'name',
                                   'descrip_field': 'description'}
 
-        else:
-            msg = ("Invalid Cinder API version (%s)" % cls._api_version)
-            raise exceptions.InvalidConfiguration(message=msg)
-
     @classmethod
     def resource_cleanup(cls):
         cls.clear_snapshots()
@@ -148,10 +163,10 @@
 
 class BaseVolumeAdminTest(BaseVolumeTest):
     """Base test case class for all Volume Admin API tests."""
-    @classmethod
-    def resource_setup(cls):
-        super(BaseVolumeAdminTest, cls).resource_setup()
 
+    @classmethod
+    def setup_credentials(cls):
+        super(BaseVolumeAdminTest, cls).setup_credentials()
         try:
             cls.adm_creds = cls.isolated_creds.get_admin_creds()
             cls.os_adm = clients.Manager(credentials=cls.adm_creds)
@@ -159,12 +174,11 @@
             msg = "Missing Volume Admin API credentials in configuration."
             raise cls.skipException(msg)
 
-        cls.qos_specs = []
+    @classmethod
+    def setup_clients(cls):
+        super(BaseVolumeAdminTest, cls).setup_clients()
 
         if cls._api_version == 1:
-            if not CONF.volume_feature_enabled.api_v1:
-                msg = "Volume API v1 is disabled"
-                raise cls.skipException(msg)
             cls.volume_qos_client = cls.os_adm.volume_qos_client
             cls.admin_volume_services_client = \
                 cls.os_adm.volume_services_client
@@ -175,9 +189,6 @@
             cls.backups_adm_client = cls.os_adm.backups_client
             cls.quotas_client = cls.os_adm.volume_quotas_client
         elif cls._api_version == 2:
-            if not CONF.volume_feature_enabled.api_v2:
-                msg = "Volume API v2 is disabled"
-                raise cls.skipException(msg)
             cls.volume_qos_client = cls.os_adm.volume_qos_v2_client
             cls.admin_volume_services_client = \
                 cls.os_adm.volume_services_v2_client
@@ -189,6 +200,12 @@
             cls.quotas_client = cls.os_adm.volume_quotas_v2_client
 
     @classmethod
+    def resource_setup(cls):
+        super(BaseVolumeAdminTest, cls).resource_setup()
+
+        cls.qos_specs = []
+
+    @classmethod
     def resource_cleanup(cls):
         cls.clear_qos_specs()
         super(BaseVolumeAdminTest, cls).resource_cleanup()
diff --git a/tempest/api/volume/test_availability_zone.py b/tempest/api/volume/test_availability_zone.py
index bd3d2a1..b6e226d 100644
--- a/tempest/api/volume/test_availability_zone.py
+++ b/tempest/api/volume/test_availability_zone.py
@@ -24,8 +24,8 @@
     """
 
     @classmethod
-    def resource_setup(cls):
-        super(AvailabilityZoneV2TestJSON, cls).resource_setup()
+    def setup_clients(cls):
+        super(AvailabilityZoneV2TestJSON, cls).setup_clients()
         cls.client = cls.availability_zone_client
 
     @test.attr(type='gate')
diff --git a/tempest/api/volume/test_snapshot_metadata.py b/tempest/api/volume/test_snapshot_metadata.py
index 03474ba..e1fe779 100644
--- a/tempest/api/volume/test_snapshot_metadata.py
+++ b/tempest/api/volume/test_snapshot_metadata.py
@@ -20,9 +20,13 @@
 class SnapshotV2MetadataTestJSON(base.BaseVolumeTest):
 
     @classmethod
+    def setup_clients(cls):
+        super(SnapshotV2MetadataTestJSON, cls).setup_clients()
+        cls.client = cls.snapshots_client
+
+    @classmethod
     def resource_setup(cls):
         super(SnapshotV2MetadataTestJSON, cls).resource_setup()
-        cls.client = cls.snapshots_client
         # Create a volume
         cls.volume = cls.create_volume()
         # Create a snapshot
diff --git a/tempest/api/volume/test_volume_transfers.py b/tempest/api/volume/test_volume_transfers.py
index 7451050..6f75403 100644
--- a/tempest/api/volume/test_volume_transfers.py
+++ b/tempest/api/volume/test_volume_transfers.py
@@ -17,6 +17,7 @@
 
 from tempest.api.volume import base
 from tempest import clients
+from tempest.common import credentials
 from tempest import config
 from tempest import test
 
@@ -26,18 +27,24 @@
 class VolumesV2TransfersTest(base.BaseVolumeTest):
 
     @classmethod
-    def resource_setup(cls):
-        super(VolumesV2TransfersTest, cls).resource_setup()
+    def skip_checks(cls):
+        super(VolumesV2TransfersTest, cls).skip_checks()
+        if not credentials.is_admin_available():
+            msg = "Missing Volume Admin API credentials in configuration."
+            raise cls.skipException(msg)
 
+    @classmethod
+    def setup_credentials(cls):
+        super(VolumesV2TransfersTest, cls).setup_credentials()
         # Add another tenant to test volume-transfer
         cls.os_alt = clients.Manager(cls.isolated_creds.get_alt_creds())
         # Add admin tenant to cleanup resources
-        try:
-            creds = cls.isolated_creds.get_admin_creds()
-            cls.os_adm = clients.Manager(credentials=creds)
-        except NotImplementedError:
-            msg = "Missing Volume Admin API credentials in configuration."
-            raise cls.skipException(msg)
+        creds = cls.isolated_creds.get_admin_creds()
+        cls.os_adm = clients.Manager(credentials=creds)
+
+    @classmethod
+    def setup_clients(cls):
+        super(VolumesV2TransfersTest, cls).setup_clients()
 
         cls.client = cls.volumes_client
         cls.alt_client = cls.os_alt.volumes_client
diff --git a/tempest/api/volume/test_volumes_actions.py b/tempest/api/volume/test_volumes_actions.py
index 333a4f7..e5f7aa4 100644
--- a/tempest/api/volume/test_volumes_actions.py
+++ b/tempest/api/volume/test_volumes_actions.py
@@ -24,11 +24,15 @@
 class VolumesV2ActionsTest(base.BaseVolumeTest):
 
     @classmethod
-    def resource_setup(cls):
-        super(VolumesV2ActionsTest, cls).resource_setup()
+    def setup_clients(cls):
+        super(VolumesV2ActionsTest, cls).setup_clients()
         cls.client = cls.volumes_client
         cls.image_client = cls.os.image_client
 
+    @classmethod
+    def resource_setup(cls):
+        super(VolumesV2ActionsTest, cls).resource_setup()
+
         # Create a test shared instance
         srv_name = data_utils.rand_name(cls.__name__ + '-Instance-')
         cls.server = cls.servers_client.create_server(srv_name,
diff --git a/tempest/api/volume/test_volumes_extend.py b/tempest/api/volume/test_volumes_extend.py
index ebe6084..fab25ec 100644
--- a/tempest/api/volume/test_volumes_extend.py
+++ b/tempest/api/volume/test_volumes_extend.py
@@ -23,8 +23,8 @@
 class VolumesV2ExtendTest(base.BaseVolumeTest):
 
     @classmethod
-    def resource_setup(cls):
-        super(VolumesV2ExtendTest, cls).resource_setup()
+    def setup_clients(cls):
+        super(VolumesV2ExtendTest, cls).setup_clients()
         cls.client = cls.volumes_client
 
     @test.attr(type='gate')
diff --git a/tempest/api/volume/test_volumes_get.py b/tempest/api/volume/test_volumes_get.py
index 2a49210..3133df4 100644
--- a/tempest/api/volume/test_volumes_get.py
+++ b/tempest/api/volume/test_volumes_get.py
@@ -26,9 +26,13 @@
 class VolumesV2GetTest(base.BaseVolumeTest):
 
     @classmethod
+    def setup_clients(cls):
+        super(VolumesV2GetTest, cls).setup_clients()
+        cls.client = cls.volumes_client
+
+    @classmethod
     def resource_setup(cls):
         super(VolumesV2GetTest, cls).resource_setup()
-        cls.client = cls.volumes_client
 
         cls.name_field = cls.special_fields['name_field']
         cls.descrip_field = cls.special_fields['descrip_field']
diff --git a/tempest/api/volume/test_volumes_list.py b/tempest/api/volume/test_volumes_list.py
index 91beae9..9a8746a 100644
--- a/tempest/api/volume/test_volumes_list.py
+++ b/tempest/api/volume/test_volumes_list.py
@@ -55,9 +55,13 @@
                              [str_vol(v) for v in fetched_list]))
 
     @classmethod
+    def setup_clients(cls):
+        super(VolumesV2ListTestJSON, cls).setup_clients()
+        cls.client = cls.volumes_client
+
+    @classmethod
     def resource_setup(cls):
         super(VolumesV2ListTestJSON, cls).resource_setup()
-        cls.client = cls.volumes_client
         cls.name = cls.VOLUME_FIELDS[1]
 
         # Create 3 test volumes
diff --git a/tempest/api/volume/test_volumes_negative.py b/tempest/api/volume/test_volumes_negative.py
index 595ddf4..c827f9e 100644
--- a/tempest/api/volume/test_volumes_negative.py
+++ b/tempest/api/volume/test_volumes_negative.py
@@ -25,9 +25,13 @@
 class VolumesV2NegativeTest(base.BaseVolumeTest):
 
     @classmethod
+    def setup_clients(cls):
+        super(VolumesV2NegativeTest, cls).setup_clients()
+        cls.client = cls.volumes_client
+
+    @classmethod
     def resource_setup(cls):
         super(VolumesV2NegativeTest, cls).resource_setup()
-        cls.client = cls.volumes_client
 
         cls.name_field = cls.special_fields['name_field']
 
diff --git a/tempest/api/volume/test_volumes_snapshots.py b/tempest/api/volume/test_volumes_snapshots.py
index 98598c1..c4f8096 100644
--- a/tempest/api/volume/test_volumes_snapshots.py
+++ b/tempest/api/volume/test_volumes_snapshots.py
@@ -23,13 +23,16 @@
 class VolumesV2SnapshotTestJSON(base.BaseVolumeTest):
 
     @classmethod
+    def skip_checks(cls):
+        super(VolumesV2SnapshotTestJSON, cls).skip_checks()
+        if not CONF.volume_feature_enabled.snapshot:
+            raise cls.skipException("Cinder volume snapshots are disabled")
+
+    @classmethod
     def resource_setup(cls):
         super(VolumesV2SnapshotTestJSON, cls).resource_setup()
         cls.volume_origin = cls.create_volume()
 
-        if not CONF.volume_feature_enabled.snapshot:
-            raise cls.skipException("Cinder volume snapshots are disabled")
-
         cls.name_field = cls.special_fields['name_field']
         cls.descrip_field = cls.special_fields['descrip_field']
 
diff --git a/tempest/api/volume/test_volumes_snapshots_negative.py b/tempest/api/volume/test_volumes_snapshots_negative.py
index 8b68ea9..3ad23f7 100644
--- a/tempest/api/volume/test_volumes_snapshots_negative.py
+++ b/tempest/api/volume/test_volumes_snapshots_negative.py
@@ -25,9 +25,8 @@
 class VolumesV2SnapshotNegativeTestJSON(base.BaseVolumeTest):
 
     @classmethod
-    def resource_setup(cls):
-        super(VolumesV2SnapshotNegativeTestJSON, cls).resource_setup()
-
+    def skip_checks(cls):
+        super(VolumesV2SnapshotNegativeTestJSON, cls).skip_checks()
         if not CONF.volume_feature_enabled.snapshot:
             raise cls.skipException("Cinder volume snapshots are disabled")
 
diff --git a/tempest/api/volume/v2/test_volumes_list.py b/tempest/api/volume/v2/test_volumes_list.py
index bc14b2c..3a21f41 100644
--- a/tempest/api/volume/v2/test_volumes_list.py
+++ b/tempest/api/volume/v2/test_volumes_list.py
@@ -31,9 +31,13 @@
     """
 
     @classmethod
+    def setup_clients(cls):
+        super(VolumesV2ListTestJSON, cls).setup_clients()
+        cls.client = cls.volumes_client
+
+    @classmethod
     def resource_setup(cls):
         super(VolumesV2ListTestJSON, cls).resource_setup()
-        cls.client = cls.volumes_client
 
         # Create 3 test volumes
         cls.volume_list = []