Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix salt.states.file.managed() for follow_symlinks=True and test=True #62067

Merged
merged 2 commits into from
Jun 7, 2022

Conversation

petrpavlu
Copy link
Contributor

What does this PR do?

When managing file /etc/test as follows:

file /etc/test:
  file.managed:
    - name: /etc/test
    - source: salt://config/test
    - mode: 644
    - follow_symlinks: True

and with /etc/test being a symlink to a different file, an invocation of salt-call '*' state.apply test=True can report that the file should be updated even when a subsequent run of the same command without the test parameter makes no changes.

The problem is that the test code path doesn't take correctly into account the follow_symlinks=True setting and ends up comparing permissions of the symlink instead of its target file.

The pull request addresses the problem by extending functions salt.modules.file.check_managed(), check_managed_changes() and check_file_meta() to have the follow_symlinks parameter which gets propagated to the salt.modules.file.stats() call and by updating salt.states.file.managed() to forward the same parameter to salt.modules.file.check_managed_changes().

What issues does this PR fix or reference?

Fixes #62066.

Previous Behavior

Unexpected updates were reported by salt.states.file.managed() with follow_symlinks=True and applying with test=True, when running without the test parameter produced no changes. See #62066 for details.

New Behavior

The test mode for salt.states.file.managed() takes into account follow_symlinks=True and doesn't report the unexpected updates.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

No

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@petrpavlu petrpavlu requested a review from a team as a code owner May 16, 2022 08:16
@petrpavlu petrpavlu requested review from MKLeb and removed request for a team May 16, 2022 08:16
@welcome
Copy link

welcome bot commented May 16, 2022

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at saltproject@vmware.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

@petrpavlu petrpavlu force-pushed the file-managed-symlinks-fix branch from 34732da to 61f2f3a Compare May 18, 2022 15:13
@petrpavlu
Copy link
Contributor Author

Updated patch should address test failures on FreeBSD and macOS.

@petrpavlu petrpavlu force-pushed the file-managed-symlinks-fix branch from 61f2f3a to 6d10245 Compare May 18, 2022 16:25
@MKLeb
Copy link
Contributor

MKLeb commented May 19, 2022

Hi @petrpavlu, thanks for your contribution! I think everything looks good here. Going to let the remaining workflows run and will come back to this tomorrow to approve if all is good.

When managing file /etc/test as follows:
> file /etc/test:
>   file.managed:
>     - name: /etc/test
>     - source: salt://config/test
>     - mode: 644
>     - follow_symlinks: True

and with /etc/test being a symlink to a different file, an invocation of
"salt-call '*' state.apply test=True" can report that the file should be
updated even when a subsequent run of the same command without the test
parameter makes no changes.

The problem is that the test code path doesn't take correctly into
account the follow_symlinks=True setting and ends up comparing
permissions of the symlink instead of its target file.

The patch addresses the problem by extending functions
salt.modules.file.check_managed(), check_managed_changes() and
check_file_meta() to have the follow_symlinks parameter which gets
propagated to the salt.modules.file.stats() call and by updating
salt.states.file.managed() to forward the same parameter to
salt.modules.file.check_managed_changes().

Fixes saltstack#62066.
@petrpavlu petrpavlu force-pushed the file-managed-symlinks-fix branch from 6d10245 to d58a3d6 Compare May 20, 2022 08:36
@petrpavlu
Copy link
Contributor Author

Updated the patch to fix the reported isort failure.

@petrpavlu
Copy link
Contributor Author

Thanks @MKLeb for the review. Can the patch be now merged or is still anything missing?

@Ch3LL Ch3LL merged commit 95bfbe3 into saltstack:master Jun 7, 2022
@welcome
Copy link

welcome bot commented Jun 7, 2022

Congratulations on your first PR being merged! 🎉

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.

[BUG] salt.states.file.managed() reports unexpected changes for follow_symlinks=True and test=True
3 participants