Fix detach notification

Our current `attachment_delete` methods in the volume API and the
manager are using DB methods directly, which makes the OVOs present in
those methods get out of sync with the latest data, which leads to
notifications having the wrong data when we send them on volume detach.

This patch replaces DB method calls with OVO calls and moves the
notification call to the end of the method, where we have the final
status on the volume.

It also adds the missing detach.start notification when deleting an
attachment in the reserved state.

Closes-Bug: #1916980
Closes-Bug: #1935011
Change-Id: Ie48cf55deacd08e7716201dac00ede8d57e6632f
This commit is contained in:
Gorka Eguileor 2021-07-02 15:11:53 +02:00
parent ca4bfddba6
commit 68d4944577
4 changed files with 27 additions and 14 deletions

View File

@ -166,6 +166,12 @@ class AttachmentManagerTestCase(test.TestCase):
mock_db_detached, mock_db_meta_delete, mock_get_attachment):
mock_elevated.return_value = self.context
mock_con_term.return_value = False
mock_db_detached.return_value = (
{'status': 'available',
'attach_status': fields.VolumeAttachStatus.DETACHED},
{'attach_status': fields.VolumeAttachStatus.DETACHED,
'deleted': True}
)
# test single attachment. This should call
# detach and remove_export

View File

@ -2259,17 +2259,17 @@ class API(base.Base):
ctxt.authorize(attachment_policy.DELETE_POLICY,
target_obj=attachment)
volume = attachment.volume
if attachment.attach_status == fields.VolumeAttachStatus.RESERVED:
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")
volume_utils.notify_about_volume_usage(ctxt, volume,
"detach.start")
volume.finish_detach(attachment.id)
do_notify = True
else:
self.volume_rpcapi.attachment_delete(ctxt,
attachment.id,
volume)
do_notify = False
status_updates = {'status': 'available',
'attach_status': 'detached'}
remaining_attachments = AO_LIST.get_all_by_volume_id(ctxt, volume.id)
@ -2305,6 +2305,8 @@ class API(base.Base):
volume.attach_status = status_updates['attach_status']
volume.save()
if do_notify:
volume_utils.notify_about_volume_usage(ctxt, volume, "detach.end")
return remaining_attachments

View File

@ -4954,15 +4954,11 @@ class VolumeManager(manager.CleanableManager,
# represent a single failed attach out of multiple attachments
# TODO(jdg): object method here
self.db.volume_attachment_update(
context, attachment.get('id'),
{'attach_status': fields.VolumeAttachStatus.ERROR_DETACHING})
attachment.attach_status = \
fields.VolumeAttachStatus.ERROR_DETACHING
attachment.save()
else:
self.db.volume_detached(context.elevated(), vref.id,
attachment.get('id'))
self.db.volume_admin_metadata_delete(context.elevated(),
vref.id,
'attached_mode')
vref.finish_detach(attachment_id)
self._notify_about_volume_usage(context, vref, "detach.end")
# Replication group API (Tiramisu)

View File

@ -0,0 +1,9 @@
---
fixes:
- |
`Bug #1916980 <https://bugs.launchpad.net/cinder/+bug/1916980>`_: Fixed
stale volume notification information on volume detach.
- |
`Bug #1935011 <https://bugs.launchpad.net/cinder/+bug/1935011>`_: Fixed
missing detach.start notification when deleting an attachment in reserved
state.