From: Mike Perez Date: Thu, 22 Jan 2015 00:06:49 +0000 (-0800) Subject: Prevent deleting volumes in a consistency group X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=eb107145173fb71314de9b10cf3ca50c74442519;p=openstack-build%2Fcinder-build.git Prevent deleting volumes in a consistency group 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 --- diff --git a/cinder/tests/api/contrib/test_volume_unmanage.py b/cinder/tests/api/contrib/test_volume_unmanage.py index c80c00d48..88c1d8698 100644 --- a/cinder/tests/api/contrib/test_volume_unmanage.py +++ b/cinder/tests/api/contrib/test_volume_unmanage.py @@ -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} } diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 8778129ea..493497026 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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) diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 303372c2f..23276893f 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -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)