Don't report failure on task manager installs

This commit is contained in:
twangboy 2023-05-31 13:12:08 -06:00 committed by Megan Wilhite
parent d9a421d014
commit 41d9f33c3f
3 changed files with 61 additions and 0 deletions

1
changelog/63767.fixed.md Normal file
View file

@ -0,0 +1 @@
pkg.installed no longer reports failure when installing packages that are installed via the task manager

View file

@ -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
@ -2034,6 +2040,7 @@ 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
)
@ -2041,6 +2048,18 @@ def installed(
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)

View file

@ -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