Skip to content

Commit 14dda64

Browse files
Fix flakiness in pfcwd/test_pfcwd_cli.py (#17411) (#17619)
What is the motivation for this PR? Sometimes the test ends up picking an egress interface which happens to be a member of a LAG. If the LAG has multiple members and only one of them is stormed the drop/forwards expectations don't take into account lag hashing. Some of the traffic is hashed to another LAG member which is not being stormed and no drops will occur. How did you do it? The proposed fix is to shutdown the remaining LAG members. How did you verify/test it? Tested on Arista-7260CX3 with dualtor-120 topology and 202411 image. Co-authored-by: Vivek Verma <[email protected]>
1 parent 54633cb commit 14dda64

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/pfcwd/test_pfcwd_cli.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from tests.common.helpers.pfcwd_helper import send_background_traffic, verify_pfc_storm_in_expected_state, parser_show_pfcwd_stat # noqa E501
1616
from tests.common.utilities import wait_until
1717
from tests.common.cisco_data import is_cisco_device
18+
from tests.common import config_reload
1819

1920
pytestmark = [
2021
pytest.mark.topology("t0", "t1")
@@ -298,6 +299,43 @@ def send_rx_ingress(self, action, verify):
298299

299300
class TestPfcwdFunc(SetupPfcwdFunc):
300301
""" Test PFC function and supporting methods """
302+
def __shutdown_lag_members(self, duthost, selected_port):
303+
304+
if self.ports[selected_port]['test_port_type'] != 'portchannel':
305+
return
306+
307+
config_facts = duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts']
308+
portChannels = config_facts['PORTCHANNEL_MEMBER']
309+
portChannel = None
310+
portChannelMembers = None
311+
for intf in portChannels:
312+
if selected_port in portChannels[intf]:
313+
portChannel = intf
314+
portChannelMembers = portChannels[intf]
315+
break
316+
317+
cmd_data = f'.PORTCHANNEL.{portChannel}.min_links = "1"'
318+
319+
for port in portChannelMembers:
320+
if port == selected_port:
321+
continue
322+
cmd_data += f' | .PORT.{port}.admin_status="down"'
323+
324+
cmd = f"""jq '{cmd_data}' /etc/sonic/config_db.json > /tmp/config_db.json"""
325+
326+
duthost.command("cp /etc/sonic/config_db.json /tmp/config_db_backup.json", _uses_shell=True)
327+
duthost.command(cmd, _uses_shell=True)
328+
duthost.command("sudo cp /tmp/config_db.json /etc/sonic/config_db.json", _uses_shell=True)
329+
config_reload(duthost, config_source='config_db', safe_reload=True, check_intf_up_ports=True, wait_for_bgp=True)
330+
331+
def __restore_original_config(self, duthost, selected_port):
332+
333+
if self.ports[selected_port]['test_port_type'] != 'portchannel':
334+
return
335+
336+
duthost.command("sudo mv /tmp/config_db_backup.json /etc/sonic/config.json", _uses_shell=True)
337+
config_reload(duthost, config_source='config_db', safe_reload=True, check_intf_up_ports=True, wait_for_bgp=True)
338+
301339
def storm_detect_path(self, dut, port, action):
302340
"""
303341
Storm detection action and associated verifications
@@ -476,6 +514,9 @@ def test_pfcwd_show_stat(self, request, setup_pfc_test, setup_dut_test_params, e
476514

477515
# for idx, port in enumerate(self.ports):
478516
port = list(self.ports.keys())[0]
517+
518+
self.__shutdown_lag_members(duthost, port)
519+
479520
logger.info("--- Testing various Pfcwd actions on {} ---".format(port))
480521
self.setup_test_params(port, setup_info['vlan'], init=True)
481522
self.traffic_inst = SendVerifyTraffic(
@@ -506,3 +547,4 @@ def test_pfcwd_show_stat(self, request, setup_pfc_test, setup_dut_test_params, e
506547
self.storm_hndle.stop_storm()
507548
logger.info("--- Stop PFC WD ---")
508549
self.dut.command("pfcwd stop")
550+
self.__restore_original_config(duthost, port)

0 commit comments

Comments
 (0)