Skip to content

Commit 35efc04

Browse files
authored
Fix test_neighbor_mac on t1-lag and t1-64-lag (#13314)
* Fix test_neighbor_mac on t1-lag and t1-64-lag A recent change sets this test to t1-only: #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.
1 parent 2269efe commit 35efc04

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

tests/arp/test_neighbor_mac.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import contextlib
12
import logging
23
import pytest
34
import time
45

56
from tests.common.helpers.assertions import pytest_assert
7+
from tests.common.utilities import wait_until
68

79
logger = logging.getLogger(__name__)
810

@@ -35,15 +37,43 @@ def interfaceConfig(self, duthosts, rand_one_dut_hostname):
3537
None
3638
"""
3739
duthost = duthosts[rand_one_dut_hostname]
38-
logger.info("Configure the DUT interface, start interface, add IP address")
39-
self.__startInterface(duthost)
40-
self.__configureInterfaceIp(duthost, action="add")
4140

42-
yield
43-
44-
logger.info("Restore the DUT interface config, remove IP address")
45-
self.__configureInterfaceIp(duthost, action="remove")
46-
self.__shutdownInterface(duthost)
41+
intfStatus = duthost.show_interface(command="status")["ansible_facts"]["int_status"]
42+
if self.DUT_ETH_IF not in intfStatus:
43+
pytest.skip('{} not found'.format(self.DUT_ETH_IF))
44+
45+
status = intfStatus[self.DUT_ETH_IF]
46+
if "up" not in status["oper_state"]:
47+
pytest.skip('{} is down'.format(self.DUT_ETH_IF))
48+
49+
portchannel = status["vlan"] if "PortChannel" in status["vlan"] else None
50+
51+
@contextlib.contextmanager
52+
def removeFromPortChannel(duthost, portchannel, intf):
53+
try:
54+
if portchannel:
55+
duthost.command("sudo config portchannel member del {} {}".format(portchannel, intf))
56+
pytest_assert(wait_until(
57+
10, 1, 0,
58+
lambda: 'routed' in duthost.show_interface(command="status")
59+
["ansible_facts"]["int_status"][intf]["vlan"]),
60+
'{} is not in routed status'.format(intf)
61+
)
62+
yield
63+
finally:
64+
if portchannel:
65+
duthost.command("sudo config portchannel member add {} {}".format(portchannel, intf))
66+
67+
with removeFromPortChannel(duthost, portchannel, self.DUT_ETH_IF):
68+
logger.info("Configure the DUT interface, start interface, add IP address")
69+
self.__startInterface(duthost)
70+
self.__configureInterfaceIp(duthost, action="add")
71+
72+
yield
73+
74+
logger.info("Restore the DUT interface config, remove IP address")
75+
self.__configureInterfaceIp(duthost, action="remove")
76+
self.__shutdownInterface(duthost)
4777

4878
@pytest.fixture(params=[0, 1])
4979
def macIndex(self, request):

0 commit comments

Comments
 (0)