]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Prevent deleting volumes in a consistency group
authorMike Perez <thingee@gmail.com>
Thu, 22 Jan 2015 00:06:49 +0000 (16:06 -0800)
committerMike Perez <thingee@gmail.com>
Thu, 22 Jan 2015 00:44:31 +0000 (16:44 -0800)
Currently you have to destroy the consistency group if you want to
delete these volumes. In the Kilo release, we'll have the ability to
remove a volume from a consistency group, which then can be deleted.

Closes-Bug: #1413427
Change-Id: Ice8ab88a89e447a08c3ce71c7698dd5fcf02d1e9

cinder/tests/api/contrib/test_volume_unmanage.py
cinder/tests/test_volume.py
cinder/volume/api.py

index c80c00d48af0320af4412abe02018f795f6608ee..88c1d8698c9a0f4fb3a85f4d8fe54977c09e57a3 100644 (file)
@@ -36,6 +36,7 @@ vols = {snapshot_vol_id: {'id': snapshot_vol_id,
                           'host': 'fake_host',
                           'project_id': 'fake_project',
                           'migration_status': None,
+                          'consistencygroup_id': None,
                           'encryption_key_id': None},
         detached_vol_id: {'id': detached_vol_id,
                           'status': 'available',
@@ -43,6 +44,7 @@ vols = {snapshot_vol_id: {'id': snapshot_vol_id,
                           'host': 'fake_host',
                           'project_id': 'fake_project',
                           'migration_status': None,
+                          'consistencygroup_id': None,
                           'encryption_key_id': None},
         attached_vol_id: {'id': attached_vol_id,
                           'status': 'available',
@@ -50,6 +52,7 @@ vols = {snapshot_vol_id: {'id': snapshot_vol_id,
                           'host': 'fake_host',
                           'project_id': 'fake_project',
                           'migration_status': None,
+                          'consistencygroup_id': None,
                           'encryption_key_id': None}
         }
 
index 8778129ea8f0950b71d81fcb743797322180e7ae..493497026850dd5652609afcdcb7d3565e78db84 100644 (file)
@@ -1968,6 +1968,17 @@ class VolumeTestCase(BaseVolumeTestCase):
         self.volume.delete_snapshot(self.context, snapshot_id)
         self.volume.delete_volume(self.context, volume['id'])
 
+    def test_delete_volume_in_consistency_group(self):
+        """Test deleting a volume that's tied to a consistency group fails."""
+        volume_api = cinder.volume.api.API()
+        volume = tests_utils.create_volume(self.context, **self.volume_params)
+        consistencygroup_id = '12345678-1234-5678-1234-567812345678'
+        volume = db.volume_update(self.context, volume['id'],
+                                  {'status': 'available',
+                                   'consistencygroup_id': consistencygroup_id})
+        self.assertRaises(exception.InvalidVolume,
+                          volume_api.delete, self.context, volume)
+
     def test_can_delete_errored_snapshot(self):
         """Test snapshot can be created and deleted."""
         volume = tests_utils.create_volume(self.context, **self.volume_params)
index 303372c2fa98fa56b4b01e50d3e72e089fc120f4..23276893fafd0a371e7a5a2c77019901b2929495 100644 (file)
@@ -296,6 +296,10 @@ class API(base.Base):
             msg = _("Volume cannot be deleted while migrating")
             raise exception.InvalidVolume(reason=msg)
 
+        if volume['consistencygroup_id'] is not None:
+            msg = _("Volume cannot be deleted while in a consistency group.")
+            raise exception.InvalidVolume(reason=msg)
+
         snapshots = self.db.snapshot_get_all_for_volume(context, volume_id)
         if len(snapshots):
             msg = _("Volume still has %d dependent snapshots") % len(snapshots)