Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword missmatch on pre 23.4. Getting RpcError(bad element) returns #1349

Open
oskar-nystr opened this issue Nov 18, 2024 · 0 comments
Open

Comments

@oskar-nystr
Copy link

oskar-nystr commented Nov 18, 2024

Hello!
I have already found a solution for this problem. I thought I'd share my findings here to hopefully help someone else out and perhaps contribute to a bugfix.

The scenario:

What I've been trying to do is using this py-junos-eznc module to make "get_bfd_session_address({"format":"json"},session_addr=X.X.X.X)" calls towards my devices.Confusingly it worked towards some and not others.
I found it especially confusing considering other commands on the same devices worked, such as "get_bgp_information({"format":"json"},neighbor_address=X.X.X.X)"

I was able to identify the difference using "show bfd session address X.X.X.X | display xml rpc" on the nodes:
This is what I received back:

root@R1> show bfd session address X.X.X.X | display xml rpc <rpc-reply xmlns:junos="http://xml.juniper.net/junos/21.2R0/junos"> <rpc> <get-bfd-session-address> <session_addr>X.X.X.X</session_addr> </get-bfd-session-address> </rpc> <cli> <banner>{master}</banner> </cli> </rpc-reply>

compared on working devices
root@R2> show bfd session address X.X.X.X | display xml rpc <rpc-reply xmlns:junos="http://xml.juniper.net/junos/23.4R2-S2.1/junos"> <rpc> <get-bfd-session-address> <session-address>X.X.X.X</session-address> </get-bfd-session-address> </rpc> <cli> <banner>{master}</banner> </cli> </rpc-reply>

If you are attentive you should already have identified three differences between these devices.
Firstly, different software versions.
One running 21.2 and the other 23.4
Secondly, the address keyword is different betwween the two devices.
On R1 it's "session_addr" and on R2 it's "session-address".
And lastly, the big thing, is the hyphen ("-") vs the underscore ("_").

I compared in junipers xmlapi documentation and 23.4 is the first software version I could find that changed it from underscore to hyphen.
And actually, this seemingly editorial difference have a huge impact. The reason for this is because of function _RpcMetaExec._exec_rpc() in the py-junos-eznc

arg_name = re.sub("_", "-",arg_name)
This line will cause also the session_addr keyword to be changed and because the node expects "session_addr", sending session-addr will cause errors.

To solve my problem I added a line
arg_name = re.sub('-addr$', '_addr', arg_name)
just under the other line.. this solves my problem but probably something better can be though of.

https://apps.juniper.net/xmlapi/operational/?swversion=junos-23.4

This was the error I received back.
jnpr.junos.exception.RpcError: RpcError(severity: error, bad_element: session-addr, message: error: syntax error, expecting <invoke-on> error: syntax error, expecting <filter type="subtree"> or <filter type="subtree" />)

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

No branches or pull requests

1 participant