Skip to content

Rebuild the Salt-SSH thin archive when its configured contents change - #70288

Open
jpmckinney wants to merge 1 commit into
saltstack:3008.xfrom
jpmckinney:thin-saltexts
Open

jpmckinney wants to merge 1 commit into
saltstack:3008.xfrom
jpmckinney:thin-saltexts

Conversation

@jpmckinney

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes gen_thin() treat the configured contents of the thin archive as part of its cache key, and lets thin_extra_mods name a module inside a namespace package.

  • gen_thin() writes <cachedir>/thin/.thin-gen-config, recording extra_mods, so_mods and the installed Salt extensions (name and version, read from entry points without importing them), and rebuilds the archive when that identity changes.
  • thin_sum() takes **kwargs and forwards them to gen_thin(), and Single passes the options it was given. Without this, the second gen_thin() call could rebuild the archive with default options, dropping thin_extra_mods, ssh_ext_alternatives and the thin_saltext_* filters.
  • get_tops() imports an extra module with importlib.import_module() and resolves the directory to pack with the existing _get_package_root_mod() helper, so a dotted name in a namespace package is packed at the right path with its namespace.
  • Documents thin_extra_mods taking a dotted path, and adds the missing entries for thin_exclude_saltexts, thin_saltext_allowlist and thin_saltext_blocklist, including the fact that extension dependencies are not shipped.

This targets 3008.x, the oldest supported branch where extensions are packed into the thin archive. The thin_extra_mods crash is older than that — 3006.x and 3007.x have the same os.path.split(__import__(mod).__file__) — but the fix here uses _get_package_root_mod(), which was added in 3008.0. Happy to write a separate backport for the older branches if you want one.

What issues does this PR fix or reference?

Fixes #70287
References #70284

Previous Behavior

A cached archive was reused as long as the Salt version and the Python major version were unchanged, so newly installed Salt extensions and changes to thin_extra_mods never reached the target until --regen-thin was used. thin_extra_mods: "saltext.mysql" raised TypeError: expected str, bytes or os.PathLike object, not NoneType when the archive was regenerated, because __import__() returns the saltext namespace package, whose __file__ is None.

New Behavior

The archive is rebuilt when the extensions or the configured extra modules change, and is still reused when nothing changed. thin_extra_mods: "saltext.mysql" packs the extension at py3/saltext/mysql/.

Verified with salt==3008.2, saltext.mysql==1.1.0 and pymysql, generating into a fresh cache directory: adding thin_extra_mods: pymysql rebuilds the archive and packs 18 py3/pymysql/ files, where 3008.2 returns the archive it built before, unchanged.

Two caveats worth naming:

  • The first gen_thin() after this change rebuilds the archive once, since an archive without .thin-gen-config is treated as outdated.
  • thin_sum() gains a **kwargs parameter. Existing callers keep working, but a caller that passes no options can now regenerate an archive that was built with them, which is why Single was updated in the same commit.

Merge requirements satisfied?

Commits signed with GPG?

Yes

gen_thin only compared the Salt version and the Python major version, so an
archive cached in the master cachedir was reused even after a Salt extension
was installed or thin_extra_mods changed, and neither reached the target.
Record an identity of what the archive was generated from, and compare
against it.

thin_sum calls gen_thin again, so it now forwards the same arguments:
otherwise the regeneration this makes possible would drop the caller's
configuration.

Also fix thin_extra_mods for a module inside a namespace package, such as
saltext.mysql: __import__ returns the namespace package, whose __file__ is
None, which raised a TypeError instead of packing the extension.

Document that thin_extra_mods takes a dotted path, along with the
thin_exclude_saltexts, thin_saltext_allowlist and thin_saltext_blocklist
options added in 3008.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant