forked from saltstack/salt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request saltstack#66857 from twangboy/fix_64630
[3006.x]Manage symlinks after dirs and files
- Loading branch information
Showing
5 changed files
with
290 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fixed an intermittent issue with file.recurse where the state would | ||
report failure even on success. Makes sure symlinks are created | ||
after the target file is created |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import logging | ||
import os | ||
import pathlib | ||
|
||
import pytest | ||
|
||
import salt.states.file as filestate | ||
from tests.support.mock import MagicMock, patch | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.fixture | ||
def configure_loader_modules(): | ||
return {filestate: {"__salt__": {}, "__opts__": {}, "__env__": "base"}} | ||
|
||
|
||
def test__gen_recurse_managed_files(): | ||
""" | ||
Test _gen_recurse_managed_files to make sure it puts symlinks at the end of the list of files. | ||
""" | ||
target_dir = pathlib.Path(f"{os.sep}some{os.sep}path{os.sep}target") | ||
cp_list_master = MagicMock( | ||
return_value=[ | ||
"target/symlink", | ||
"target/just_a_file.txt", | ||
"target/not_a_symlink/symlink", | ||
"target/notasymlink", | ||
], | ||
) | ||
cp_list_master_symlinks = MagicMock( | ||
return_value={ | ||
"target/symlink": f"{target_dir}{os.sep}not_a_symlink{os.sep}symlink" | ||
} | ||
) | ||
patch_salt = { | ||
"cp.list_master": cp_list_master, | ||
"cp.list_master_symlinks": cp_list_master_symlinks, | ||
} | ||
with patch.dict(filestate.__salt__, patch_salt): | ||
files, dirs, links, keep = filestate._gen_recurse_managed_files( | ||
name=str(target_dir), source=f"salt://{target_dir.name}", keep_symlinks=True | ||
) | ||
expected = ( | ||
f"{os.sep}some{os.sep}path{os.sep}target{os.sep}symlink", | ||
"salt://target/symlink?saltenv=base", | ||
) | ||
assert files[-1] == expected |