add code to pass full_return through stack so exceptions can return retcode properly to salt-run cli

This commit is contained in:
Thomas Phipps 2023-06-13 19:33:09 +00:00 committed by Megan Wilhite
parent a7d7c4151b
commit c1292aecbf
4 changed files with 38 additions and 5 deletions

1
changelog/61173.fixed.md Normal file
View file

@ -0,0 +1 @@
fix fixed runner not having a proper exit code when runner modules throw an exception.

View file

@ -412,6 +412,7 @@ class SyncClientMixin(ClientStateMixin):
traceback.format_exc(),
)
data["success"] = False
data["retcode"] = 1
if self.store_job:
try:
@ -480,7 +481,17 @@ class AsyncClientMixin(ClientStateMixin):
@classmethod
def _proc_function_remote(
cls, *, instance, opts, fun, low, user, tag, jid, daemonize=True
cls,
*,
instance,
opts,
fun,
low,
user,
tag,
jid,
daemonize=True,
full_return=False
):
"""
Run this method in a multiprocess target to execute the function on the
@ -506,13 +517,23 @@ class AsyncClientMixin(ClientStateMixin):
instance = cls(opts)
try:
return instance.cmd_sync(low)
return instance.cmd_sync(low, full_return=False)
except salt.exceptions.EauthAuthenticationError as exc:
log.error(exc)
@classmethod
def _proc_function(
cls, *, instance, opts, fun, low, user, tag, jid, daemonize=True
cls,
*,
instance,
opts,
fun,
low,
user,
tag,
jid,
daemonize=True,
full_return=False
):
"""
Run this method in a multiprocess target to execute the function
@ -537,7 +558,7 @@ class AsyncClientMixin(ClientStateMixin):
low["__user__"] = user
low["__tag__"] = tag
return instance.low(fun, low)
return instance.low(fun, low, full_return=full_return)
def cmd_async(self, low):
"""

View file

@ -289,7 +289,7 @@ class Runner(RunnerClient):
# otherwise run it in the main process
if self.opts.get("eauth"):
ret = self.cmd_sync(low)
ret = self.cmd_sync(low, full_return=True)
if isinstance(ret, dict) and set(ret) == {"data", "outputter"}:
outputter = ret["outputter"]
ret = ret["data"]
@ -306,6 +306,7 @@ class Runner(RunnerClient):
tag=async_pub["tag"],
jid=async_pub["jid"],
daemonize=False,
full_return=True,
)
except salt.exceptions.SaltException as exc:
with salt.utils.event.get_event("master", opts=self.opts) as evt:

View file

@ -0,0 +1,10 @@
import logging
log = logging.getLogger(__name__)
def test_exception_exit(salt_run_cli):
ret = salt_run_cli.run(
"error.error", "name='Exception'", "message='This is an error.'"
)
assert ret.returncode == 1