From 82f6b32ddf6bca3b93cc21e4451c4bae9c800ccd Mon Sep 17 00:00:00 2001 From: Boyang Yu Date: Fri, 14 Jun 2024 15:55:48 -0700 Subject: [PATCH 1/4] Fix test_neighbor_mac on t1-lag and t1-64-lag A recent change sets this test to t1-only: https://github.com/sonic-net/sonic-mgmt/pull/12952 The test can pass on topo t1 without any change. For t1-lag or t1-64-lag, the Ethernet0 to test is in portchannel, so IP address cannot be set to it. The fix here is to delete the intf from the portchanenl before testing it. --- tests/arp/test_neighbor_mac.py | 43 +++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/tests/arp/test_neighbor_mac.py b/tests/arp/test_neighbor_mac.py index 0b8bf3f15b0..8ece1dc0c57 100644 --- a/tests/arp/test_neighbor_mac.py +++ b/tests/arp/test_neighbor_mac.py @@ -1,3 +1,4 @@ +import contextlib import logging import pytest import time @@ -35,15 +36,41 @@ def interfaceConfig(self, duthosts, rand_one_dut_hostname): None """ duthost = duthosts[rand_one_dut_hostname] - logger.info("Configure the DUT interface, start interface, add IP address") - self.__startInterface(duthost) - self.__configureInterfaceIp(duthost, action="add") - yield - - logger.info("Restore the DUT interface config, remove IP address") - self.__configureInterfaceIp(duthost, action="remove") - self.__shutdownInterface(duthost) + intfStatus = duthost.show_interface(command="status")["ansible_facts"]["int_status"] + if self.DUT_ETH_IF not in intfStatus: + pytest.skip('{} not found'.format(self.DUT_ETH_IF)) + + status = intfStatus[self.DUT_ETH_IF] + if "up" not in status["oper_state"]: + pytest.skip('{} is down'.format(self.DUT_ETH_IF)) + + portchannel = status["vlan"] if "PortChannel" in status["vlan"] else None + + @contextlib.contextmanager + def removeFromPortChannel(duthost, portchannel, intf): + try: + if portchannel: + duthost.command("sudo config portchannel member del {} {}".format(portchannel, intf)) + time.sleep(2) + intfStatus = duthost.show_interface(command="status")["ansible_facts"]["int_status"] + if 'routed' not in intfStatus[intf]["vlan"]: + pytest.skip('{} is not in routed status'.format(self.DUT_ETH_IF)) + yield + finally: + if portchannel: + duthost.command("sudo config portchannel member add {} {}".format(portchannel, intf)) + + with removeFromPortChannel(duthost, portchannel, self.DUT_ETH_IF): + logger.info("Configure the DUT interface, start interface, add IP address") + self.__startInterface(duthost) + self.__configureInterfaceIp(duthost, action="add") + + yield + + logger.info("Restore the DUT interface config, remove IP address") + self.__configureInterfaceIp(duthost, action="remove") + self.__shutdownInterface(duthost) @pytest.fixture(params=[0, 1]) def macIndex(self, request): From 4b536a55ede71f7f01965a9833c2a9fc37d5e3f5 Mon Sep 17 00:00:00 2001 From: Boyang Yu Date: Fri, 14 Jun 2024 16:15:59 -0700 Subject: [PATCH 2/4] Assert when not in routed status --- tests/arp/test_neighbor_mac.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/arp/test_neighbor_mac.py b/tests/arp/test_neighbor_mac.py index 8ece1dc0c57..82a6e1c0f92 100644 --- a/tests/arp/test_neighbor_mac.py +++ b/tests/arp/test_neighbor_mac.py @@ -54,8 +54,7 @@ def removeFromPortChannel(duthost, portchannel, intf): duthost.command("sudo config portchannel member del {} {}".format(portchannel, intf)) time.sleep(2) intfStatus = duthost.show_interface(command="status")["ansible_facts"]["int_status"] - if 'routed' not in intfStatus[intf]["vlan"]: - pytest.skip('{} is not in routed status'.format(self.DUT_ETH_IF)) + pytest_assert('routed' in intfStatus[intf]["vlan"], '{} not in routed status'.format(intf)) yield finally: if portchannel: From 100cbddb2d6c24b51d15d5b7de980d36ed03cf19 Mon Sep 17 00:00:00 2001 From: Boyang Yu Date: Wed, 19 Jun 2024 14:10:40 -0700 Subject: [PATCH 3/4] Change sleep to wait_until --- tests/arp/test_neighbor_mac.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/arp/test_neighbor_mac.py b/tests/arp/test_neighbor_mac.py index 82a6e1c0f92..25d0417566f 100644 --- a/tests/arp/test_neighbor_mac.py +++ b/tests/arp/test_neighbor_mac.py @@ -4,6 +4,7 @@ import time from tests.common.helpers.assertions import pytest_assert +from tests.common.utilities import wait_until logger = logging.getLogger(__name__) @@ -52,9 +53,8 @@ def removeFromPortChannel(duthost, portchannel, intf): try: if portchannel: duthost.command("sudo config portchannel member del {} {}".format(portchannel, intf)) - time.sleep(2) - intfStatus = duthost.show_interface(command="status")["ansible_facts"]["int_status"] - pytest_assert('routed' in intfStatus[intf]["vlan"], '{} not in routed status'.format(intf)) + pytest_assert(wait_until(10, 1, 0, lambda: 'routed' in duthost.show_interface(command="status")["ansible_facts"]["int_status"][intf]["vlan"]), + '{} is not in routed status'.format(intf)) yield finally: if portchannel: From 96f18cdf3e4a6a3c488651808d82a0653526f7a1 Mon Sep 17 00:00:00 2001 From: Boyang Yu Date: Thu, 20 Jun 2024 11:47:27 -0700 Subject: [PATCH 4/4] Fix format issue of line too long --- tests/arp/test_neighbor_mac.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/arp/test_neighbor_mac.py b/tests/arp/test_neighbor_mac.py index 25d0417566f..e0347bdd773 100644 --- a/tests/arp/test_neighbor_mac.py +++ b/tests/arp/test_neighbor_mac.py @@ -53,8 +53,12 @@ def removeFromPortChannel(duthost, portchannel, intf): try: if portchannel: duthost.command("sudo config portchannel member del {} {}".format(portchannel, intf)) - pytest_assert(wait_until(10, 1, 0, lambda: 'routed' in duthost.show_interface(command="status")["ansible_facts"]["int_status"][intf]["vlan"]), - '{} is not in routed status'.format(intf)) + pytest_assert(wait_until( + 10, 1, 0, + lambda: 'routed' in duthost.show_interface(command="status") + ["ansible_facts"]["int_status"][intf]["vlan"]), + '{} is not in routed status'.format(intf) + ) yield finally: if portchannel: