From 80b943c7f29ea2e88bb9a934c166ef095c8ca84d Mon Sep 17 00:00:00 2001 From: John Griffith Date: Wed, 5 Jul 2017 16:06:55 +0000 Subject: [PATCH] Fix attachment_delete for reserved case In attachment-delete we attempt a little short cut in cases where the volume is reserved but not actually attached to an instance. In this case we don't have a connector and we never actually sent anything to the driver, so we take a short cut in cinder.volume.api and we just call an object.destroy(). The problem with this is that the object doesn't do the proper/needed context settings and checks and just fails due to policy. We should clean this up and add the extra db update steps and also include the notification messages. Change-Id: Ib448f0548739cd42edf03eab07f305b3ac184d8f Closes-Bug: #1702512 --- cinder/volume/api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 40b8ca67fe6..bc8db539f95 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -2003,7 +2003,12 @@ class API(base.Base): def attachment_delete(self, ctxt, attachment): volume = objects.Volume.get_by_id(ctxt, attachment.volume_id) if attachment.attach_status == 'reserved': - attachment.destroy() + self.db.volume_detached(ctxt.elevated(), attachment.volume_id, + attachment.get('id')) + self.db.volume_admin_metadata_delete(ctxt.elevated(), + attachment.volume_id, + 'attached_mode') + volume_utils.notify_about_volume_usage(ctxt, volume, "detach.end") else: self.volume_rpcapi.attachment_delete(ctxt, attachment.id,