From 8a1e4c120f03149ebff288c6c989cca69327cd17 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Fri, 24 Mar 2023 12:30:37 -0700 Subject: [PATCH] Ensure kwargs is passed along to _call_apt when passed into install function. --- changelog/63847.fixed.md | 1 + salt/modules/aptpkg.py | 2 +- tests/pytests/unit/modules/test_aptpkg.py | 39 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 changelog/63847.fixed.md diff --git a/changelog/63847.fixed.md b/changelog/63847.fixed.md new file mode 100644 index 00000000000..430ee039d27 --- /dev/null +++ b/changelog/63847.fixed.md @@ -0,0 +1 @@ +Ensure kwargs is passed along to _call_apt when passed into install function. diff --git a/salt/modules/aptpkg.py b/salt/modules/aptpkg.py index 8d609c83169..f68b1907e88 100644 --- a/salt/modules/aptpkg.py +++ b/salt/modules/aptpkg.py @@ -1003,7 +1003,7 @@ def install( unhold(pkgs=to_unhold) for cmd in cmds: - out = _call_apt(cmd) + out = _call_apt(cmd, **kwargs) if out["retcode"] != 0 and out["stderr"]: errors.append(out["stderr"]) diff --git a/tests/pytests/unit/modules/test_aptpkg.py b/tests/pytests/unit/modules/test_aptpkg.py index ff3023678ad..b69402578a6 100644 --- a/tests/pytests/unit/modules/test_aptpkg.py +++ b/tests/pytests/unit/modules/test_aptpkg.py @@ -434,6 +434,45 @@ def test_install(install_var): kwargs = {"force_conf_new": True} assert aptpkg.install(name="tmux", **kwargs) == install_var + patch_kwargs = { + "__salt__": { + "pkg_resource.parse_targets": MagicMock( + return_value=({"tmux": None}, "repository") + ), + "pkg_resource.sort_pkglist": MagicMock(), + "pkg_resource.stringify": MagicMock(), + "cmd.run_stdout": MagicMock(return_value="install ok installed python3\n"), + } + } + mock_call_apt_ret = { + "pid": 48174, + "retcode": 0, + "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nvim is already the newest version (2:8.2.3995-1ubuntu2.4).\n", + "stderr": "Running scope as unit: run-rc2803bccd0b445a5b00788cd74b4e635.scope", + } + mock_call_apt = MagicMock(return_value=mock_call_apt_ret) + expected_call = call( + [ + "apt-get", + "-q", + "-y", + "-o", + "DPkg::Options::=--force-confold", + "-o", + "DPkg::Options::=--force-confdef", + "install", + "tmux", + ], + scope=True, + ) + with patch.multiple(aptpkg, **patch_kwargs): + with patch( + "salt.modules.aptpkg.get_selections", MagicMock(return_value={"hold": []}) + ): + with patch("salt.modules.aptpkg._call_apt", mock_call_apt): + ret = aptpkg.install(name="tmux", scope=True) + assert expected_call in mock_call_apt.mock_calls + def test_remove(uninstall_var): """