From 43c63d11417de8624d120ca78a9849d09ffa8cf6 Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Thu, 29 Mar 2012 16:57:19 -0700 Subject: 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 --- nova/tests/test_volume.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/test_volume.py b/nova/tests/test_volume.py index caeaa7098..be589d3e2 100644 --- a/nova/tests/test_volume.py +++ b/nova/tests/test_volume.py @@ -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.""" -- cgit