[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.

Additionally in that patch there is "master" instead of "primary" used
for router state.

Conflicts:
    neutron/tests/functional/agent/l3/test_dvr_router.py

Closes-Bug: #1939507
Change-Id: Ibd8f78fc822b04965c6a79b57b13be364934f64f
(cherry picked from commit b8ef8e722a)
This commit is contained in:
Slawek Kaplonski 2021-09-09 15:10:40 +02:00 committed by Bernard Cafarelli
parent 68b7aaf500
commit 3ce22c7e47
2 changed files with 13 additions and 0 deletions

View File

@ -1591,8 +1591,12 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework):
master, backup = self._get_master_and_slave_routers(
router1, router2, check_external_device=False)
utils.wait_until_true(lambda: master.ha_state == 'master')
utils.wait_until_true(lambda: backup.ha_state == 'backup')
self._assert_ip_addresses_in_dvr_ha_snat_namespace_with_fip(master)
self._assert_no_ip_addresses_in_dvr_ha_snat_namespace_with_fip(backup)
self.fail_ha_router(master)
utils.wait_until_true(lambda: backup.ha_state == 'master')
@ -1617,6 +1621,9 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework):
master, backup = self._get_master_and_slave_routers(
router1, router2, check_external_device=False)
utils.wait_until_true(lambda: master.ha_state == 'master')
utils.wait_until_true(lambda: backup.ha_state == 'backup')
self._assert_ip_addresses_in_dvr_ha_snat_namespace(master)
self._assert_no_ip_addresses_in_dvr_ha_snat_namespace(backup)

View File

@ -297,6 +297,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 == 'master')
self.fail_ha_router(router)
common_utils.wait_until_true(lambda: router.ha_state == 'backup')
@ -438,6 +439,11 @@ class L3HATestFailover(framework.L3AgentTestFramework):
self._assert_ipv6_accept_ra(slave_router, False)
self._assert_ipv6_forwarding(slave_router, False, False)
common_utils.wait_until_true(
lambda: master_router.ha_state == 'master')
common_utils.wait_until_true(
lambda: slave_router.ha_state == 'backup')
self.fail_ha_router(router1)
# NOTE: passing slave_router as first argument, because we expect