Fix crash/mutation/log bugs in the shared napalm utils and proxy#69796
Open
ggiesen wants to merge 2 commits into
Open
Fix crash/mutation/log bugs in the shared napalm utils and proxy#69796ggiesen wants to merge 2 commits into
ggiesen wants to merge 2 commits into
Conversation
- get_device_opts: optional_args explicitly set to null yielded None (the get
default only applies to a missing key), crashing the "config_lock" membership
test; and a present optional_args dict was mutated in place, leaking the
config_lock / keepalive defaults into the caller's opts/pillar. Use
copy.deepcopy(device_dict.get("optional_args") or {}).
- proxy_napalm_wrap: force_reconnect did opts["proxy"].update(**kwargs)
unconditionally, raising KeyError on a straight (non-proxy) minion which has
no 'proxy' key. That merge is only for the always-alive proxy path; a straight
minion picks the override up from clean_kwargs, so guard it with is_proxy().
- proxy.shutdown: a trailing comma made 'port' a 1-tuple, so a failed close()
logged ':(830,)' / ':(None,)'. Remove it.
3 tasks
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 three bugs in the shared NAPALM machinery (
salt/utils/napalm.pyandsalt/proxy/napalm.py) that every NAPALM module and proxy sits on top of.get_device_optscrashes onoptional_args: nulland mutates the caller'sconfig.
device_dict.get("optional_args", {})returnsNonewhen the key ispresent but null (the default only applies to a missing key), so the
"config_lock" not in ...membership test raisedTypeError. And whenoptional_argswas a dict, it was used by reference -- theconfig_lock/keepalivedefaults injected below were written straight back into the user'slive opts/pillar structure. Now
copy.deepcopy(... or {}).force_reconnectraisesKeyError: 'proxy'on a straight minion.proxy_napalm_wrapdidopts["proxy"].update(**kwargs)unconditionally, but astraight (non-proxy) NAPALM minion has no
proxykey. That merge is onlyneeded for the always-alive proxy path; a straight minion already picks the
override up from
clean_kwargsfurther down, so it's now guarded byis_proxy(opts).proxy.shutdownlogs a malformed port. A trailing comma madeporta1-tuple, so a failed
close()logged:(830,)/:(None,)(and theif portguard never suppressed the empty case). Comma removed.What issues does this PR fix or reference?
Found by an audit of the NAPALM modules (same series as #69793 / #69794 /
#69795).
Note
The audit also found a
salt.utils.napalm.call()reconnect issue -- innot-always-alive mode, the inner
open()during aConnectionClosedExceptionretry is closed by its own
finallybefore the command re-runs. It needs a morecareful fix plus a reconnect test harness, so it is intentionally left for a
follow-up rather than shipped unvalidated here.
This PR adds
tests/pytests/unit/utils/test_napalm.py; #69793 also adds thatfile (different test functions), so whichever merges second needs a trivial
combine.
Merge requirements satisfied?
test_get_device_opts_null_optional_args,test_get_device_opts_does_not_mutate_caller,test_proxy_napalm_wrap_force_reconnect_straight_minion(newutils/test_napalm.py) andtest_shutdown_logs_scalar_port_on_close_failure(added to
proxy/test_napalm.py). All fail against the current code.Commits signed with GPG?
No