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

[3006.x] Fix pkg.latest failing for winrepo packages that are already up to date #65171

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/65165.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix pkg.latest failing on windows for winrepo packages where the package is already up to date
3 changes: 2 additions & 1 deletion salt/states/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,8 @@ def latest(
x
for x in targets
if not changes.get(x)
or targets[x] not in changes[x].get("new").split(",")
or changes[x].get("new") is not None
and targets[x] not in changes[x].get("new").split(",")
and targets[x] != "latest"
]
successful = [x for x in targets if x not in failed]
Expand Down
21 changes: 21 additions & 0 deletions tests/pytests/unit/states/test_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,3 +1196,24 @@ def test_latest_multiple_versions():
with patch.dict(pkg.__salt__, salt_dict):
ret = pkg.latest(pkg_name)
assert ret.get("result", False) is True


def test_latest_no_change_windows():
"""
Test pkg.latest with no change to the package version for winrepo packages

See: https://github.com/saltstack/salt/issues/65165
"""
pkg_name = "fake_pkg"
version = "1.2.2"
latest_version_mock = MagicMock(return_value={pkg_name: version})
current_version_mock = MagicMock(return_value={pkg_name: version})
install_mock = MagicMock(return_value={pkg_name: {"install status": "success"}})
salt_dict = {
"pkg.latest_version": latest_version_mock,
"pkg.version": current_version_mock,
"pkg.install": install_mock,
}
with patch.dict(pkg.__salt__, salt_dict):
ret = pkg.latest(pkg_name)
assert ret.get("result", False) is True