diff --git a/tests/pfcwd/test_pfcwd_cli.py b/tests/pfcwd/test_pfcwd_cli.py index 59ed2966947..218867cc2b6 100644 --- a/tests/pfcwd/test_pfcwd_cli.py +++ b/tests/pfcwd/test_pfcwd_cli.py @@ -15,6 +15,7 @@ from tests.common.helpers.pfcwd_helper import send_background_traffic, verify_pfc_storm_in_expected_state, parser_show_pfcwd_stat # noqa E501 from tests.common.utilities import wait_until from tests.common.cisco_data import is_cisco_device +from tests.common import config_reload pytestmark = [ pytest.mark.topology("t0", "t1") @@ -298,6 +299,43 @@ def send_rx_ingress(self, action, verify): class TestPfcwdFunc(SetupPfcwdFunc): """ Test PFC function and supporting methods """ + def __shutdown_lag_members(self, duthost, selected_port): + + if self.ports[selected_port]['test_port_type'] != 'portchannel': + return + + config_facts = duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts'] + portChannels = config_facts['PORTCHANNEL_MEMBER'] + portChannel = None + portChannelMembers = None + for intf in portChannels: + if selected_port in portChannels[intf]: + portChannel = intf + portChannelMembers = portChannels[intf] + break + + cmd_data = f'.PORTCHANNEL.{portChannel}.min_links = "1"' + + for port in portChannelMembers: + if port == selected_port: + continue + cmd_data += f' | .PORT.{port}.admin_status="down"' + + cmd = f"""jq '{cmd_data}' /etc/sonic/config_db.json > /tmp/config_db.json""" + + duthost.command("cp /etc/sonic/config_db.json /tmp/config_db_backup.json", _uses_shell=True) + duthost.command(cmd, _uses_shell=True) + duthost.command("sudo cp /tmp/config_db.json /etc/sonic/config_db.json", _uses_shell=True) + config_reload(duthost, config_source='config_db', safe_reload=True, check_intf_up_ports=True, wait_for_bgp=True) + + def __restore_original_config(self, duthost, selected_port): + + if self.ports[selected_port]['test_port_type'] != 'portchannel': + return + + duthost.command("sudo mv /tmp/config_db_backup.json /etc/sonic/config.json", _uses_shell=True) + config_reload(duthost, config_source='config_db', safe_reload=True, check_intf_up_ports=True, wait_for_bgp=True) + def storm_detect_path(self, dut, port, action): """ 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 # for idx, port in enumerate(self.ports): port = list(self.ports.keys())[0] + + self.__shutdown_lag_members(duthost, port) + logger.info("--- Testing various Pfcwd actions on {} ---".format(port)) self.setup_test_params(port, setup_info['vlan'], init=True) self.traffic_inst = SendVerifyTraffic( @@ -506,3 +547,4 @@ def test_pfcwd_show_stat(self, request, setup_pfc_test, setup_dut_test_params, e self.storm_hndle.stop_storm() logger.info("--- Stop PFC WD ---") self.dut.command("pfcwd stop") + self.__restore_original_config(duthost, port)