Skip to content

Commit 2102f18

Browse files
committed
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 anymore. 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 _rollback_live_migration: * 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
1 parent 274cc3d commit 2102f18

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

nova/compute/manager.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8612,7 +8612,12 @@ def _rollback_volume_bdms(self, context, bdms, original_bdms, instance):
86128612
for bdm in bdms:
86138613
try:
86148614
original_bdm = original_bdms_by_volid[bdm.volume_id]
8615-
if bdm.attachment_id and original_bdm.attachment_id:
8615+
# NOTE(lyarwood): Only delete the referenced attachment if it
8616+
# is different to the original in order to avoid accidentally
8617+
# removing the source host volume attachment after it has
8618+
# already been rolled back by a failure in pre_live_migration.
8619+
if (bdm.attachment_id and original_bdm.attachment_id and
8620+
bdm.attachment_id != original_bdm.attachment_id):
86168621
# NOTE(lyarwood): 3.44 cinder api flow. Delete the
86178622
# attachment used by the bdm and reset it to that of
86188623
# the original bdm.

nova/tests/functional/regressions/test_bug_1889108.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class TestVolAttachmentsDuringPreLiveMigration(
2323
"""Regression test for bug 1889108.
2424
2525
This regression test asserts that the original source volume attachments
26-
are incorrectly removed during the rollback from pre_live_migration
27-
failures on the destination.
26+
are not removed during the rollback from pre_live_migration failures on the
27+
destination.
2828
"""
2929

3030
# Default self.api to the self.admin_api as live migration is admin only
@@ -95,9 +95,7 @@ def test_vol_attachments_during_driver_pre_live_mig_failure(
9595
server = self.api.get_server(server['id'])
9696
self.assertEqual(src_host, server['OS-EXT-SRV-ATTR:host'])
9797

98-
# FIXME(lyarwood): Assert that both the src and dest attachments have
99-
# been removed. Only the dest attachment should be removed during the
100-
# rollback of a pre_live_migration failure.
98+
# Assert that the src attachment is still present
10199
attachments = self.cinder.volume_to_attachment.get(volume_id)
102-
self.assertNotIn(src_attachment_id, attachments.keys())
103-
self.assertEqual(0, len(attachments))
100+
self.assertIn(src_attachment_id, attachments.keys())
101+
self.assertEqual(1, len(attachments))

nova/tests/unit/compute/test_compute_mgr.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10079,6 +10079,19 @@ def test_rollback_volume_bdms_exc(self, mock_delete_attachment, mock_log):
1007910079
self.assertIn('Exception while attempting to rollback',
1008010080
mock_log.exception.call_args[0][0])
1008110081

10082+
@mock.patch('nova.volume.cinder.API.attachment_delete')
10083+
def test_rollback_volume_bdms_after_pre_failure(
10084+
self, mock_delete_attachment):
10085+
instance = fake_instance.fake_instance_obj(
10086+
self.context, uuid=uuids.instance)
10087+
original_bdms = bdms = self._generate_volume_bdm_list(instance)
10088+
self.compute._rollback_volume_bdms(
10089+
self.context, bdms, original_bdms, instance)
10090+
# Assert that attachment_delete isn't called when the bdms have already
10091+
# been rolled back by a failure in pre_live_migration to reference the
10092+
# source bdms.
10093+
mock_delete_attachment.assert_not_called()
10094+
1008210095
@mock.patch.object(objects.ComputeNode,
1008310096
'get_first_node_by_host_for_old_compat')
1008410097
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'

0 commit comments

Comments
 (0)