You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we do get request from pygnmi for the xpaths where keyname has "-" character, pygnmi returns error
Exception seen
raise Exception("GNMI Error:" + output['stderr'])
E Exception: GNMI Error:/root/gnxi/gnmi_cli_py/py_gnmicli.py:537: SyntaxWarning: "is not" with a literal. Did you mean "!="?
E if filter_event_regex is not "":
E /root/gnxi/gnmi_cli_py/py_gnmicli.py:539: SyntaxWarning: "is not" with a literal. Did you mean "!="?
E if len(match) is not 0:
root@docker-ptf:~# python /root/gnxi/gnmi_cli_py/py_gnmicli.py --timeout 30 -t 192.168.122.54 -p 8080 -xt oc-yang -m get --xpath "/openconfig-network-instance:network-instances/network-instance[name=Vrf4]/protocols/protocol[identifier=BGP][name=bgp]/bgp/neighbors/neighbor[neighbor-address=192.168.20.1]/"
Traceback (most recent call last):
File "/root/gnxi/gnmi_cli_py/py_gnmicli.py", line 652, in
<module>
main()
File "/root/gnxi/gnmi_cli_py/py_gnmicli.py", line 573, in
main
paths.append(_parse_path(_path_names(xpath)))
File "/root/gnxi/gnmi_cli_py/py_gnmicli.py", line 258, in
_parse_path
raise XpathError('xpath component parse error: %s' %
word)
__main__.XpathError: xpath component parse error:
neighbor[neighbor-address=192.168.20.1]
How to verify it
Test patch application
Run pygnmi command with key-name with "-"
Run sonic-mgmt gnmi tests
root@b260562538a8:~# python /root/gnxi/gnmi_cli_py/py_gnmicli.py --timeout 30 -t 10.89.171.137 -p 11865 -xt oc-yang -m get --xpath "/openconfig-network-instance:network-instances/network-instance[name=Vrf4]/protocols/protocol[identifier=BGP][name =bgp]/bgp/neighbors/neighbor[neighbor-address=192.168.20.1]/" -n
/root/gnxi/gnmi_cli_py/py_gnmicli.py:537: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if filter_event_regex is not "":
/root/gnxi/gnmi_cli_py/py_gnmicli.py:539: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if len(match) is not 0:
Traceback (most recent call last):
File "/root/gnxi/gnmi_cli_py/py_gnmicli.py", line 678, in <module>
main()
File "/root/gnxi/gnmi_cli_py/py_gnmicli.py", line 599, in main
paths.append(_parse_path(_path_names(xpath)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/gnxi/gnmi_cli_py/py_gnmicli.py", line 269, in _parse_path
raise XpathError('xpath component parse error: %s' % word)
XpathError: xpath component parse error: neighbor[neighbor-address=192.168.20.1]
root@b260562538a8:~#
root@b260562538a8:~#
root@b260562538a8:~# cd /root/gnxi/
root@b260562538a8:~/gnxi#
root@b260562538a8:~/gnxi# patch -p1 < 0009-Fix-regex-to-allow-hyphen-character-in-key-name.patch
patching file gnmi_cli_py/py_gnmicli.py
Hunk #1 succeeded at 56 (offset 4 lines).
root@b260562538a8:~/gnxi#
root@b260562538a8:~/gnxi# python /root/gnxi/gnmi_cli_py/py_gnmicli.py --timeout 30 -t 10.89.171.137 -p 11865 -xt oc-yang -m get --xpath "/openconfig-network-instance:network-instances/network-instance[name=Vrf4]/protocols/protocol[identifier=BGP][name =bgp]/bgp/neighbors/neighbor[neighbor-address=192.168.20.1]/" -n
/root/gnxi/gnmi_cli_py/py_gnmicli.py:537: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if filter_event_regex is not "":
/root/gnxi/gnmi_cli_py/py_gnmicli.py:539: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if len(match) is not 0:
Performing GetRequest, encoding=JSON_IETF to 10.89.171.137 with the following gNMI Path
-------------------------
[elem {
name: "openconfig-network-instance:network-instances"
}
elem {
name: "network-instance"
key {
key: "name"
value: "Vrf4"
}
}
elem {
name: "protocols"
}
elem {
name: "protocol"
key {
key: "identifier"
value: "BGP"
}
Which release branch to backport (provide reason below if selected)
202305
202311
202405
202411
202505
202511
Tested branch (Please provide the tested image version)
Description for the changelog
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)
@zbud-msft@Verma-Anukul do any of you know why we need to patch a 6 years old change as opposed to update the py_gnmicli.py (or whatever package containing it) to a newer version?
@zbud-msft@Verma-Anukul do any of you know why we need to patch a 6 years old change as opposed to update the py_gnmicli.py (or whatever package containing it) to a newer version?
Verma-Anukul
changed the title
Porting gnxi patch https://github.com/google/gnxi/pull/240 to sonic-buildimage
gnxi commands on PTF fails when we have "-" in key [Blocking Openconfig sonic-mgmt tests]
Mar 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why I did it
When we do get request from pygnmi for the xpaths where keyname has "-" character, pygnmi returns error
Exception seen
Work item tracking
How I did it
Ported patch from gnxi upstream to sonic-buildimage
Fix RegEx for xpath leaf-list keys which include a "-" character. google/gnxi#240
Fix the python syntax issues
How to verify it
Which release branch to backport (provide reason below if selected)
Tested branch (Please provide the tested image version)
Description for the changelog
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)