Skip to content

gnxi commands on PTF fails when we have "-" in key [Blocking Openconfig sonic-mgmt tests]#25209

Merged
yxieca merged 1 commit intosonic-net:masterfrom
Verma-Anukul:ptf-pygnmi-hyphen-fix
Mar 20, 2026
Merged

gnxi commands on PTF fails when we have "-" in key [Blocking Openconfig sonic-mgmt tests]#25209
yxieca merged 1 commit intosonic-net:masterfrom
Verma-Anukul:ptf-pygnmi-hyphen-fix

Conversation

@Verma-Anukul
Copy link
Contributor

@Verma-Anukul Verma-Anukul commented Jan 27, 2026

Why I did it

  1. When we do get request from pygnmi for the xpaths where keyname has "-" character, pygnmi returns error

  2. 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:
Work item tracking

How I did it

  1. Ported patch from gnxi upstream to sonic-buildimage
    Fix RegEx for xpath leaf-list keys which include a "-" character. google/gnxi#240

  2. Fix the python syntax issues

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

  1. Test patch application
  2. Run pygnmi command with key-name with "-"
  3. 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)

@Verma-Anukul Verma-Anukul requested a review from lguohan as a code owner January 27, 2026 12:46
@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Verma-Anukul
Copy link
Contributor Author

@StormLiangMS @qiluo-msft @ganglyu @hdwhdw @liuh-80 @zbud-msft

Please review this PR

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Verma-Anukul
Copy link
Contributor Author

@StormLiangMS @qiluo-msft @ganglyu @hdwhdw @liuh-80 @zbud-msft

Please review this PR

@Verma-Anukul
Copy link
Contributor Author

@StormLiangMS @qiluo-msft @ganglyu @hdwhdw @liuh-80 @zbud-msft

Please review this PR

hdwhdw
hdwhdw previously approved these changes Mar 10, 2026
@hdwhdw
Copy link
Contributor

hdwhdw commented Mar 10, 2026

@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
Copy link
Contributor Author

@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?

https://github.com/sonic-net/sonic-buildimage/blob/master/dockers/docker-ptf/Dockerfile.j2#L331
ptf is currently using commit from Jul 2, 2020 base.
So for now to unblock some new tests we have added patch on top of the same.

Will discuss if we can use latest gnxi repo with Google and other folks.

@Verma-Anukul
Copy link
Contributor Author

@lguohan @qiluo-msft
please help in merging this PR

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Verma-Anukul Verma-Anukul requested a review from hdwhdw March 18, 2026 09:50
@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@Verma-Anukul
Copy link
Contributor Author

@wangxin @auspham @hdwhdw @lguohan @zbud-msft @liuh-80 @ganglyu @qiluo-msft @StormLiangMS

Please review and merge this PR

@Verma-Anukul 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
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@hdwhdw
Copy link
Contributor

hdwhdw commented Mar 19, 2026

Also FYI sonic-net/sonic-gnmi#562

@Verma-Anukul
Copy link
Contributor Author

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 25209 in repo sonic-net/sonic-buildimage

@Verma-Anukul
Copy link
Contributor Author

@qiluo-msft @wangxin
Please help in merging this PR

@hdwhdw
Copy link
Contributor

hdwhdw commented Mar 20, 2026

@Verma-Anukul rerunning failed pipeline.

@Verma-Anukul
Copy link
Contributor Author

@Verma-Anukul rerunning failed pipeline.

@hdwhdw
Re-triggered and passed now

@hdwhdw
Copy link
Contributor

hdwhdw commented Mar 20, 2026

@yxieca @qiluo-msft to merge

@yxieca yxieca merged commit fb38a74 into sonic-net:master Mar 20, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants