Skip to content

Fix napalm.junos_rpc get-config filter leaking the __kwarg__ marker (#65867)#69818

Open
ggiesen wants to merge 1 commit into
saltstack:3006.xfrom
ggiesen:fix-65867-junos-rpc-kwarg-leak
Open

Fix napalm.junos_rpc get-config filter leaking the __kwarg__ marker (#65867)#69818
ggiesen wants to merge 1 commit into
saltstack:3006.xfrom
ggiesen:fix-65867-junos-rpc-kwarg-leak

Conversation

@ggiesen

@ggiesen ggiesen commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes junos.rpc (used by napalm.junos_rpc) so a get-config call with a filter works again.

junos.rpc builds its RPC options (op) from __pub_arg, which carries the reserved __kwarg__ marker that the Salt CLI appends to keyword arguments. That marker leaked into the RPC options; on the get-config path junos-eznc's ElementMaker then tried to render the True value as an XML attribute and raised KeyError: <class 'bool'>, so the filter option stopped working after upgrading from 3004 to 3006.

The fix strips dunder keys from op with salt.utils.args.clean_kwargs (already used by junos.diff) right after op is assembled, so reserved markers are dropped on both the get-config and the generic RPC branch.

Fixes

Fixes #65867

Tests

Adds two regression tests in tests/pytests/unit/modules/test_junos.py:

  • test_rpc_get_config_filter_ignores_kwarg_marker - the reported case: __pub_arg carries {'filter': ..., '__kwarg__': True} and the rendered RPC must be the clean <get-configuration format="xml">...</get-configuration>.
  • test_rpc_non_get_config_ignores_kwarg_marker - the generic path, where op is forwarded as RPC arguments rather than options.

Both fail without the fix (the get-config case raises KeyError: <class 'bool'> in junos-eznc's ElementMaker) and pass with it, verified against real junos-eznc (2.8.2) rendering with only Device.execute mocked.

Notes

The same __pub_arg handling block is repeated in several other junos functions (e.g. cli, commit, install_config). This PR is scoped to the reported get-config regression; applying the same marker stripping to the other functions can follow separately.

…altstack#65867)

junos.rpc (used by napalm.junos_rpc) builds the RPC ``op`` dict from
__pub_arg, which carries the reserved ``__kwarg__`` marker that the Salt CLI
appends to keyword arguments. On a ``get-config`` call with a ``filter`` the
marker leaked into the RPC options, and junos-eznc's ElementMaker raised
``KeyError: <class 'bool'>`` while rendering the ``True`` value as an XML
attribute, so the filter option stopped working after upgrading from 3004.

Strip dunder keys from ``op`` with salt.utils.args.clean_kwargs (already used
by junos.diff) right after it is assembled, so reserved markers are dropped
on every RPC path. Adds regression tests for the get-config and non
get-config paths.
@ggiesen
ggiesen requested a review from a team as a code owner July 16, 2026 18:20
@ggiesen

ggiesen commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Validated against a live Junos device (junos-eznc 2.8.2, NETCONF over SSH), running the reporter's exact path:

  • Without this change, napalm.junos_rpc get_config filter=... raises KeyError: <class 'bool'> inside junos-eznc's ElementMaker at E("get-configuration", options), because the RPC options carry {'__kwarg__': True}.
  • With this change, the options are {'format': 'xml'} and the same call returns the requested configuration normally.

That's the same mechanism the added unit tests cover (only Device.execute is mocked there, so the real RPC element is still rendered).

@twangboy twangboy added the test:full Run the full test suite label Jul 17, 2026
@twangboy twangboy added this to the Sulphur v3006.28 milestone Jul 17, 2026
@twangboy

twangboy commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Looks like you have some test failures

@ggiesen

ggiesen commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @twangboy -- those were the functional zeromq jobs hitting the 6-hour runner timeout on a superseded run, not real failures. The re-run on the same commit is green and the merge state is clean now.

@twangboy

Copy link
Copy Markdown
Contributor

It's the most beautiful thing I've ever seen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants