summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-10-07 15:23:25 +0000
committerGerrit Code Review <review@openstack.org>2020-10-07 15:23:25 +0000
commit9167558dfa8fc706c3d93727d6d5f6faf229b17c (patch)
tree17a7da02e2a44d9a8ab6e7043de66bcf66a3e1b7
parent0dd44fc1a307802b90e4e3ad82107efdb7c83676 (diff)
parent65a888fbaa8b4ee7c409e00ba069c5cc343c0f63 (diff)
downloadnova-9167558dfa8fc706c3d93727d6d5f6faf229b17c.tar.gz
Merge "compute: Don't delete the original attachment during pre LM rollback" into stable/queens
-rw-r--r--nova/compute/manager.py7
-rw-r--r--nova/tests/functional/regressions/test_bug_1889108.py12
-rw-r--r--nova/tests/unit/compute/test_compute_mgr.py13
3 files changed, 24 insertions, 8 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 0990976412..adc6696b3d 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -6881,7 +6881,12 @@ class ComputeManager(manager.Manager):
for bdm in bdms:
try:
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.
diff --git a/nova/tests/functional/regressions/test_bug_1889108.py b/nova/tests/functional/regressions/test_bug_1889108.py
index 4f6d644136..68f954baae 100644
--- a/nova/tests/functional/regressions/test_bug_1889108.py
+++ b/nova/tests/functional/regressions/test_bug_1889108.py
@@ -27,8 +27,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
+ destination.
"""
api_major_version = 'v2.1'
microversion = 'latest'
@@ -114,9 +114,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))
diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py
index 09cc97dc09..803fe72781 100644
--- a/nova/tests/unit/compute/test_compute_mgr.py
+++ b/nova/tests/unit/compute/test_compute_mgr.py
@@ -8284,6 +8284,19 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
self.assertIn('Exception while attempting to rollback',
mock_log.exception.call_args[0][0])
+ @mock.patch('nova.volume.cinder.API.attachment_delete')
+ 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.compute._rollback_volume_bdms(
+ 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.
+ mock_delete_attachment.assert_not_called()
+
@mock.patch.object(objects.ComputeNode,
'get_first_node_by_host_for_old_compat')
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'