Skip to content

Commit

Permalink
Don't report failure on task manager installs
Browse files Browse the repository at this point in the history
  • Loading branch information
twangboy authored and Megan Wilhite committed Jun 2, 2023
1 parent d9a421d commit 41d9f33
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/63767.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg.installed no longer reports failure when installing packages that are installed via the task manager
19 changes: 19 additions & 0 deletions salt/states/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,12 @@ def installed(
Any argument that is passed through to the ``install`` function, which
is not defined for that function, will be silently ignored.
.. note::
In Windows, some packages are installed using the task manager. The Salt
minion installer does this. In that case, there is no way to know if the
package installs correctly. All that can be reported is that the task
that launches the installer started successfully.
:param str name:
The name of the package to be installed. This parameter is ignored if
either "pkgs" or "sources" is used. Additionally, please note that this
Expand Down Expand Up @@ -2034,13 +2040,26 @@ def installed(
new_caps = __salt__["pkg.list_provides"](**kwargs)
else:
new_caps = {}

_ok, failed = _verify_install(
desired, new_pkgs, ignore_epoch=ignore_epoch, new_caps=new_caps
)
modified = [x for x in _ok if x in targets]
not_modified = [x for x in _ok if x not in targets and x not in to_reinstall]
failed = [x for x in failed if x in targets]

# When installing packages that use the task scheduler, we can only know
# that the task was started, not that it installed successfully. This is
# especially the case when upgrading the Salt minion on Windows as the
# installer kills and unregisters the Salt minion service. We will only know
# that the installation was successful if the minion comes back up. So, we
# just want to report success in that scenario
for item in failed:
if item in changes and isinstance(changes[item], dict):
if changes[item].get("install status", "") == "task started":
modified.append(item)
failed.remove(item)

if modified:
if sources:
summary = ", ".join(modified)
Expand Down
41 changes: 41 additions & 0 deletions tests/pytests/unit/states/test_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,3 +1081,44 @@ def test__get_installable_versions_version_found():
expected = {"dummy": {"new": "1.0.1", "old": ""}}
ret = pkg._get_installable_versions({"dummy": None}, current=None)
assert ret == expected


def test_installed_salt_minion_windows():
mock_list_pkgs = MagicMock(
return_value={
"git": "1.34.1",
"salt-minion-py3": "3006.0",
"vim": "1.6",
}
)
mock_install = MagicMock(
return_value={
"salt-minion-py3": {"install status": "task started"},
}
)
mock_find_install_targets = MagicMock(
return_value=(
{"salt-minion-py3": "3006.1"},
{"salt-minion-py3": "3006.1"},
[],
{},
{},
[],
True,
)
)
salt_dict = {
"pkg.install": mock_install,
"pkg.list_pkgs": mock_list_pkgs,
"pkg_resource.check_extra_requirements": pkg_resource.check_extra_requirements,
"pkg_resource.version_clean": pkg_resource.version_clean,
}
with patch.dict(pkg.__salt__, salt_dict), patch.object(
pkg, "_find_install_targets", mock_find_install_targets
):
expected = {
"salt-minion-py3": {"install status": "task started"},
}
ret = pkg.installed(name="salt-minion-py3", version="3006.1")
assert ret["result"]
assert ret["changes"] == expected

0 comments on commit 41d9f33

Please sign in to comment.