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()