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

Add debug logging to win_pkg.remove #63867

Merged
merged 3 commits into from
Mar 15, 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/63866.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added debug log messages displaying the command being run when removing packages on Windows
3 changes: 3 additions & 0 deletions salt/modules/win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,8 @@ def remove(name=None, pkgs=None, **kwargs):
# Uninstall the software
changed.append(pkgname)
# Check Use Scheduler Option
log.debug("PKG : cmd: %s /s /c %s", cmd_shell, arguments)
log.debug("PKG : pwd: %s", cache_path)
if pkginfo[target].get("use_scheduler", False):
# Create Scheduled Task
__salt__["task.create_task"](
Expand Down Expand Up @@ -2184,6 +2186,7 @@ def remove(name=None, pkgs=None, **kwargs):
python_shell=False,
redirect_stderr=True,
)
log.debug("PKG : retcode: %s", result["retcode"])
if not result["retcode"]:
ret[pkgname] = {"uninstall status": "success"}
changed.append(pkgname)
Expand Down
45 changes: 45 additions & 0 deletions tests/pytests/unit/modules/test_win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,51 @@ def test_pkg_install_minion_error_salt_cache_dir():
assert ret == expected


def test_pkg_remove_log_message(caplog):
"""
test pkg.remove pkg logging
"""
ret__get_package_info = {
"3.03": {
"uninstaller": "%program.exe",
"reboot": False,
"msiexec": False,
"installer": "runme.exe",
"uninstall_flags": "/S",
"locale": "en_US",
"install_flags": "/s",
"full_name": "Firebox 3.03 (x86 en-US)",
}
}

mock_cmd_run_all = MagicMock(return_value={"retcode": 0})
se_list_pkgs = {"firebox": ["3.03"]}
with patch.object(win_pkg, "list_pkgs", return_value=se_list_pkgs), patch.object(
salt.utils.data, "is_true", MagicMock(return_value=True)
), patch.object(
win_pkg, "_get_package_info", MagicMock(return_value=ret__get_package_info)
), patch.dict(
win_pkg.__salt__,
{
"pkg_resource.parse_targets": MagicMock(
return_value=[{"firebox": "3.03"}, None]
),
"cp.is_cached": MagicMock(return_value="C:\\fake\\path.exe"),
"cmd.run_all": mock_cmd_run_all,
},
), caplog.at_level(
logging.DEBUG
):
win_pkg.remove(
pkgs=["firebox"],
)
assert (
'PKG : cmd: C:\\WINDOWS\\system32\\cmd.exe /s /c "%program.exe" /S'
).lower() in [x.lower() for x in caplog.messages]
assert "PKG : pwd: ".lower() in [x.lower() for x in caplog.messages]
assert "PKG : retcode: 0" in caplog.messages


def test_pkg_remove_minion_error_salt_cache_dir():
"""
Test pkg.remove when cp.cache_dir encounters a minion error
Expand Down