[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
This commit is contained in:
Slawek Kaplonski 2021-09-09 15:10:40 +02:00
parent d1a89af312
commit b8ef8e722a
2 changed files with 13 additions and 0 deletions

View File

@ -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)

View File

@ -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')
@ -468,6 +469,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