Skip to content
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

Return system exit codes on failures #14435

Closed
powellchristoph opened this issue Jul 23, 2014 · 9 comments
Closed

Return system exit codes on failures #14435

powellchristoph opened this issue Jul 23, 2014 · 9 comments
Labels
Bug broken, incorrect, or confusing behavior Duplicate Duplicate of another issue or PR - will be closed stale
Milestone

Comments

@powellchristoph
Copy link

When executing salt states or modules from the command line, it would be extremely helpful for it to return standard system exit codes.

When combined with other automation pieces, it is impossible to catch any possible errors. I have seen other reasons why there are no codes returned, but as OPS using this tool, I need to know if something went wrong. Anything non-zero would be ok.

For example, when an SLS is not found.

user@server:~$ sudo salt -v -G 'roles:web_server' state.sls web_server test-org
Executing job with jid 20140723180505863893
-------------------------------------------

web01:
    Data failed to compile:
----------
    No matching sls found for 'web_server' in env 'test-org'

user@server:~$ echo $?
0

But, when no minions match a glob?

user@server:~$ sudo salt pho* grains.items
No minions matched the target. No command was sent, no jid was assigned.
user@server:~$ echo $?
2
@basepi
Copy link
Contributor

basepi commented Jul 23, 2014

Pretty sure #11337 fixes this issue, but those changes do not exist in the current release of salt, they will be in the next feature release (2014.7.0) which should go into release candidate very very soon, and full release in a month or two.

@basepi
Copy link
Contributor

basepi commented Jul 23, 2014

Would you mind testing on the develop branch or the 2014.7 branch to verify?

@basepi basepi added this to the Blocked milestone Jul 23, 2014
@powellchristoph
Copy link
Author

Sure thing. I will look at it today/tomorrow.

On Wed, Jul 23, 2014 at 7:11 PM, Colton Myers notifications@github.com
wrote:

Would you mind testing on the develop branch or the 2014.7 branch to
verify?


Reply to this email directly or view it on GitHub
#14435 (comment).

@powellchristoph
Copy link
Author

Some quick testing and it looks like its working. I will do some more indepth with my own states when I can put more time into it. Guess I need to upgrade soon. What's the timeline for release?

(salt-test)root@cpowell-saltmaster-dev:~/salt-test# salt -c etc/salt \* state.sls notfoundstate.sls
saltdev:
    Data failed to compile:
----------
    No matching sls found for 'notfoundstate.sls' in env 'base'
(salt-test)root@cpowell-saltmaster-dev:~/salt-test# echo $?
11
(salt-test)root@cpowell-saltmaster-dev:~/salt-test# salt -c etc/salt notfoundminion test.ping
No minions matched the target. No command was sent, no jid was assigned.
(salt-test)root@cpowell-saltmaster-dev:~/salt-test# echo $?
2
(salt-test)root@cpowell-saltmaster-dev:~/salt-test# salt -c etc/salt \* cmd.run 'exit 1'
saltdev:

(salt-test)root@cpowell-saltmaster-dev:~/salt-test# echo $?
11
(salt-test)root@cpowell-saltmaster-dev:~/salt-test# salt -c etc/salt \* cmd.run 'exit 0'
saltdev:

(salt-test)root@cpowell-saltmaster-dev:~/salt-test# echo $?
0

@basepi
Copy link
Contributor

basepi commented Jul 24, 2014

We should have 2014.7.0rc1 out first thing next week, and the final release is expected 4-6 weeks after that, depending on how the release candidate is received.

@basepi
Copy link
Contributor

basepi commented Jul 24, 2014

I'm going to close this, since it's been implemented.

@basepi basepi closed this as completed Jul 24, 2014
@uvsmtid
Copy link
Contributor

uvsmtid commented Mar 18, 2015

Please re-open this bug. It still exists in 2014.7.2:

> salt --versions-report
           Salt: 2014.7.2
         Python: 2.7.8 (default, Nov 10 2014, 08:19:18)
         Jinja2: 2.7.3
       M2Crypto: 0.21.1
 msgpack-python: 0.4.6
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.11
          ioflo: Not Installed
          PyZMQ: 14.3.1
           RAET: Not Installed
            ZMQ: 3.2.5
           Mako: 1.0.0

I'm also linking it to #18510 - an "umbrella" issue for many other expected non-zero codes.

It is easily reproducible:

  • Create a dummy.sls state like this:

    > cat dummy.sls
    run_problematic_command:
        cmd.run:
            - name: 'false'
    
  • Execute salt or salt-call (salt in this output):

    > salt 'minion_id' state.sls dummy
    projector:
    ----------
              ID: run_problematic_command
        Function: cmd.run
            Name: false
          Result: False
         Comment: Command "false" run
         Started: 14:47:12.600703
        Duration: 7.304 ms
         Changes:   
                  ----------
                  pid:
                      9046
                  retcode:
                      1
                  stderr:
    
                  stdout:
    
    
    Summary
    ------------
    Succeeded: 0 (changed=1)
    Failed:    1
    ------------
    Total states run:     1
    
  • Check error code:

    > echo $?
    0
    

@rallytime
Copy link
Contributor

Thanks for updating us here @uvsmtid.

@rallytime rallytime reopened this Mar 18, 2015
@rallytime rallytime removed the fixed-pls-verify fix is linked, bug author to confirm fix label Mar 18, 2015
@stale
Copy link

stale bot commented Oct 20, 2017

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.

@stale stale bot added the stale label Oct 20, 2017
@stale stale bot closed this as completed Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Duplicate Duplicate of another issue or PR - will be closed stale
Projects
None yet
Development

No branches or pull requests

4 participants