From abe04f048c432fed5726af8244bb055e6e44657e Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Wed, 25 Mar 2020 17:48:23 +0100 Subject: [PATCH] Update scheduler instance info at confirm resize When a resize is confirmed the instance does not belong to the source compute any more. In the past the scheduler instance info is only updated by the _sync_scheduler_instance_info periodic. This caused that server boots with anti-affinity did not consider the source host. But now at the end of the confirm_resize call the compute also updates the scheduler about the move. Conflicts: nova/compute/manager.py due to I933687891abef4878de09481937d576ce5899511 is a stable only patch nova/tests/unit/compute/test_compute_mgr.py due to 35ce77835bb271bad3c18eaf22146edac3a42ea0 is missing from stable/rocky Change-Id: Ic50e72e289b56ac54720ad0b719ceeb32487b8c8 Closes-Bug: #1869050 (cherry picked from commit 738110db7492b1360f5f197e8ecafd69a3b141b4) (cherry picked from commit e8b3927c92d29c74fd0c79b5a51b7a34e9d66236) (cherry picked from commit e34b375a6161b15d92beba64fa281f40634ffeab) (cherry picked from commit e1116ee3b776ec84e4ce7d6ac9346fa0d43269b5) --- nova/compute/manager.py | 4 ++++ nova/tests/functional/test_server_group.py | 23 ++++++--------------- nova/tests/unit/compute/test_compute_mgr.py | 8 +++++-- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 904245c096f0..e7243d4a1211 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -4078,6 +4078,10 @@ class ComputeManager(manager.Manager): self._delete_allocation_after_move( context, instance, migration, old_instance_type, migration.source_node) + # Also as the instance is not any more on this host, update + # the scheduler about the move + self._delete_scheduler_instance_info( + context, instance.uuid) do_confirm_resize(context, instance, migration.id) diff --git a/nova/tests/functional/test_server_group.py b/nova/tests/functional/test_server_group.py index f3e43bc44131..301735192ae5 100644 --- a/nova/tests/functional/test_server_group.py +++ b/nova/tests/functional/test_server_group.py @@ -369,7 +369,7 @@ class ServerGroupTestV21(ServerGroupTestBase): self.assertNotEqual(servers[0]['OS-EXT-SRV-ATTR:host'], migrated_server['OS-EXT-SRV-ATTR:host']) - def test_migrate_with_anti_affinity_stale_scheduler_instance_info(self): + def test_migrate_with_anti_affinity_confirm_updates_scheduler(self): # Start additional host to test migration with anti-affinity compute3 = self.start_service('compute', host='host3') @@ -398,23 +398,12 @@ class ServerGroupTestV21(ServerGroupTestBase): self.admin_api.post_server_action(servers[1]['id'], post) self._wait_for_state_change(self.admin_api, servers[1], 'ACTIVE') - # NOTE(gibi): This is bug 1869050. The confirm resize does to update - # the scheduler instance info so the migrate_server occupies two host - # according to the stale information in the scheduler. - # Alternatively waiting for the periodic _sync_scheduler_instance_info - # call would update the stale data. + server3 = self._boot_a_server_to_group(created_group) - server3 = self._boot_a_server_to_group( - created_group, expected_status='ERROR') - self.assertIn('No valid host', server3['fault']['message']) - - # When bug 1869050 is fixed the following is expected: - # server3 = self._boot_a_server_to_group(created_group) - # - # # we have 3 servers that should occupy 3 different hosts - # hosts = {server['OS-EXT-SRV-ATTR:host'] - # for server in [servers[0], migrated_server, server3]} - # self.assertEqual(3, len(hosts)) + # we have 3 servers that should occupy 3 different hosts + hosts = {server['OS-EXT-SRV-ATTR:host'] + for server in [servers[0], migrated_server, server3]} + self.assertEqual(3, len(hosts)) def test_resize_to_same_host_with_anti_affinity(self): self.flags(allow_resize_to_same_host=True) diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 64d501a82dea..d14d8c0fa24b 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -7481,7 +7481,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase): do_revert_resize() do_finish_revert_resize() - def test_confirm_resize_deletes_allocations(self): + def test_confirm_resize_deletes_allocations_and_update_scheduler(self): + @mock.patch.object(self.compute, '_delete_scheduler_instance_info') @mock.patch('nova.objects.Instance.get_by_uuid') @mock.patch('nova.objects.Migration.get_by_id') @mock.patch.object(self.migration, 'save') @@ -7494,7 +7495,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase): @mock.patch.object(self.instance, 'save') def do_confirm_resize(mock_save, mock_drop, mock_delete, mock_get_rt, mock_confirm, mock_nwapi, mock_notify, - mock_mig_save, mock_mig_get, mock_inst_get): + mock_mig_save, mock_mig_get, mock_inst_get, + mock_delete_scheduler_info): self.instance.migration_context = objects.MigrationContext( new_pci_devices=None, old_pci_devices=None) @@ -7512,6 +7514,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase): mock_save.assert_called_with(expected_task_state= [None, task_states.DELETING, task_states.SOFT_DELETING]) + mock_delete_scheduler_info.assert_called_once_with( + self.context, self.instance.uuid) do_confirm_resize()