From 39a2e5e4f2659f83392b15285c35febb56809888 Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Thu, 9 Sep 2021 15:10:40 +0200 Subject: [PATCH] [Functional] Wait for the initial state of ha router before test In functional tests of the HA and DVR HA routers, when e.g. failover is tested, we should always wait for routers to be in the expected initial state (primary or backup) before router failover will actually be done. Without that, we may hit race condition when initial router's state is enqueued but not processed yet and then state will be changed thus no any action will be performed by L3 agent and test may fail. Closes-Bug: #1939507 Change-Id: Ibd8f78fc822b04965c6a79b57b13be364934f64f (cherry picked from commit b8ef8e722af761dd394064ab70e159aa05639e56) --- neutron/tests/functional/agent/l3/test_dvr_router.py | 7 +++++++ neutron/tests/functional/agent/l3/test_ha_router.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/neutron/tests/functional/agent/l3/test_dvr_router.py b/neutron/tests/functional/agent/l3/test_dvr_router.py index e250f86961c..5f5a17e817c 100644 --- a/neutron/tests/functional/agent/l3/test_dvr_router.py +++ b/neutron/tests/functional/agent/l3/test_dvr_router.py @@ -1590,8 +1590,12 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework): primary, backup = self._get_primary_and_backup_routers( router1, router2, check_external_device=False) + utils.wait_until_true(lambda: primary.ha_state == 'primary') + utils.wait_until_true(lambda: backup.ha_state == 'backup') + self._assert_ip_addresses_in_dvr_ha_snat_namespace_with_fip(primary) self._assert_no_ip_addresses_in_dvr_ha_snat_namespace_with_fip(backup) + self.fail_ha_router(primary) utils.wait_until_true(lambda: backup.ha_state == 'primary') @@ -1616,6 +1620,9 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework): primary, backup = self._get_primary_and_backup_routers( router1, router2, check_external_device=False) + utils.wait_until_true(lambda: primary.ha_state == 'primary') + utils.wait_until_true(lambda: backup.ha_state == 'backup') + self._assert_ip_addresses_in_dvr_ha_snat_namespace(primary) self._assert_no_ip_addresses_in_dvr_ha_snat_namespace(backup) diff --git a/neutron/tests/functional/agent/l3/test_ha_router.py b/neutron/tests/functional/agent/l3/test_ha_router.py index eb87550eec0..e20f4bed76d 100644 --- a/neutron/tests/functional/agent/l3/test_ha_router.py +++ b/neutron/tests/functional/agent/l3/test_ha_router.py @@ -295,6 +295,7 @@ class L3HATestCase(framework.L3AgentTestFramework): def test_delete_external_gateway_on_standby_router(self): router_info = self.generate_router_info(enable_ha=True) router = self.manage_router(self.agent, router_info) + common_utils.wait_until_true(lambda: router.ha_state == 'primary') self.fail_ha_router(router) common_utils.wait_until_true(lambda: router.ha_state == 'backup') @@ -434,6 +435,11 @@ class L3HATestFailover(framework.L3AgentTestFramework): self._assert_ipv6_accept_ra(backup_router, False) self._assert_ipv6_forwarding(backup_router, False, False) + common_utils.wait_until_true( + lambda: primary_router.ha_state == 'primary') + common_utils.wait_until_true( + lambda: backup_router.ha_state == 'backup') + self.fail_ha_router(router1) # NOTE: passing backup_router as first argument, because we expect