This patch adds exception handler when deleting key of an encryption volume.
Raise 400 invalid volume instead of 500 to give the user a better understanding
why deleting failed.
Closes-bug: #
1482120
Change-Id: I591f65823d1f212e92434323905cc9c4fbe6fd96
discover)
self.assertEqual(expected, capabilities['properties'])
+ def test_delete_encryptied_volume(self):
+ self.volume_params['status'] = 'active'
+ volume = tests_utils.create_volume(self.context,
+ **self.volume_params)
+ vol_api = cinder.volume.api.API()
+ with mock.patch.object(
+ vol_api.key_manager,
+ 'delete_key',
+ side_effect=Exception):
+ self.assertRaises(exception.InvalidVolume,
+ vol_api.delete,
+ self.context, volume)
+
class CopyVolumeToImageTestCase(BaseVolumeTestCase):
def fake_local_path(self, volume):
# because the volume cannot be decrypted without its key.
encryption_key_id = volume.get('encryption_key_id', None)
if encryption_key_id is not None:
- self.key_manager.delete_key(context, encryption_key_id)
+ 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)
now = timeutils.utcnow()
vref = self.db.volume_update(context,