Skip to content

Fix linux_shadow and solaris_shadow spwd usage on Python 3.13+ (#64264) - #69651

Merged
dwoz merged 3 commits into
saltstack:3006.xfrom
dwoz:fix/64264-spwd-removal
Jul 7, 2026
Merged

dwoz merged 3 commits into
saltstack:3006.xfrom
dwoz:fix/64264-spwd-removal

Conversation

@dwoz

@dwoz dwoz commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Removes the last uses of the removed-in-Python-3.13 spwd stdlib module
from Salt's shadow modules, so shadow.info no longer crashes with
NameError: name 'spwd' is not defined on Python 3.13+.

Two-part change against 3006.x:

  1. Cherry-pick of a5cd3113f2d "Remove uses of spwd" (originally
    authored by Toyam Cox / Georg Pfuetzenreuter, referencing [BUG] Salt relies on spwd module, deprecated in 3.11 and removed in 3.13 #67119)
    which fixes salt/modules/linux_shadow.py. That commit currently
    lives on 3007.x / 3008.x / master but has not yet shipped in
    any 3007 release tag
    (latest tag is v3007.14), and it has never
    been on 3006.x.
  2. A fresh, mirrored fix for salt/modules/solaris_shadow.py (still
    import spwd on every branch, including master) plus rewrites of
    the affected unit tests so they run on Python 3.13+ (they previously
    importorskip('spwd'), which silently disabled all coverage on the
    new interpreters).

Merge-forward will carry the solaris_shadow removal from 3006.x up
through 3007.x, 3008.x, and master; the linux_shadow cherry-pick is a
no-op on 3007.x+ because the fix is already there.

What issues does this PR fix or reference?

Fixes #64264

Previous Behavior

On Python 3.13, salt.modules.linux_shadow.info raised at first use:

File ".../salt/modules/linux_shadow.py", line 74, in info
    getspnam = functools.partial(spwd.getspnam)
                                 ^^^^
NameError: name 'spwd' is not defined

salt.modules.solaris_shadow still imported spwd at module load
(deprecation warning on 3.11/3.12, ImportError swallowed on 3.13+),
and its HAS_SPWD-guarded primary Solaris code path was silently dead
on 3.13+, forcing every Solaris minion into the SmartOS passwd -s
fallback.

New Behavior

Both modules parse /etc/shadow directly via a local _getspnam helper
that returns an spwd.struct_spwd-compatible namedtuple. The
SmartOS-style pwd + passwd -s fallback in solaris_shadow is
preserved for the case where /etc/shadow is not readable.

Merge requirements satisfied?

  • Docs (no doc changes needed — the CLI/behavior for shadow.info
    is unchanged, only its internal implementation)
  • Changelog (changelog/64264.fixed.md; the cherry-picked commit
    also keeps its original changelog/67119.fixed.md)
  • Tests written/updated (tests/pytests/unit/modules/test_linux_shadow.py,
    tests/pytests/unit/modules/test_solaris_shadow.py)

Commits signed with GPG?

Yes

@dwoz
dwoz requested a review from a team as a code owner July 2, 2026 06:17
@dwoz dwoz added this to the Sulphur v3006.26 milestone Jul 2, 2026
@dwoz dwoz added the test:full Run the full test suite label Jul 2, 2026
Vaelatern and others added 2 commits July 3, 2026 15:13
Module deprecated and no longer shipped with Python 3.13.

Co-authored-by: Toyam Cox <[email protected]>
Co-authored-by: Georg Pfuetzenreuter <[email protected]>
Signed-off-by: Georg Pfuetzenreuter <[email protected]>
The stdlib ``spwd`` module was deprecated in Python 3.11 and removed in
Python 3.13. ``salt.modules.solaris_shadow`` still tried to import it
and to reference ``spwd.getspnam``/``spwd.struct_spwd`` on the primary
Solaris code path, mirroring the earlier ``linux_shadow`` breakage
tracked in this issue.

Replace the ``spwd`` primary path with a local ``_getspnam`` that reads
``/etc/shadow`` directly and returns a ``struct_spwd``-compatible
namedtuple, matching the pattern already used in ``linux_shadow`` (see
commit a5cd311). The SmartOS-style ``pwd`` + ``passwd -s`` fallback
is preserved for the case where ``/etc/shadow`` is not readable. Update
the ``linux_shadow`` and ``solaris_shadow`` unit tests to patch the new
``_getspnam`` helper instead of ``spwd.getspnam`` so the suites run on
Python 3.13+.

Fixes saltstack#64264
Comment thread salt/modules/solaris_shadow.py Resolved
twangboy
twangboy previously approved these changes Jul 6, 2026
- Replace `except (KeyError, FileNotFoundError)` with
  `except (KeyError, OSError)` in both linux_shadow.py and
  solaris_shadow.py so that PermissionError (and any other
  OS-level error reading /etc/shadow) falls back gracefully
  rather than propagating to the caller.

This branch was previously deployed

1 inactive deployment
ci — 07782878 Deployed Jul 7, 2026 by dwoz via Build Onedir Packages / macOS (x86_64) #25370
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.

4 participants