Check that volume has no snapshots before deletion

* Raise a helpful error message if existing snapshots are detected
 * Fixes bug 968700
 * Fixes bug 968649

Change-Id: I470db6bd51a103249aae9bfcb2167f0a486732c2
This commit is contained in:
Anthony Young
2012-03-29 16:57:19 -07:00
parent 273b0d5c44
commit 540b60ed5f

View File

@@ -256,6 +256,29 @@ class VolumeTestCase(test.TestCase):
snapshot_id)
self.volume.delete_volume(self.context, volume['id'])
def test_cant_delete_volume_with_snapshots(self):
"""Test snapshot can be created and deleted."""
volume = self._create_volume()
self.volume.create_volume(self.context, volume['id'])
snapshot_id = self._create_snapshot(volume['id'])
self.volume.create_snapshot(self.context, volume['id'], snapshot_id)
self.assertEqual(snapshot_id,
db.snapshot_get(context.get_admin_context(),
snapshot_id).id)
volume['status'] = 'available'
volume['host'] = 'fakehost'
volume_api = nova.volume.api.API()
self.assertRaises(exception.InvalidVolume,
volume_api.delete,
self.context,
volume)
self.volume.delete_snapshot(self.context, snapshot_id)
self.volume.delete_volume(self.context, volume['id'])
def test_create_snapshot_force(self):
"""Test snapshot in use can be created forcibly."""