Browse Source

compute: Don't delete the original attachment during pre LM rollback

I0bfb11296430dfffe9b091ae7c3a793617bd9d0d introduced support for live
migration with cinderv3 volume attachments during Queens. This initial
support handled failures in pre_live_migration directly by removing any
attachments created on the destination and reverting to the original
attachment ids before re-raising the caught exception to the source
compute. It also added rollback code within the main
_rollback_live_migration method but missed that this would also be
called during a pre_live_migration rollback.

As a result after a failure in pre_live_migration
_rollback_live_migration will attempt to delete the source host volume
attachments referenced by the bdm before updating the bdms with the now
non-existent attachment ids, leaving the volumes in an `available` state
in Cinder as they have no attachment records associated with them

This change aims to resolve this within _rollback_volume_bdms by
ensuring that the current and original attachment_ids are not equal
before requesting that the current attachment referenced by the bdm is
deleted. When called after a failure in pre_live_migration this should
result in no attempt being made to remove the original source host
attachments from Cinder.

Note that the following changes muddy the waters slightly here but
introduced no actual changes to the logic within

* I0f3ab6604d8b79bdb75cf67571e359cfecc039d8 reworked some of the error
  handling in Rocky but isn't the source of the issue here.

* Ibe9215c07a1ee00e0e121c69bcf7ee1b1b80fae0 reworked
  _rollback_live_migration to use the provided source_bdms.

* I6bc73e8c8f98d9955f33f309beb8a7c56981b553 then refactored
  _rollback_live_migration, moving the logic into a self contained
  _rollback_volume_bdms method.

Closes-Bug: #1889108
Change-Id: I9edb36c4df1cc0d8b529e669f06540de71766085
(cherry picked from commit 2102f1834a)
(cherry picked from commit 034b2fa8fe)
(cherry picked from commit c6c3483a41)
(cherry picked from commit 6007c41aa8)
Lee Yarwood 1 year ago
  1. 7
  2. 12
  3. 13


@ -7242,7 +7242,12 @@ class ComputeManager(manager.Manager):
for bdm in bdms:
original_bdm = original_bdms_by_volid[bdm.volume_id]
if bdm.attachment_id and original_bdm.attachment_id:
# NOTE(lyarwood): Only delete the referenced attachment if it
# is different to the original in order to avoid accidentally
# removing the source host volume attachment after it has
# already been rolled back by a failure in pre_live_migration.
if (bdm.attachment_id and original_bdm.attachment_id and
bdm.attachment_id != original_bdm.attachment_id):
# NOTE(lyarwood): 3.44 cinder api flow. Delete the
# attachment used by the bdm and reset it to that of
# the original bdm.


@ -26,8 +26,8 @@ class TestVolAttachmentsDuringPreLiveMigration(
"""Regression test for bug 1889108.
This regression test asserts that the original source volume attachments
are incorrectly removed during the rollback from pre_live_migration
failures on the destination.
are not removed during the rollback from pre_live_migration failures on the
api_major_version = 'v2.1'
microversion = 'latest'
@ -106,9 +106,7 @@ class TestVolAttachmentsDuringPreLiveMigration(
server = self.api.get_server(server['id'])
self.assertEqual(src_host, server['OS-EXT-SRV-ATTR:host'])
# FIXME(lyarwood): Assert that both the src and dest attachments have
# been removed. Only the dest attachment should be removed during the
# rollback of a pre_live_migration failure.
# Assert that the src attachment is still present
attachments = self.cinder.volume_to_attachment.get(volume_id)
self.assertNotIn(src_attachment_id, attachments.keys())
self.assertEqual(0, len(attachments))
self.assertIn(src_attachment_id, attachments.keys())
self.assertEqual(1, len(attachments))


@ -8950,6 +8950,19 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
self.assertIn('Exception while attempting to rollback',
def test_rollback_volume_bdms_after_pre_failure(
self, mock_delete_attachment):
instance = fake_instance.fake_instance_obj(
self.context, uuid=uuids.instance)
original_bdms = bdms = self._generate_volume_bdm_list(instance)
self.context, bdms, original_bdms, instance)
# Assert that attachment_delete isn't called when the bdms have already
# been rolled back by a failure in pre_live_migration to reference the
# source bdms.