-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
salt-ssh swallows exceptions in custom modules #52452
Comments
I tested it on version 2019.2.0. It is the same. The important stacktrace is even not visible if you use Just for the records. To get 2019.2.0 working, I had to work-around #51768. |
Someone may be able to correct me, but I'm not sure that's what modules are for. Modules are typically executed either like:
Or, using states:
Just for some further information, could you try using the test state like so:
You might also try:
HTH! |
it is possible to use execution modules in a state like the original poster is doing. The problem here is when you run it with salt-call you can see the exception, but not in salt-ssh. This is because of here: https://github.com/saltstack/salt/blob/v2018.3.4/salt/client/ssh/ssh_py_shim.py#L281 and even if you were to change that to debug you still will not see it, because we are not currently adding the ssh logs from the salt-call log output. We could probably grab the stream from the logs and add it to the log output on the salt-ssh original host and change quiet to what the user sets. |
@Ch3LL to grab the stream from the logs and add it to the log output is no solution for me. If there is an exception the whole thing should stop. See Zen of Python line 10. |
@waynew If I use this:
The output is:
Sorry: no new insights. |
That's definitely not an acceptable approach for Salt. We especially do not want a user's custom (and potentially poorly tested code) to crash Salt. The error should be reported, potentially including the stack trace, but completely halting the execution on failure is not what most people need or want. |
to follow up on the idea of grabbing the debug logs. looks like i was not correct about that. When you run the module with salt-call even with quiet it does include the exception where salt-ssh does not. So the solution for salt-ssh to show the exception would be somewhere else. |
I really would like to see my salt-ssh command to fail if there is an exception in a custom module. I want it very much. Maybe there is an alternative solution, an alternative way, an alternative tool. |
Fail or stop? Where fail means something like: fail.py
And stop means something like stop.py
|
@waynew you ask: "fail or stop?". I think "fail" would fit. |
Then Salt is definitely not the tool you're looking for - that goal is completely antithetical to a tool like Salt. Fabric may be more to your liking. That being said, this state file:
With this custom module (foo.py):
Should most certainly never be truthy. Ideally we would fail similar to something like this:
But something like |
Today I came across this swallowing of exceptions again. But I am deeply relaxed. I will switch my job in one week, and then I don't need to work with salt any more. I am relieved. Ansible is coming. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue. |
. |
Thank you for updating this issue. It is no longer marked as stale. |
I think the previous conversation misses the point of this bug. This behavior is not specific to custom modules. Try running the following via salt-ssh: This should fail being rendered:
test.show_notification:
- text: {{ salt["disk.usage"]("c") | yaml_dquote }} The output of This is caused by the The usual (expected) behavior is that rendering is aborted, while this bug can result in surprising outcomes. The following (PoC) patch causes exceptions to be thrown and rendering to be aborted, as expected: --- a/salt/client/ssh/wrapper/__init.py
+++ b/salt/client/ssh/wrapper/__init.py
@@ -9,6 +9,7 @@
import copy
import salt.client.ssh
+import salt.exceptions
import salt.loader
import salt.utils.data
import salt.utils.json
@@ -126,6 +127,8 @@
"stderr": stderr,
"retcode": retcode,
}
+ if retcode:
+ raise salt.exceptions.CommandExecutionError(stderr)
try:
ret = salt.utils.json.loads(stdout)
if len(ret) < 2 and "local" in ret: Since the patched class is also used for running any module via Edit: For reference, here is what happens with $ salt-call state.apply render_fail
[ERROR ] Rendering exception occurred
Traceback (most recent call last):
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/templates.py", line 476, in render_jinja_tmpl
output = template.render(**decoded_context)
File "/opt/saltstack/salt/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/opt/saltstack/salt/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 3, in top-level template code
File "/opt/saltstack/salt/lib/python3.10/site-packages/jinja2/sandbox.py", line 393, in call
return __context.call(__obj, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1232, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1247, in _run_as
return _func_or_method(*args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/disk.py", line 92, in usage
flags = _clean_flags(args, "disk.usage")
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/disk.py", line 74, in _clean_flags
raise CommandExecutionError("Invalid flag passed to {}".format(caller))
salt.exceptions.CommandExecutionError: Invalid flag passed to disk.usage
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/templates.py", line 218, in render_tmpl
output = render_str(tmplstr, context, tmplpath)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/templates.py", line 500, in render_jinja_tmpl
raise SaltRenderError(
salt.exceptions.SaltRenderError: Problem running salt function in Jinja template: Invalid flag passed to disk.usage; line 3
---
This should fail being rendered:
test.show_notification:
- text: {{ salt["disk.usage"]("c") | yaml_dquote }} <======================
---
[CRITICAL] Rendering SLS 'base:render_fail' failed: Problem running salt function in Jinja template: Invalid flag passed to disk.usage; line 3
---
This should fail being rendered:
test.show_notification:
- text: {{ salt["disk.usage"]("c") | yaml_dquote }} <======================
---
local:
Data failed to compile:
----------
Rendering SLS 'base:render_fail' failed: Problem running salt function in Jinja template: Invalid flag passed to disk.usage; line 3
---
This should fail being rendered:
test.show_notification:
- text: {{ salt["disk.usage"]("c") | yaml_dquote }} <======================
--- |
Description of Issue/Question
Setup
You see: an exception in the custom module does silently get a boolean True.
At least on my system: salt 2018.3.2 (Oxygen)
Versions Report
Related discussion on the user mailing list: https://groups.google.com/forum/#!topic/salt-users/jbtZ5T92xCY
The text was updated successfully, but these errors were encountered: