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 commit855b554656
) (cherry picked from commitbcb42a43a9
)
This commit is contained in:
parent
9bb78d5765
commit
f1ac5183d4
|
@ -4119,17 +4119,17 @@ class ComputeManager(manager.Manager):
|
||||||
|
|
||||||
self.network_api.setup_networks_on_host(context, instance,
|
self.network_api.setup_networks_on_host(context, instance,
|
||||||
migration.source_compute)
|
migration.source_compute)
|
||||||
migration_p = obj_base.obj_to_primitive(migration)
|
# NOTE(hanrong): we need to change migration.dest_compute to
|
||||||
# NOTE(hanrong): we need to change migration_p['dest_compute'] to
|
|
||||||
# source host temporarily. "network_api.migrate_instance_finish"
|
# source host temporarily. "network_api.migrate_instance_finish"
|
||||||
# will setup the network for the instance on the destination host.
|
# will setup the network for the instance on the destination host.
|
||||||
# For revert resize, the instance will back to the source host, the
|
# For revert resize, the instance will back to the source host, the
|
||||||
# setup of the network for instance should be on the source host.
|
# setup of the network for instance should be on the source host.
|
||||||
# So set the migration_p['dest_compute'] to source host at here.
|
# So set the migration.dest_compute to source host at here.
|
||||||
migration_p['dest_compute'] = migration.source_compute
|
with utils.temporary_mutation(
|
||||||
self.network_api.migrate_instance_finish(context,
|
migration, dest_compute=migration.source_compute):
|
||||||
instance,
|
self.network_api.migrate_instance_finish(context,
|
||||||
migration_p)
|
instance,
|
||||||
|
migration)
|
||||||
network_info = self.network_api.get_instance_nw_info(context,
|
network_info = self.network_api.get_instance_nw_info(context,
|
||||||
instance)
|
instance)
|
||||||
|
|
||||||
|
|
|
@ -6631,9 +6631,10 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
||||||
uuid=uuids.migration_uuid,
|
uuid=uuids.migration_uuid,
|
||||||
instance_uuid=self.instance.uuid,
|
instance_uuid=self.instance.uuid,
|
||||||
new_instance_type_id=7,
|
new_instance_type_id=7,
|
||||||
dest_compute=None,
|
dest_compute='dest_compute',
|
||||||
dest_node=None,
|
dest_node=None,
|
||||||
dest_host=None,
|
dest_host=None,
|
||||||
|
source_compute='source_compute',
|
||||||
status='migrating')
|
status='migrating')
|
||||||
self.migration.save = mock.MagicMock()
|
self.migration.save = mock.MagicMock()
|
||||||
self.useFixture(fixtures.SpawnIsSynchronousFixture())
|
self.useFixture(fixtures.SpawnIsSynchronousFixture())
|
||||||
|
@ -6817,6 +6818,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
||||||
self.nw_info = None
|
self.nw_info = None
|
||||||
|
|
||||||
def _migrate_instance_finish(context, instance, migration):
|
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'
|
self.nw_info = 'nw_info'
|
||||||
|
|
||||||
def _get_instance_nw_info(context, instance):
|
def _get_instance_nw_info(context, instance):
|
||||||
|
@ -6863,6 +6866,10 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
||||||
instance=self.instance)
|
instance=self.instance)
|
||||||
finish_revert_migration.assert_called_with(self.context,
|
finish_revert_migration.assert_called_with(self.context,
|
||||||
self.instance, 'nw_info', mock.ANY, mock.ANY)
|
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()
|
do_test()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue