From a3619a41fb5a3fa7f220453e45e56f8ecf08452d Mon Sep 17 00:00:00 2001 From: Twangboy Date: Thu, 17 Nov 2022 08:49:05 -0700 Subject: [PATCH] Add changelog and test case --- changelog/62480.added | 1 + salt/modules/win_pkg.py | 6 +-- tests/pytests/unit/modules/test_win_pkg.py | 47 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 changelog/62480.added diff --git a/changelog/62480.added b/changelog/62480.added new file mode 100644 index 00000000000..50044e2d1d9 --- /dev/null +++ b/changelog/62480.added @@ -0,0 +1 @@ +Added debug log messages displaying the command being run when installing packages on Windows diff --git a/salt/modules/win_pkg.py b/salt/modules/win_pkg.py index 9560c94567d..51441b34668 100644 --- a/salt/modules/win_pkg.py +++ b/salt/modules/win_pkg.py @@ -1768,10 +1768,10 @@ def install(name=None, refresh=False, pkgs=None, **kwargs): # Install the software # Check Use Scheduler Option + log.debug("PKG : cmd: %s /s /c %s", cmd_shell, arguments) + log.debug("PKG : pwd: %s", cache_path) if pkginfo[version_num].get("use_scheduler", False): # Create Scheduled Task - log.debug("PKG : cmd: %s /s /c %s", cmd_shell, arguments) - log.debug("PKG : pwd: %s", cache_path) __salt__["task.create_task"]( name="update-salt-software", user_name="System", @@ -1829,8 +1829,6 @@ def install(name=None, refresh=False, pkgs=None, **kwargs): ret[pkg_name] = {"install status": "failed"} else: # Launch the command - log.debug("PKG : cmd: %s /s /c %s", cmd_shell, arguments) - log.debug("PKG : pwd: %s", cache_path) result = __salt__["cmd.run_all"]( '"{}" /s /c "{}"'.format(cmd_shell, arguments), cache_path, diff --git a/tests/pytests/unit/modules/test_win_pkg.py b/tests/pytests/unit/modules/test_win_pkg.py index c14cadb5994..4201736657f 100644 --- a/tests/pytests/unit/modules/test_win_pkg.py +++ b/tests/pytests/unit/modules/test_win_pkg.py @@ -1,6 +1,8 @@ """ Tests for the win_pkg module """ +import logging + import pytest import salt.modules.config as config @@ -279,6 +281,51 @@ def test_pkg_install_single_pkg(): assert "-e True -test_flag True" in str(mock_cmd_run_all.call_args[0]) +def test_pkg_install_log_message(caplog): + """ + test pkg.install pkg with extra_install_flags + """ + 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}) + with 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.install( + pkgs=["firebox"], + version="3.03", + extra_install_flags="-e True -test_flag True", + ) + assert ( + 'PKG : cmd: C:\\WINDOWS\\system32\\cmd.exe /s /c "runme.exe" /s -e ' + "True -test_flag True" + ) in caplog.messages + assert "PKG : pwd: " in caplog.messages + assert "PKG : retcode: 0" in caplog.messages + + def test_pkg_install_multiple_pkgs(): """ test pkg.install pkg with extra_install_flags