|
15 | 15 | from tests.common.helpers.pfcwd_helper import send_background_traffic, verify_pfc_storm_in_expected_state, parser_show_pfcwd_stat # noqa E501 |
16 | 16 | from tests.common.utilities import wait_until |
17 | 17 | from tests.common.cisco_data import is_cisco_device |
| 18 | +from tests.common import config_reload |
18 | 19 |
|
19 | 20 | pytestmark = [ |
20 | 21 | pytest.mark.topology("t0", "t1") |
@@ -298,6 +299,43 @@ def send_rx_ingress(self, action, verify): |
298 | 299 |
|
299 | 300 | class TestPfcwdFunc(SetupPfcwdFunc): |
300 | 301 | """ 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 | + |
301 | 339 | def storm_detect_path(self, dut, port, action): |
302 | 340 | """ |
303 | 341 | 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 |
476 | 514 |
|
477 | 515 | # for idx, port in enumerate(self.ports): |
478 | 516 | port = list(self.ports.keys())[0] |
| 517 | + |
| 518 | + self.__shutdown_lag_members(duthost, port) |
| 519 | + |
479 | 520 | logger.info("--- Testing various Pfcwd actions on {} ---".format(port)) |
480 | 521 | self.setup_test_params(port, setup_info['vlan'], init=True) |
481 | 522 | self.traffic_inst = SendVerifyTraffic( |
@@ -506,3 +547,4 @@ def test_pfcwd_show_stat(self, request, setup_pfc_test, setup_dut_test_params, e |
506 | 547 | self.storm_hndle.stop_storm() |
507 | 548 | logger.info("--- Stop PFC WD ---") |
508 | 549 | self.dut.command("pfcwd stop") |
| 550 | + self.__restore_original_config(duthost, port) |
0 commit comments