From e1116ee3b776ec84e4ce7d6ac9346fa0d43269b5 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/tests/unit/compute/test_compute_mgr.py due to Ib50b6b02208f5bd2972de8a6f8f685c19745514c and Ia6d8a7909081b0b856bd7e290e234af7e42a2b38 are missing from stable/stein Change-Id: Ic50e72e289b56ac54720ad0b719ceeb32487b8c8 Closes-Bug: #1869050 (cherry picked from commit 738110db7492b1360f5f197e8ecafd69a3b141b4) (cherry picked from commit e8b3927c92d29c74fd0c79b5a51b7a34e9d66236) (cherry picked from commit e34b375a6161b15d92beba64fa281f40634ffeab) --- 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 7c7a101ffc41..7f21be41542a 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -4181,6 +4181,10 @@ class ComputeManager(manager.Manager): # allocations in placement, delete them here. self._delete_allocation_after_move( context, instance, migration) + # 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 92d536b9b2c5..88c48b8fa713 100644 --- a/nova/tests/functional/test_server_group.py +++ b/nova/tests/functional/test_server_group.py @@ -371,7 +371,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') @@ -400,23 +400,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 c28737467fbe..3eaff8acb61d 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -7634,7 +7634,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') @@ -7646,7 +7647,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase, @mock.patch.object(self.instance, 'save') def do_confirm_resize(mock_save, mock_drop, mock_delete, 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._mock_rt() self.instance.migration_context = objects.MigrationContext( new_pci_devices=None, @@ -7663,6 +7665,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()