Skip to content

Commit 82f6b32

Browse files
committed
Fix test_neighbor_mac on t1-lag and t1-64-lag
A recent change sets this test to t1-only: sonic-net#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 eac47d2 commit 82f6b32

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

tests/arp/test_neighbor_mac.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import logging
23
import pytest
34
import time
@@ -35,15 +36,41 @@ def interfaceConfig(self, duthosts, rand_one_dut_hostname):
3536
None
3637
"""
3738
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")
4139

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

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

0 commit comments

Comments
 (0)