Skip to content

Commit b1b95dc

Browse files
Gfrom2016mssonicbld
authored andcommitted
Fix PortChannel name matching in verify_attr_change to handle leading spaces (sonic-net#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
1 parent 7461bf3 commit b1b95dc

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

tests/generic_config_updater/test_portchannel_interface.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,12 @@ def verify_attr_change(duthost, po_name, attr, value):
247247
...
248248
"""
249249
if attr == "mtu":
250-
output = duthost.shell("show interfaces status | grep -w '^{}' | awk '{{print $4}}'".format(po_name))
250+
cmd = (
251+
"show interfaces status | "
252+
"grep -w '^[[:space:]]*{}' | "
253+
"awk '{{print $4}}'"
254+
).format(po_name)
255+
output = duthost.shell(cmd)
251256

252257
pytest_assert(output['stdout'] == value, "{} attribute {} failed to change to {}".format(po_name, attr, value))
253258
elif attr == "min_links":

0 commit comments

Comments
 (0)