From 44c47421785ba07d4b238bba06eacc42827c84ab Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Wed, 25 Mar 2020 17:38:14 +0100 Subject: [PATCH] Reproduce bug 1869050 This patch adds a functional test that reproduce the bug when stale scheduler instance info prevents booting server with anti-affinity. Change-Id: If485330b48ae2671651aafabc93f92a8999f7ca2 Related-Bug: #1869050 (cherry picked from commit b52c483308f32f3744dd8a5df424b9f518c13155) (cherry picked from commit 016eeec9841116bbbbc6c3019850c18012e3781a) (cherry picked from commit 66e4d8218133a5e4a68f68a3017446cb585675c4) (cherry picked from commit 2a15e0096bc87234a930bb75b73d4874f0f7ec87) --- nova/tests/functional/test_server_group.py | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/nova/tests/functional/test_server_group.py b/nova/tests/functional/test_server_group.py index e6268e6bc0db..f3e43bc44131 100644 --- a/nova/tests/functional/test_server_group.py +++ b/nova/tests/functional/test_server_group.py @@ -369,6 +369,53 @@ 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): + # Start additional host to test migration with anti-affinity + compute3 = self.start_service('compute', host='host3') + + # make sure that compute syncing instance info to scheduler + # this tells the scheduler that it can expect such updates periodically + # and don't have to look into the db for it at the start of each + # scheduling + for compute in [self.compute, self.compute2, compute3]: + compute.manager._sync_scheduler_instance_info( + context.get_admin_context()) + + created_group = self.api.post_server_groups(self.anti_affinity) + servers = self._boot_servers_to_group(created_group) + + post = {'migrate': {}} + self.admin_api.post_server_action(servers[1]['id'], post) + migrated_server = self._wait_for_state_change( + self.admin_api, servers[1], 'VERIFY_RESIZE') + + self.assertNotEqual(servers[0]['OS-EXT-SRV-ATTR:host'], + migrated_server['OS-EXT-SRV-ATTR:host']) + + # We have 3 hosts, so after the move is confirmed one of the hosts + # should be considered empty so we could boot a 3rd server on that host + post = {'confirmResize': {}} + 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, 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)) + def test_resize_to_same_host_with_anti_affinity(self): self.flags(allow_resize_to_same_host=True) created_group = self.api.post_server_groups(self.anti_affinity)