From 533ca2c99c454c171f2b8d6577a39bb7be6376e6 Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Thu, 16 Dec 2021 22:25:27 +0100 Subject: [PATCH] [Functional] Fix expected number of the enqueue_state_change calls In the HA router's keepalived state change monitor tests, it was expected that enqueue_state_change method will be called 3 or 4 times. But after some changes in the keepalived_state_change monitor which were done some time ago, it may be now that it will be called just 2 or 3 times: - 2 when initial status will be "primary" and it will be just transition to "backup", - 3 when initial status will be "backup", then it will transition to "primary" and finally to "backup" again. To reflect those 2 possibilities, test was changed that it will expect 2 or 3 calls and will check only that last 2 will be always transition to "primary" and then to "backup". Additionally this patch adds some extra logging in that test so it will be easier to check what was going on in that test. Closes-Bug: #1954751 Change-Id: Ib5de7e65839f52c35c43801969e3f0c16dead5bb (cherry picked from commit c6a6c5ae127a97856c880da3f82257977a06a571) --- neutron/tests/functional/agent/l3/framework.py | 3 +++ .../tests/functional/agent/l3/test_ha_router.py | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/neutron/tests/functional/agent/l3/framework.py b/neutron/tests/functional/agent/l3/framework.py index f22f1c00836..e437725b6b4 100644 --- a/neutron/tests/functional/agent/l3/framework.py +++ b/neutron/tests/functional/agent/l3/framework.py @@ -45,6 +45,8 @@ from neutron.tests.common import net_helpers from neutron.tests.functional import base +LOG = logging.getLogger(__name__) + _uuid = uuidutils.generate_uuid OVS_INTERFACE_DRIVER = 'neutron.agent.linux.interface.OVSInterfaceDriver' @@ -169,6 +171,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase): qos_policy_id=qos_policy_id) def change_router_state(self, router_id, state): + LOG.debug("Router %s state changed to '%s'", router_id, state) ri = self.agent.router_info.get(router_id) if not ri: self.fail('Router %s is not present in the L3 agent' % router_id) diff --git a/neutron/tests/functional/agent/l3/test_ha_router.py b/neutron/tests/functional/agent/l3/test_ha_router.py index 4fa166900eb..447d945e905 100644 --- a/neutron/tests/functional/agent/l3/test_ha_router.py +++ b/neutron/tests/functional/agent/l3/test_ha_router.py @@ -17,6 +17,7 @@ import copy from unittest import mock from neutron_lib import constants +from oslo_log import log as logging from oslo_utils import netutils import testtools @@ -29,6 +30,9 @@ from neutron.tests.common import net_helpers from neutron.tests.functional.agent.l3 import framework +LOG = logging.getLogger(__name__) + + class L3HATestCase(framework.L3AgentTestFramework): def test_ha_router_update_floatingip_statuses(self): @@ -46,11 +50,13 @@ class L3HATestCase(framework.L3AgentTestFramework): self.fail_ha_router(router) common_utils.wait_until_true(lambda: router.ha_state == 'backup') - common_utils.wait_until_true(lambda: - (enqueue_mock.call_count == 3 or enqueue_mock.call_count == 4)) + def enqueue_call_count_match(): + LOG.debug("enqueue_mock called %s times.", enqueue_mock.call_count) + return enqueue_mock.call_count in [2, 3] + + common_utils.wait_until_true(enqueue_call_count_match) calls = [args[0] for args in enqueue_mock.call_args_list] - self.assertEqual((router.router_id, 'backup'), calls[0]) - self.assertEqual((router.router_id, 'primary'), calls[1]) + self.assertEqual((router.router_id, 'primary'), calls[-2]) self.assertEqual((router.router_id, 'backup'), calls[-1]) def _expected_rpc_report(self, expected):