Fix Junos timeout wrappers crashing on dev_timeout=None (#58108)#69789
Open
ggiesen wants to merge 1 commit into
Open
Fix Junos timeout wrappers crashing on dev_timeout=None (#58108)#69789ggiesen wants to merge 1 commit into
ggiesen wants to merge 1 commit into
Conversation
) napalm.junos_cli defaults dev_timeout to None and forwards it, so the Junos _timeout_decorator / _timeout_decorator_cleankwargs wrappers hit max(None, 0) -- which raises TypeError -- and would otherwise try to set the junos-eznc connection timeout to None, which it rejects. Coalesce None to 0 when computing the effective timeout, and only override the connection timeout when a real (>0) dev_timeout/timeout is given; otherwise run the command with the connection's default timeout. This makes junos_cli and the other timeout-decorated calls work when no timeout is passed, while still honouring an explicit dev_timeout/timeout.
Contributor
Author
|
Confirmed on real hardware (a live Juniper EX3400, Junos 23.4R2-S5.8) via a napalm Junos proxy: Before (current 3006.x): After (this PR): And |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Fixes the Junos timeout wrappers crashing when no timeout is requested.
napalm.junos_cli(and other napalm/junos calls) defaultdev_timeouttoNoneand forward it. The_timeout_decorator/_timeout_decorator_cleankwargswrappers in
salt/modules/junos.pytreated a present-but-Nonedev_timeoutas a real value:
so
max(None, 0)raisedTypeError: '>' not supported between instances of 'int' and 'NoneType'(and older junos-eznc raisedRuntimeError: could not convert timeout value of None to an integerfromconn.timeout = None).The wrappers now coalesce
Noneto0and only override the connection timeoutwhen a real (>0)
dev_timeout/timeoutis given; otherwise the call runs withthe connection's default timeout. An explicit
dev_timeout/timeoutis stillhonoured.
What issues does this PR fix or reference?
Fixes #58108
This addresses the first (and reproducible) part of #58108 --
napalm.junos_cli "show version"failing with a timeout exception. It also makesdev_timeoutactually usable, which is the mechanism for setting a longer device RPC timeout
on slow operations (the second part of the report).
The earlier #63812 removed
dev_timeoutfromjunos_cli(which drops theability to set a per-call timeout); this instead makes
dev_timeoutwork.Previous Behavior
(current tree:
TypeError: '>' not supported between instances of 'int' and 'NoneType'.)New Behavior
napalm.junos_cli "show version"runs with the connection's default timeout;napalm.junos_cli "show version" dev_timeout=120runs with a 120s devicetimeout.
Merge requirements satisfied?
tests/pytests/unit/modules/test_junos.py::test__timeout_decorator_none_dev_timeoutcalls both wrappers with
dev_timeout=Noneand asserts they do not raise and donot touch the connection timeout. It fails against the current code with the
TypeErrorabove. The existingtest__timeout_decorator/test__timeout_cleankwargs_decorator(explicitdev_timeout=10) still pass, soa real timeout is still applied.
Commits signed with GPG?
No