mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Exclude salt-ssh error returns from mine
This commit is contained in:
parent
7411dcc2d5
commit
41e35b59e7
2 changed files with 24 additions and 5 deletions
|
@ -10,10 +10,13 @@ Wrapper function for mine operations for salt-ssh
|
|||
|
||||
|
||||
import copy
|
||||
import logging
|
||||
|
||||
import salt.client.ssh
|
||||
import salt.daemons.masterapi
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get(
|
||||
tgt, fun, tgt_type="glob", roster="flat", ssh_minions=True, regular_minions=False
|
||||
|
@ -97,9 +100,24 @@ def get(
|
|||
for ret in ssh.run_iter(mine=True):
|
||||
mrets.update(ret)
|
||||
|
||||
for host in mrets:
|
||||
if "return" in mrets[host]:
|
||||
rets[host] = mrets[host]["return"]
|
||||
for host, data in mrets.items():
|
||||
if not isinstance(data, dict):
|
||||
log.error(
|
||||
f"Error executing mine func {fun} on {host}: {data}."
|
||||
" Excluding minion from mine."
|
||||
)
|
||||
elif "_error" in data:
|
||||
log.error(
|
||||
f"Error executing mine func {fun} on {host}: {data['_error']}."
|
||||
" Excluding minion from mine. Full output in debug log."
|
||||
)
|
||||
log.debug(f"Return was: {salt.utils.json.dumps(data)}")
|
||||
elif "return" not in data:
|
||||
log.error(
|
||||
f"Error executing mine func {fun} on {host}: No return was specified."
|
||||
" Excluding minion from mine. Full output in debug log."
|
||||
)
|
||||
log.debug(f"Return was: {salt.utils.json.dumps(data)}")
|
||||
else:
|
||||
rets[host] = mrets[host]
|
||||
rets[host] = data["return"]
|
||||
return rets
|
||||
|
|
|
@ -81,7 +81,7 @@ def test_mine_get(salt_ssh_cli, salt_minion, tgts):
|
|||
assert ret.data[id_] is True
|
||||
|
||||
|
||||
def test_ssh_mine_get_error(salt_ssh_cli):
|
||||
def test_ssh_mine_get_error(salt_ssh_cli, caplog):
|
||||
"""
|
||||
Test that a mine function returning an error is not
|
||||
included in the output.
|
||||
|
@ -89,3 +89,4 @@ def test_ssh_mine_get_error(salt_ssh_cli):
|
|||
ret = salt_ssh_cli.run("mine.get", "localhost", "disk.usage")
|
||||
assert ret.returncode == 0
|
||||
assert not ret.data
|
||||
assert "Error executing mine func disk.usage" in caplog.text
|
||||
|
|
Loading…
Add table
Reference in a new issue