mirror of
https://github.com/saltstack/salt.git
synced 2025-04-10 06:41:40 +00:00
Added support and tests for dnf5 to services_need_restart for yum packages
This commit is contained in:
parent
59ddf3cf88
commit
002d02a5e7
3 changed files with 18 additions and 3 deletions
1
changelog/67177.fixed.md
Normal file
1
changelog/67177.fixed.md
Normal file
|
@ -0,0 +1 @@
|
|||
Added support and tests for dnf5 to services_need_restart for yum packages
|
|
@ -3541,12 +3541,17 @@ def services_need_restart(**kwargs):
|
|||
|
||||
salt '*' pkg.services_need_restart
|
||||
"""
|
||||
if _yum() != "dnf":
|
||||
raise CommandExecutionError("dnf is required to list outdated services.")
|
||||
if _yum() in ("dnf", "dnf5"):
|
||||
raise CommandExecutionError(
|
||||
"dnf or dnf5 is required to list outdated services."
|
||||
)
|
||||
if not salt.utils.systemd.booted(__context__):
|
||||
raise CommandExecutionError("systemd is required to list outdated services.")
|
||||
|
||||
cmd = ["dnf", "--quiet", "needs-restarting"]
|
||||
if _yum() == "dnf5":
|
||||
cmd = ["dnf5", "--quiet", "needs-restarting"]
|
||||
else:
|
||||
cmd = ["dnf", "--quiet", "needs-restarting"]
|
||||
dnf_output = __salt__["cmd.run_stdout"](cmd, python_shell=False)
|
||||
if not dnf_output:
|
||||
return []
|
||||
|
|
|
@ -3163,6 +3163,15 @@ def test_services_need_restart_no_dnf_output():
|
|||
assert yumpkg.services_need_restart() == []
|
||||
|
||||
|
||||
def test_services_need_restart_no_dnf5_output():
|
||||
patch_yum = patch("salt.modules.yumpkg._yum", Mock(return_value="dnf5"))
|
||||
patch_booted = patch("salt.utils.systemd.booted", Mock(return_value=True))
|
||||
mock_run_stdout = MagicMock(return_value="")
|
||||
patch_run_stdout = patch.dict(yumpkg.__salt__, {"cmd.run_stdout": mock_run_stdout})
|
||||
with patch_yum, patch_booted, patch_run_stdout:
|
||||
assert yumpkg.services_need_restart() == []
|
||||
|
||||
|
||||
def test_61003_pkg_should_not_fail_when_target_not_in_old_pkgs():
|
||||
patch_list_pkgs = patch(
|
||||
"salt.modules.yumpkg.list_pkgs", return_value={}, autospec=True
|
||||
|
|
Loading…
Add table
Reference in a new issue