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 (cherry picked from commit68d4944577
) Conflicts: cinder/volume/api.py Changes: cinder/volume/manager.py (cherry picked from commitc0197c6f1a
) (cherry picked from commited06fc7452
)
This commit is contained in:
parent
7d6ca2feb9
commit
c9d3cc966c
|
@ -163,6 +163,12 @@ class AttachmentManagerTestCase(test.TestCase):
|
|||
mock_elevated, mock_db_detached, mock_db_meta_delete):
|
||||
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
|
||||
|
|
|
@ -2267,17 +2267,17 @@ class API(base.Base):
|
|||
ctxt.authorize(attachment_policy.DELETE_POLICY,
|
||||
target_obj=attachment)
|
||||
volume = objects.Volume.get_by_id(ctxt, attachment.volume_id)
|
||||
|
||||
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)
|
||||
|
@ -2312,6 +2312,9 @@ class API(base.Base):
|
|||
volume.status = status_updates['status']
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -4696,15 +4696,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)
|
||||
|
|
|
@ -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.
|
Loading…
Reference in New Issue