Merge "Skip some tests when cinder is not enabled"
diff --git a/tempest/api/compute/servers/test_delete_server.py b/tempest/api/compute/servers/test_delete_server.py
index 6a5da58..55931a4 100644
--- a/tempest/api/compute/servers/test_delete_server.py
+++ b/tempest/api/compute/servers/test_delete_server.py
@@ -116,6 +116,7 @@
         self.assertEqual('204', resp['status'])
         self.client.wait_for_server_termination(server['id'])
 
+    @test.services('volume')
     @test.attr(type='gate')
     def test_delete_server_while_in_attached_volume(self):
         # Delete a server while a volume is attached to it
diff --git a/tempest/api/compute/servers/test_server_rescue.py b/tempest/api/compute/servers/test_server_rescue.py
index a984ade..5986f41 100644
--- a/tempest/api/compute/servers/test_server_rescue.py
+++ b/tempest/api/compute/servers/test_server_rescue.py
@@ -45,12 +45,6 @@
                                                              cls.sg_desc)
         cls.sg_id = cls.sg['id']
 
-        # Create a volume and wait for it to become ready for attach
-        resp, cls.volume = cls.volumes_extensions_client.create_volume(
-            1, display_name=data_utils.rand_name(cls.__name__ + '_volume'))
-        cls.volumes_extensions_client.wait_for_volume_status(
-            cls.volume['id'], 'available')
-
         # Server for positive tests
         resp, server = cls.create_test_server(wait_until='BUILD')
         cls.server_id = server['id']
@@ -64,8 +58,6 @@
     def resource_cleanup(cls):
         # Deleting the floating IP which is created in this method
         cls.floating_ips_client.delete_floating_ip(cls.floating_ip_id)
-        if getattr(cls, 'volume', None):
-            cls.delete_volume(cls.volume['id'])
         resp, cls.sg = cls.security_groups_client.delete_security_group(
             cls.sg_id)
         super(ServerRescueTestJSON, cls).resource_cleanup()
diff --git a/tempest/api/compute/servers/test_server_rescue_negative.py b/tempest/api/compute/servers/test_server_rescue_negative.py
index 0d29968..de43164 100644
--- a/tempest/api/compute/servers/test_server_rescue_negative.py
+++ b/tempest/api/compute/servers/test_server_rescue_negative.py
@@ -35,12 +35,6 @@
         super(ServerRescueNegativeTestJSON, cls).resource_setup()
         cls.device = CONF.compute.volume_device_name
 
-        # Create a volume and wait for it to become ready for attach
-        resp, cls.volume = cls.volumes_extensions_client.create_volume(
-            1, display_name=data_utils.rand_name(cls.__name__ + '_volume'))
-        cls.volumes_extensions_client.wait_for_volume_status(
-            cls.volume['id'], 'available')
-
         # Server for negative tests
         resp, server = cls.create_test_server(wait_until='BUILD')
         resp, resc_server = cls.create_test_server(wait_until='ACTIVE')
@@ -54,11 +48,14 @@
         cls.servers_client.wait_for_server_status(cls.rescue_id, 'RESCUE')
         cls.servers_client.wait_for_server_status(cls.server_id, 'ACTIVE')
 
-    @classmethod
-    def resource_cleanup(cls):
-        if getattr(cls, 'volume', None):
-            cls.delete_volume(cls.volume['id'])
-        super(ServerRescueNegativeTestJSON, cls).resource_cleanup()
+    def _create_volume(self):
+        resp, volume = self.volumes_extensions_client.create_volume(
+            1, display_name=data_utils.rand_name(
+                self.__class__.__name__ + '_volume'))
+        self.addCleanup(self.delete_volume, volume['id'])
+        self.volumes_extensions_client.wait_for_volume_status(
+            volume['id'], 'available')
+        return volume
 
     def _detach(self, server_id, volume_id):
         self.servers_client.detach_volume(server_id, volume_id)
@@ -108,8 +105,11 @@
                           self.rescue_id,
                           self.image_ref_alt)
 
+    @test.services('volume')
     @test.attr(type=['negative', 'gate'])
     def test_rescued_vm_attach_volume(self):
+        volume = self._create_volume()
+
         # Rescue the server
         self.servers_client.rescue_server(self.server_id,
                                           adminPass=self.password)
@@ -120,31 +120,34 @@
         self.assertRaises(exceptions.Conflict,
                           self.servers_client.attach_volume,
                           self.server_id,
-                          self.volume['id'],
+                          volume['id'],
                           device='/dev/%s' % self.device)
 
+    @test.services('volume')
     @test.attr(type=['negative', 'gate'])
     def test_rescued_vm_detach_volume(self):
+        volume = self._create_volume()
+
         # Attach the volume to the server
         self.servers_client.attach_volume(self.server_id,
-                                          self.volume['id'],
+                                          volume['id'],
                                           device='/dev/%s' % self.device)
         self.volumes_extensions_client.wait_for_volume_status(
-            self.volume['id'], 'in-use')
+            volume['id'], 'in-use')
 
         # Rescue the server
         self.servers_client.rescue_server(self.server_id,
                                           adminPass=self.password)
         self.servers_client.wait_for_server_status(self.server_id, 'RESCUE')
         # addCleanup is a LIFO queue
-        self.addCleanup(self._detach, self.server_id, self.volume['id'])
+        self.addCleanup(self._detach, self.server_id, volume['id'])
         self.addCleanup(self._unrescue, self.server_id)
 
         # Detach the volume from the server expecting failure
         self.assertRaises(exceptions.Conflict,
                           self.servers_client.detach_volume,
                           self.server_id,
-                          self.volume['id'])
+                          volume['id'])
 
 
 class ServerRescueNegativeTestXML(ServerRescueNegativeTestJSON):