salt icon indicating copy to clipboard operation
salt copied to clipboard

Non-zero exit status on error?

Open rca opened this issue 13 years ago • 8 comments

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.

rca avatar Feb 28 '13 17:02 rca

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.

UtahDave avatar Mar 01 '13 17:03 UtahDave

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.

rca avatar Mar 01 '13 18:03 rca

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.

rca avatar Mar 01 '13 19:03 rca

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 avatar Mar 04 '13 01:03 terminalmage

@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 avatar Mar 04 '13 05:03 rca

@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

terminalmage avatar Mar 04 '13 05:03 terminalmage

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.

erickyellott avatar May 09 '13 02:05 erickyellott

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

thatch45 avatar May 09 '13 23:05 thatch45