Use shutil.move in seed.apply_ to support cross-filesystem seeding#69773
Merged
Conversation
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
dwoz
approved these changes
Jul 12, 2026
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?
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 threeos.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 raisesOSErrorEXDEV ("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.shutilis 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 linkfromos.rename()in the pre-installed (_check_install) branch ofseed.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?
changelog/55348.fixed.md)Tests (in
tests/pytests/unit/modules/test_seed.py):test_apply_moves_config_and_keys_with_shutil_move_55348- drivesapply_()through the_check_install==True branch with production defaults, stubsos.renameto raise EXDEV, and asserts the threeshutil.movecalls with the exact(src, joined-dst)pairs plusos.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 viafile.makedirswhen absent before the keys are moved.Commits signed with GPG?
No