Repository navigation
Fix misleading proxymodule init/shutdown error message (#69139) - #69330
Merged
Merged
Conversation
Previously, all three salt-proxy bootstrap paths (salt.metaproxy.proxy,
salt.metaproxy.deltaproxy, and salt.minion.SProxyMinion) emitted the
same hard-coded message when ``init`` and/or ``shutdown`` were missing
from the proxy LazyLoader:
Proxymodule X is missing an init() or a shutdown() or both.
Check your proxymodule. Salt-proxy aborted.
That wording is correct only for the narrow case where the proxymodule
loaded but lacks one of the required functions. In practice it fires
far more often when the module never loaded at all -- a missing
dependency, an ``ImportError``, or any ``__virtual__()`` returning
``(False, reason)``. The reason is sitting right there in
``LazyLoader.missing_modules`` and ``LazyLoader.missing_fun_string()``,
but the call sites were ignoring it. Operators had no way to tell
"napalm's __virtual__ said NAPALM is not installed" from "napalm
literally has no init()."
Introduce a small ``salt.minion.proxy_load_failure_message`` helper
that consults the LazyLoader and picks the appropriate wording:
* If the proxymodule isn't in ``loaded_modules``, surface
``missing_fun_string()`` (e.g. "__virtual__ returned False: NAPALM
is not installed: ``pip install napalm``") so the operator sees the
real reason.
* Otherwise keep the historical "missing an init() or a shutdown()"
wording for the case it was actually written for.
All three call sites now use the helper. The trailing "Salt-proxy
aborted." suffix is preserved so external log scrapers still match.
Regression tests cover the three branches (virtual-returned-tuple,
virtual-returned-bare-False, and module-loaded-but-missing-init) via a
small temp-directory proxy LazyLoader.
Fixes saltstack#69139
twangboy
approved these changes
Jun 15, 2026
This was referenced Jul 11, 2026
Closed
ggiesen
added a commit
to ggiesen/salt
that referenced
this pull request
Jul 11, 2026
…ack#69139) The LazyLoader put Salt's own source directories on the global sys.path while a module body executed (__populate_sys_path, and the fpath_dirname append in _load_module). Any bare import issued while that module ran could then resolve to a same-named single-file Salt module and get cached in sys.modules for the life of the process. That is what broke napalm on modern Salt. Loading salt/utils/napalm.py runs its top-level `import napalm`, which reaches ncclient.transport, which does a bare `import ssh` to detect the optional ssh-python/libssh package. With salt/utils on sys.path that bound to salt/utils/ssh.py (a plain module, not the ssh-python package), so ncclient's `from ssh.channel import Channel` raised "'ssh' is not a package", `import napalm` failed, HAS_NAPALM was False, and the napalm proxy/execution modules never passed their __virtual__ gate. This is the root cause behind the "Proxymodule napalm is missing an init()" reports in saltstack#69139 (which saltstack#69330 only improved the error message for). Salt-internal modules are imported via their fully-qualified salt.* names, so they never needed sys.path; only external/custom module dirs do, so a custom module's bare sibling imports keep resolving. Skip appending any directory under SALT_BASE_PATH in both __populate_sys_path and the fpath_dirname append. As a side effect, a module whose optional same-named dependency is not installed no longer "loads" by importing itself.
ggiesen
added a commit
to ggiesen/salt
that referenced
this pull request
Jul 12, 2026
…ack#69139) The LazyLoader put Salt's own source directories on the global sys.path while a module body executed (__populate_sys_path, and the fpath_dirname append in _load_module). Any bare import issued while that module ran could then resolve to a same-named single-file Salt module and get cached in sys.modules for the life of the process. That is what broke napalm on modern Salt. Loading salt/utils/napalm.py runs its top-level `import napalm`, which reaches ncclient.transport, which does a bare `import ssh` to detect the optional ssh-python/libssh package. With salt/utils on sys.path that bound to salt/utils/ssh.py (a plain module, not the ssh-python package), so ncclient's `from ssh.channel import Channel` raised "'ssh' is not a package", `import napalm` failed, HAS_NAPALM was False, and the napalm proxy/execution modules never passed their __virtual__ gate. This is the root cause behind the "Proxymodule napalm is missing an init()" reports in saltstack#69139 (which saltstack#69330 only improved the error message for). Salt-internal modules are imported via their fully-qualified salt.* names, so they never needed sys.path; only external/custom module dirs do, so a custom module's bare sibling imports keep resolving. Skip appending any directory under SALT_BASE_PATH in both __populate_sys_path and the fpath_dirname append. As a side effect, a module whose optional same-named dependency is not installed no longer "loads" by importing itself.
twangboy
pushed a commit
to ggiesen/salt
that referenced
this pull request
Aug 3, 2026
…ack#69139) The LazyLoader put Salt's own source directories on the global sys.path while a module body executed (__populate_sys_path, and the fpath_dirname append in _load_module). Any bare import issued while that module ran could then resolve to a same-named single-file Salt module and get cached in sys.modules for the life of the process. That is what broke napalm on modern Salt. Loading salt/utils/napalm.py runs its top-level `import napalm`, which reaches ncclient.transport, which does a bare `import ssh` to detect the optional ssh-python/libssh package. With salt/utils on sys.path that bound to salt/utils/ssh.py (a plain module, not the ssh-python package), so ncclient's `from ssh.channel import Channel` raised "'ssh' is not a package", `import napalm` failed, HAS_NAPALM was False, and the napalm proxy/execution modules never passed their __virtual__ gate. This is the root cause behind the "Proxymodule napalm is missing an init()" reports in saltstack#69139 (which saltstack#69330 only improved the error message for). Salt-internal modules are imported via their fully-qualified salt.* names, so they never needed sys.path; only external/custom module dirs do, so a custom module's bare sibling imports keep resolving. Skip appending any directory under SALT_BASE_PATH in both __populate_sys_path and the fpath_dirname append. As a side effect, a module whose optional same-named dependency is not installed no longer "loads" by importing itself.
This branch was previously deployed
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?
Surface the real reason a proxymodule failed to load instead of always reporting "missing an init() or a shutdown()".
What issues does this PR fix or reference?
Fixes #69139
Previous Behavior
All three salt-proxy bootstrap paths (
salt.metaproxy.proxy,salt.metaproxy.deltaproxy,salt.minion.SProxyMinion) emitted the same hard-coded message wheneverinit/shutdownweren't in the proxyLazyLoader, regardless of why the module wasn't loaded. The real cause (e.g.__virtual__returning(False, "NAPALM is not installed")or anImportError) sat inLazyLoader.missing_modulesbut the call sites ignored it.New Behavior
A new helper,
salt.minion.proxy_load_failure_message, used by all three call sites, consults the proxyLazyLoaderand surfacesmissing_fun_string()when the module never loaded, so operators see the actual reason (e.g. the failed__virtual__message). The historical "missing an init() or a shutdown()" wording is preserved verbatim for the case it was actually intended for. The trailing "Salt-proxy aborted." suffix is kept for log scrapers.Merge requirements satisfied?
Commits signed with GPG?
Yes