diff --git a/tests/arp/test_neighbor_mac.py b/tests/arp/test_neighbor_mac.py index 0b8bf3f15b0..e0347bdd773 100644 --- a/tests/arp/test_neighbor_mac.py +++ b/tests/arp/test_neighbor_mac.py @@ -1,8 +1,10 @@ +import contextlib import logging import pytest import time from tests.common.helpers.assertions import pytest_assert +from tests.common.utilities import wait_until logger = logging.getLogger(__name__) @@ -35,15 +37,43 @@ 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)) + 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: + 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):