From b816e3cc33ad37c4b4850e05336fd3ed7ac9e197 Mon Sep 17 00:00:00 2001 From: zte-hanrong Date: Wed, 29 Jun 2016 08:53:53 +0800 Subject: [PATCH] migration.source_compute should be unchanged after finish_revert_resize. The field of dest_compute in migration table represent destination host name during a migration. The value of migration.dest_compute has been changed to migration's source host name after resize-revert operation. That would lead to history records of migrations are not accurate. This change modifies this problem. Close-Bug:#1625462 Change-Id: Ie616045c40ea4a18977c18df9f5624efa4ba7e6a --- nova/compute/manager.py | 11 +++++++---- nova/tests/unit/compute/test_compute.py | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index dfaee532eb..5fab73e57f 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -3583,13 +3583,16 @@ class ComputeManager(manager.Manager): instance.node = migration.source_node instance.save() - migration.dest_compute = migration.source_compute - with migration.obj_as_admin(): - migration.save() - 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 + # 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) diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 861e6b1077..d8b349cc77 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -102,6 +102,7 @@ CONF = nova.conf.CONF FAKE_IMAGE_REF = uuids.image_ref NODENAME = 'fakenode1' +NODENAME2 = 'fakenode2' def fake_not_implemented(*args, **kwargs): @@ -149,7 +150,7 @@ class BaseTestCase(test.TestCase): def setUp(self): super(BaseTestCase, self).setUp() self.flags(network_manager='nova.network.manager.FlatManager') - fake.set_nodes([NODENAME]) + fake.set_nodes([NODENAME, NODENAME2]) fake_notifier.stub_notifier(self) self.addCleanup(fake_notifier.reset) @@ -5451,6 +5452,10 @@ class ComputeTestCase(BaseTestCase): self.context.elevated(), instance.uuid) self.assertIsInstance(migration_context.old_numa_topology, numa_topology.__class__) + source_compute = migration.source_compute + migration.dest_compute = NODENAME2 + migration.dest_node = NODENAME2 + migration.save() # NOTE(mriedem): ensure prep_resize set old_vm_state in system_metadata sys_meta = instance.system_metadata @@ -5491,6 +5496,12 @@ class ComputeTestCase(BaseTestCase): instance.system_metadata = sys_meta instance.save() + # NOTE(hanrong): Prove that we pass the right value to the + # "self.network_api.migrate_instance_finish". + def fake_migrate_instance_finish(cls, context, instance, migration): + self.assertEqual(source_compute, migration['dest_compute']) + self.stub_out('nova.network.api.API.migrate_instance_finish', + fake_migrate_instance_finish) self.compute.finish_revert_resize(self.context, migration=migration, instance=instance, reservations=reservations) @@ -5501,7 +5512,10 @@ class ComputeTestCase(BaseTestCase): instance['instance_type_id']) self.assertEqual(flavor.flavorid, '1') self.assertEqual(instance.host, migration.source_compute) - self.assertEqual(migration.dest_compute, migration.source_compute) + self.assertNotEqual(migration.dest_compute, migration.source_compute) + self.assertNotEqual(migration.dest_node, migration.source_node) + self.assertEqual(NODENAME2, migration.dest_compute) + self.assertEqual(NODENAME2, migration.dest_node) self.assertIsInstance(instance.numa_topology, numa_topology.__class__) if remove_old_vm_state: