From 46d65edcc948781aeea1d611735d81c2b29322f3 Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Thu, 29 Mar 2012 16:41:21 -0700 Subject: [PATCH] Allow snapshots in error state to be deleted. * Fixes bug 968682 Change-Id: I37fd8e84e50b2f824f978eb7e3181ffb6ddde537 --- nova/tests/test_volume.py | 20 ++++++++++++++++++++ nova/volume/api.py | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_volume.py b/nova/tests/test_volume.py index be589d3e2474..fca593c7c293 100644 --- a/nova/tests/test_volume.py +++ b/nova/tests/test_volume.py @@ -275,7 +275,27 @@ class VolumeTestCase(test.TestCase): volume_api.delete, self.context, volume) + self.volume.delete_snapshot(self.context, snapshot_id) + self.volume.delete_volume(self.context, volume['id']) + def test_can_delete_errored_snapshot(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) + snapshot = db.snapshot_get(context.get_admin_context(), + snapshot_id) + + volume_api = nova.volume.api.API() + + snapshot['status'] = 'badstatus' + self.assertRaises(exception.InvalidVolume, + volume_api.delete_snapshot, + self.context, + snapshot) + + snapshot['status'] = 'error' self.volume.delete_snapshot(self.context, snapshot_id) self.volume.delete_volume(self.context, volume['id']) diff --git a/nova/volume/api.py b/nova/volume/api.py index 26d56c0578c3..76de55131ea0 100644 --- a/nova/volume/api.py +++ b/nova/volume/api.py @@ -321,8 +321,8 @@ class API(base.Base): @wrap_check_policy def delete_snapshot(self, context, snapshot): - if snapshot['status'] != "available": - msg = _("must be available") + if snapshot['status'] not in ["available", "error"]: + msg = _("Volume Snapshot status must be available or error") raise exception.InvalidVolume(reason=msg) self.db.snapshot_update(context, snapshot['id'], {'status': 'deleting'})