Fix show error report from salt.function

When no minions matched the default "No change made .." error was show
rather than the No minions responded error.
This commit is contained in:
Michael Birtwell 2020-07-10 12:38:31 +01:00 committed by Daniel Wozniak
parent 95b4f6d14e
commit 387b82784e
3 changed files with 25 additions and 1 deletions

2
changelog/57920.fixed Normal file
View file

@ -0,0 +1,2 @@
Set the comment to "No minions responded" if salt.function fails to find any
minions

View file

@ -577,7 +577,7 @@ def function(
changes[minion] = m_ret
if not cmd_ret:
func_ret["result"] = False
func_ret["command"] = "No minions responded"
func_ret["comment"] = "No minions responded"
else:
if changes:
func_ret["changes"] = {"out": "highstate", "ret": changes}

View file

@ -226,6 +226,28 @@ class SaltmodTestCase(TestCase, LoaderModuleMockMixin):
with patch.dict(saltmod.__salt__, {"saltutil.cmd": mock_cmd}):
self.assertDictEqual(saltmod.function(name, tgt), ret)
@slowTest
def test_function_when_no_minions_match(self):
"""
Test to execute a single module function on a remote
minion via salt or salt-ssh
"""
name = "state"
tgt = "larry"
mock_ret = {}
mock_cmd = MagicMock(return_value=mock_ret)
ret = {
"name": name,
"changes": {},
"result": False,
"comment": "No minions responded",
}
with patch.dict(saltmod.__opts__, {"test": False}):
with patch.dict(saltmod.__salt__, {"saltutil.cmd": mock_cmd}):
self.assertDictEqual(saltmod.function(name, tgt), ret)
# 'wait_for_event' function tests: 1
def test_wait_for_event(self):