]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Continue volume delete on encryption key delete errors
authorDuncan Thomas <duncan.thomas@gmail.com>
Wed, 2 Mar 2016 10:08:52 +0000 (12:08 +0200)
committerDuncan Thomas <duncan.thomas@gmail.com>
Mon, 7 Mar 2016 15:22:02 +0000 (23:22 +0800)
If there is a problem removing the encryption key from the key manager
(e.g. because the key has been manually deleted already) then the
volume delete should not fail - this leaves undeletable volumes.

Just log a warning and continue instead.

Closes-bug: 1552169
Change-Id: Id3571cbfa7c66787573cf750735be33a440d15dc

cinder/tests/unit/test_volume.py
cinder/volume/api.py

index 6cf65569bc5a2c18564cf5110579af8ab0e271e5..bf0c133a1af96e561b781498da51ed4f20057de1 100644 (file)
@@ -7710,6 +7710,19 @@ class ImageVolumeCacheTestCase(BaseVolumeTestCase):
                                                        volume['id'])
         self.assertIsNone(entry)
 
+    def test_delete_volume_with_keymanager_exception(self):
+        volume_params = {
+            'host': 'some_host',
+            'size': 1
+        }
+        volume_api = cinder.volume.api.API()
+        volume = tests_utils.create_volume(self.context, **volume_params)
+
+        with mock.patch.object(
+                volume_api.key_manager, 'delete_key') as key_del_mock:
+            key_del_mock.side_effect = Exception("Key not found")
+            volume_api.delete(self.context, volume)
+
 
 @ddt.ddt
 class DiscardFlagTestCase(BaseVolumeTestCase):
index 4fba50a8d26003c84925e69bab69d42ec48db5ef..a4b1be4242e1d1713265a2573940f4e86850a1ff 100644 (file)
@@ -425,8 +425,8 @@ class API(base.Base):
             try:
                 self.key_manager.delete_key(context, encryption_key_id)
             except Exception as e:
-                msg = _("Unable to delete encrypted volume: %s.") % e.msg
-                raise exception.InvalidVolume(reason=msg)
+                LOG.warning(_LW("Unable to delete encryption key for "
+                                "volume: %s."), e.msg, resource=volume)
 
         self.volume_rpcapi.delete_volume(context,
                                          volume,