Skip to content

Fix misleading proxymodule init/shutdown error message (#69139) - #69330

Merged
dwoz merged 1 commit into
saltstack:3006.xfrom
dwoz:fix/issue-69139
Jun 15, 2026
Merged

dwoz merged 1 commit into
saltstack:3006.xfrom
dwoz:fix/issue-69139

Conversation

@dwoz

@dwoz dwoz commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

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 whenever init/shutdown weren't in the proxy LazyLoader, regardless of why the module wasn't loaded. The real cause (e.g. __virtual__ returning (False, "NAPALM is not installed") or an ImportError) sat in LazyLoader.missing_modules but the call sites ignored it.

New Behavior

A new helper, salt.minion.proxy_load_failure_message, used by all three call sites, consults the proxy LazyLoader and surfaces missing_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?

  • Docs
  • Changelog
  • Tests written/updated

Commits signed with GPG?

Yes

@dwoz
dwoz requested a review from a team as a code owner June 6, 2026 05:53
@dwoz dwoz added the test:full Run the full test suite label Jun 6, 2026
@dwoz dwoz added this to the Sulphur v3006.26 milestone Jun 6, 2026
@dwoz
dwoz force-pushed the fix/issue-69139 branch from 2d6ce34 to 41e5f9e Compare June 7, 2026 04:19
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
@dwoz
dwoz merged commit 43b2d98 into saltstack:3006.x Jun 15, 2026
410 checks passed
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

1 inactive deployment
ci — fe1f8cd7 Deployed Jun 15, 2026 by dwoz via Build Onedir Packages / Windows (amd64) #24112
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