From f1ac5183d43459614ba5a356c2c7b50251fcd94f Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Tue, 5 Mar 2019 16:39:51 -0500 Subject: [PATCH] Temporarily mutate migration object in finish_revert_resize As the comment in the code suggests, when calling migrate_instance_finish in finish_revert_resize we need to temporarily set the migration object dest_compute to the source_compute since we are moving port bindings from the dest back to the source. However, this is not really a temporary change to the object if something fails after this because the @errors_out_migration decorator will persist the change which could be confusing later if trying to debug this migration from the API and the dest_compute and source_compute have the same value. This fixes the issue by using the temporary_mutation utility. Also, the obj_to_primitive dance in here is removed since it is not necessary as migrate_instance_finish handles a Migration object. Conflicts: nova/tests/unit/compute/test_compute_mgr.py NOTE(mriedem): The conflict is due to not having change I0851e2d54a1fdc82fe3291fb7e286e790f121e92 in Rocky. Change-Id: I312d61383345ea0ac1ab0c277b4c468e6aa94656 Closes-Bug: #1818730 (cherry picked from commit 855b5546564f0ed96243623b67b1322e9b891c8b) (cherry picked from commit bcb42a43a9f12d929ec7025f29bd2e3d482cd406) --- nova/compute/manager.py | 14 +++++++------- nova/tests/unit/compute/test_compute_mgr.py | 9 ++++++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 85427d62c5fb..89159b3ad3de 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -4119,17 +4119,17 @@ class ComputeManager(manager.Manager): self.network_api.setup_networks_on_host(context, instance, migration.source_compute) - migration_p = obj_base.obj_to_primitive(migration) - # NOTE(hanrong): we need to change migration_p['dest_compute'] to + # NOTE(hanrong): we need to change migration.dest_compute to # source host temporarily. "network_api.migrate_instance_finish" # will setup the network for the instance on the destination host. # For revert resize, the instance will back to the source host, the # setup of the network for instance should be on the source host. - # So set the migration_p['dest_compute'] to source host at here. - migration_p['dest_compute'] = migration.source_compute - self.network_api.migrate_instance_finish(context, - instance, - migration_p) + # So set the migration.dest_compute to source host at here. + with utils.temporary_mutation( + migration, dest_compute=migration.source_compute): + self.network_api.migrate_instance_finish(context, + instance, + migration) network_info = self.network_api.get_instance_nw_info(context, instance) diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 2b9364adae60..923747e3bf82 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -6631,9 +6631,10 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase): uuid=uuids.migration_uuid, instance_uuid=self.instance.uuid, new_instance_type_id=7, - dest_compute=None, + dest_compute='dest_compute', dest_node=None, dest_host=None, + source_compute='source_compute', status='migrating') self.migration.save = mock.MagicMock() self.useFixture(fixtures.SpawnIsSynchronousFixture()) @@ -6817,6 +6818,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase): self.nw_info = None def _migrate_instance_finish(context, instance, migration): + # The migration.dest_compute is temporarily set to source_compute. + self.assertEqual(migration.source_compute, migration.dest_compute) self.nw_info = 'nw_info' def _get_instance_nw_info(context, instance): @@ -6863,6 +6866,10 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase): instance=self.instance) finish_revert_migration.assert_called_with(self.context, self.instance, 'nw_info', mock.ANY, mock.ANY) + # Make sure the migration.dest_compute is not still set to the + # source_compute value. + self.assertNotEqual(self.migration.dest_compute, + self.migration.source_compute) do_test()