Skip to content

Use shutil.move in seed.apply_ to support cross-filesystem seeding#69773

Merged
dwoz merged 2 commits into
saltstack:3006.xfrom
ggiesen:fix-55348
Jul 12, 2026
Merged

Use shutil.move in seed.apply_ to support cross-filesystem seeding#69773
dwoz merged 2 commits into
saltstack:3006.xfrom
ggiesen:fix-55348

Conversation

@ggiesen

@ggiesen ggiesen commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

salt.modules.seed.apply_() relocates the generated minion config and keys into the mounted image once _check_install() reports that salt-minion is already present. It did this with three os.rename() calls. os.rename() cannot move a file across filesystem boundaries, so when the temp source (<mpt>/tmp/...) and the destination (<mpt>/etc/salt/minion, <mpt>/<pki_dir>/minion.pem|.pub) resolve to different mounts, the syscall raises OSError EXDEV ("Invalid cross-device link") and seeding aborts.

This switches the three moves to shutil.move(), which falls back to copy + unlink when the source and destination are on different filesystems. shutil is already imported, and the destinations are explicit file paths (never existing directories), so on the common same-filesystem path the behaviour is unchanged.

What issues does this PR fix or reference?

Fixes #55348

Previous Behavior

Seeding an image whose temp directory and target paths lived on different mounts failed with OSError: [Errno 18] Invalid cross-device link from os.rename() in the pre-installed (_check_install) branch of seed.apply.

New Behavior

The config and keys are relocated with shutil.move(), which transparently copies across filesystem boundaries, so seeding succeeds regardless of whether the temp files and their destination share a mount. Same-filesystem behaviour is unchanged.

Merge requirements satisfied?

  • Docs: N/A (no user-facing docs change)
  • Changelog entry added (changelog/55348.fixed.md)
  • Tests written and described below

Tests (in tests/pytests/unit/modules/test_seed.py):

  • test_apply_moves_config_and_keys_with_shutil_move_55348 - drives apply_() through the _check_install==True branch with production defaults, stubs os.rename to raise EXDEV, and asserts the three shutil.move calls with the exact (src, joined-dst) pairs plus os.rename.assert_not_called().
  • test_apply_pre_installed_branch_returns_true_55348 - must-not-regress guard: with both move primitives stubbed to succeed, the branch still returns True and unmounts.
  • test_apply_creates_pki_dir_when_missing_55348 - peripheral coverage: the pki directory is created via file.makedirs when absent before the keys are moved.

Commits signed with GPG?

No

seed.apply_ relocated the generated minion config and keys into the
mounted image with os.rename, which raises OSError EXDEV
("Invalid cross-device link") when the temp source and destination are
on different mounts. Switch the three moves to shutil.move, which falls
back to copy+unlink across filesystem boundaries. shutil is already
imported and the destinations are explicit file paths, so behaviour is
unchanged on the same-filesystem path.

Fixes saltstack#55348
@ggiesen ggiesen requested a review from a team as a code owner July 10, 2026 17:56
@charzl charzl self-assigned this Jul 10, 2026
@dwoz dwoz added the test:full Run the full test suite label Jul 10, 2026
@dwoz dwoz merged commit 1101fc6 into saltstack:3006.x Jul 12, 2026
851 of 854 checks passed
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.

3 participants