From 7025c98d813dd281ecc90b74e66f794b6b775d1a Mon Sep 17 00:00:00 2001 From: zitingguo-ms Date: Tue, 13 May 2025 18:48:34 +0800 Subject: [PATCH] Fix PortChannel name matching in verify_attr_change to handle leading spaces (#18301) What is the motivation for this PR? test_portchannel_interface_tc2_attributes failed with the following error: if attr == "mtu": output = duthost.shell("show interfaces status | grep -w '^{}' | awk '{{print $4}}'".format(po_name)) > pytest_assert(output['stdout'] == value, "{} attribute {} failed to change to {}".format(po_name, attr, value)) E Failed: PortChannel102 attribute mtu failed to change to 3324 This is due to cmd "show interfaces status | grep -w '^{}' | awk '{{print $4}}'" failed to filter out the correct PortChannel interface line when the PortChannel name is indented with spaces: PortChannel102 N/A 100G 9100 N/A N/A routed up up N/A N/A PortChannel104 N/A 100G 9100 N/A N/A routed up up N/A N/A PortChannel106 N/A 100G 9100 N/A N/A routed up up N/A N/A PortChannel108 N/A 100G 9100 N/A N/A routed up up N/A N/A PortChannel109 N/A 100G 9100 N/A N/A routed up up N/A N/A PortChannel1010 N/A 100G 9100 N/A N/A routed up up N/A N/A PortChannel1011 N/A 100G 9100 N/A N/A routed up up N/A N/A PortChannel1012 N/A 100G 9100 N/A N/A routed up up N/A N/A This PR updates the verify_attr_change function in test_portchannel_interface.py to correctly handle leading spaces in the PortChannel name when parsing interface status output. How did you do it? Modified the grep pattern from '^{}' to ^[[:space:]]*{} to match interface lines with leading spaces robustly. How did you verify/test it? Run generic_config_updater/test_portchannel_interface.py::test_portchannel_interface_tc2_attributes manually on DUT. generic_config_updater/test_portchannel_interface.py::test_portchannel_interface_tc2_attributes PASSED --- tests/generic_config_updater/test_portchannel_interface.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/generic_config_updater/test_portchannel_interface.py b/tests/generic_config_updater/test_portchannel_interface.py index 288bab0c1bb..047de48b439 100644 --- a/tests/generic_config_updater/test_portchannel_interface.py +++ b/tests/generic_config_updater/test_portchannel_interface.py @@ -247,7 +247,12 @@ def verify_attr_change(duthost, po_name, attr, value): ... """ if attr == "mtu": - output = duthost.shell("show interfaces status | grep -w '^{}' | awk '{{print $4}}'".format(po_name)) + cmd = ( + "show interfaces status | " + "grep -w '^[[:space:]]*{}' | " + "awk '{{print $4}}'" + ).format(po_name) + output = duthost.shell(cmd) pytest_assert(output['stdout'] == value, "{} attribute {} failed to change to {}".format(po_name, attr, value)) elif attr == "min_links":