Non-zero exit status on error?
I noticed that even when a state and/or any of its requirements fail, exit status is always zero.
Is this by design? It'd be nice to have non-zero exit status when highstate is not reached cleanly.
Thanks.
I completely agree that this would be awesome. The decision that was made a while ago was that the actual Salt application did execute successfully so it returns 0.
I suppose that's a matter of opinion. I agree Salt did not crash, but I'm running Salt to ensure my system is in a particular state. In the event where Salt is not able to put a system into that state it was not successful and I have no way of knowing.
Exit status is not just binary 0 or 1. What about:
- status 0 = your system is the way you expect it
- status 1 = Salt barfed
- status 2 = Salt ran fine, but you're still not where you want to be.
Here's a simple example of what I mean in standard UNIX cp:
$ mkdir tmp/no
$ chmod 000 tmp/no
$ cp sent tmp/no
cp: tmp/no/sent: Permission denied
$ echo $?
1
$ chmod 755 tmp/no
$ cp sent tmp/no
$ echo $?
0
When cp can't copy a file it doesn't crash, but your intent wasn't fulfilled, so it doesn't exit 0.
Another issue with doing this would be that the salt CLI exits eventually when there are long-running jobs, so it wouldn't know the outcome until the minion finally finished and reported back.
@terminalmage, do you mean that the exit status is irrelevant in the grand scheme of things? I ran into this in the context of running salt-call, but I think I understand what you're trying to say.
@rca Yeah, I guess you could say that. The salt CLI command orders minions to run jobs. The results of the job are then sent back to the master via the event system. The salt CLI tool will keep polling the event system for results on the jobs it executed, but after a certain point it will just give up. If you're running a particularly long job (such as installing packages in Gentoo using emerge, where the minion may take a while to finish compiling and installing), then the CLI will eventually stop looking for results, but when that job completes its results will be returned to the master (where they can be looked up at a later time).
I can see the use of having an individual salt-call, run locally on the minion, return a non-zero exit status though:
$ sudo salt-call pkg.install foobarbaz12345
Loaded plugins: fastestmirror, rhnplugin
This system is receiving updates from RHN Classic or RHN Satellite.
Loading mirror speeds from cached hostfile
[ERROR ] Package "foobarbaz12345" failed to install
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/modules/yumpkg.py", line 334, in install
a = yb.install(pattern=target)
File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 3509, in install
raise Errors.InstallError, _('No package(s) available to install')
InstallError: No package(s) available to install
Running rpm_check_debug
{'local': {}}
$ echo $?
0
I'm running salt-call --local state.highstate with a fab script, and even when the highstate executes successfully, I get a non-zero status code:
Fatal error: sudo() received nonzero return code 2 while executing!
Which will kill the script from doing anything after that.
Looks like we need to clean that out! I acctually think that this issue should be closed, and we should open up a new issue for the return code