Skip to content

Can't get batch mode and --failhard to work as expected #29643

Closed

Description

@matthayes

I'm using a command like this below to execute state.highstate on one machine at a time, with the intention that it stop on the first failure. But, it's not stopping even though there is a failure.

sudo salt -b 1 --failhard -G 'roles:foo' state.highstate

The cause of the failure is a http_test.ping custom module function I wrote that checks that an HTTP call is succeeding. I gave it a bogus path to force it to fail. I'm testing this against two minions. Looking at the minion logs I can see the calls are failing. But, the output I get from the salt command above is essentially:

Executing run on ['some-machine-A']

retcode:
    0

Executing run on ['some-machine-B']

some-machine-B:    <-- highlighted red

(... lots of SLS state output ...)

----------
ID: Ping the web app    <-- all highlighted red
    Function: http_test.ping
      Result: False
     Comment: Call to http://localhost:80/pingping failed. Error: HTTP 404: NOT FOUND. HTTP status: 404
     Started: 22:52:49.686395
    Duration: 57.519 ms
     Changes: 

(... more SLS state output ...)

So, you can see that the Ping the web app call is failing and has Result: False. This happens for both machines. But, the retcode for both machines is apparently 0. I ran the same command again with --out=yaml appended, which showed me that retcode is 0 for both machines.

Maybe this isn't a problem with the batch mode but instead a problem with how retcode is determined. Am I missing something? Shouldn't the retcode be non-zero since the state has Result: False?

Activity

  1. matthayes commented on Dec 12, 2015

    @matthayes
    Author

    I've also tried following the events by running sudo salt-run state.event pretty=True. Here I also see that retcode is 0 for both state.highstate executions. How is the value of retcode determined? Is it not based on the state success or failure?

  2. matthayes commented on Dec 12, 2015

    @matthayes
    Author

    As a test I tried adding some logging to get_retcode that I saw mentioned in #22855 . What I found is that the final else is executing, meaning that the default retcode of 0 is returned. I also tried dumping ret. It looks like it only consists of keys corresponding to each state that is executed. I don't see any useful return values that could be used to detect failure.

    def get_retcode(ret):
        '''
        Determine a retcode for a given return
        '''
        retcode = 0
        # if there is a dict with retcode, use that
        if isinstance(ret, dict) and ret.get('retcode', 0) != 0:
            log.error("Found retcode: " + ret['retcode'])
            return ret['retcode']
        # if its a boolean, False means 1
        elif isinstance(ret, bool) and not ret:
            log.error("Found bool value, returning 1")
            return 1
        else:
            log.error("No retcode found, returning default: " + str(retcode))
        return retcode
    

    Also, if I remove -b 1 --failhard from the command, get_retcode is logging different output (below). This time there is a retcode with value 0, which still doesn't seem right since one of the states has a false result.

    {
        "out": "highstate",
        "ret": {  ... ommitted .. },
        "retcode": 0
    }
    

    Also this seems to indicate a bug in how get_retcode is called in these two cases. In batch mode it appears that the value of ret is passed to get_retcode, which doesn't have retcode. But when not in batch mode the parent object that contains ret is passed to it, which does contain retcode.

  3. matthayes commented on Dec 12, 2015

    @matthayes
    Author

    @jacksontj thoughts on this?

  4. matthayes commented on Dec 14, 2015

    @matthayes
    Author

    @basepi , wanted to bring this to your attention as it is related to your suggestion in #1038 .

  5. matthayes commented on Dec 14, 2015

    @matthayes
    Author

    To summarize, I think there are two issues:

    1. The retcode coming back from the minion for state.highstate is zero even though one of the result values is false.
    2. In batch mode, even if we were getting back a non-zero value for retcode we would never know because the wrong object is passed to get_retcode in salt.py.
  6. lorengordon commented on Dec 14, 2015

    @lorengordon
    Contributor

    Does salt support --retcode-passthrough or is that only an option for salt-call? (I only use masterless, so I don't have a master to check with...)

    https://docs.saltstack.com/en/latest/ref/cli/salt-call.html#cmdoption-salt-call--retcode-passthrough

  7. matthayes commented on Dec 14, 2015

    @matthayes
    Author

    Not that I've seen. I think that's only supported by salt-call.

  8. added
    bug
    severity-medium
    Core
    P3
    on Dec 14, 2015
  9. added this to the Approved milestone on Dec 14, 2015
  10. basepi commented on Dec 14, 2015

    @basepi
    Contributor

    thanks for the ping, @matthayes. This looks like something we need to get fixed.

  11. matthayes commented on Dec 14, 2015

    @matthayes
    Author

    I can help diagnose the issue on my side but I need some pointers for what code to check. I've been adding logging to dig deeper but I've reached the limit of my familiarity with the Salt code. Can you point me to where in the code the minion returns the retcode to the master? Or let me know if there is something I can do to help find the problem. I was working on automating some deployment but now I'm stuck until this is fixed so I am motivated to identify the problem :)

  12. 65 remaining items

  13. modified the milestones: Approved, B 4 on Feb 2, 2016
  14. DmitryKuzmenko commented on Feb 12, 2016

    @DmitryKuzmenko
    Contributor

    @matthayes I've just fixed this. All details provided in the PR #31164

  15. added
    fixed-pls-verify
    on Feb 12, 2016
  16. danlsgiga commented on Feb 12, 2016

    @danlsgiga
    Contributor

    This may fix an issue I've opened for a few months already. #24996
    Thanks for the fix @DmitryKuzmenko

  17. DmitryKuzmenko commented on Feb 12, 2016

    @DmitryKuzmenko
    Contributor

    @danlsgiga you're welcome!

  18. added
    ZD
    on Feb 12, 2016
  19. modified the milestones: B 3, Approved on Feb 12, 2016
  20. matthayes commented on Feb 16, 2016

    @matthayes
    Author

    @DmitryKuzmenko thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CoreP3State-CompilerZDZRELEASED - Boronbugfixed-pls-verifyseverity-medium

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions