salt icon indicating copy to clipboard operation
salt copied to clipboard

salt and salt-run command popping on _salt_error returns (2015.5.3 and 2015.5.5)

Open junster1 opened this issue 11 years ago • 6 comments

The following command can fail with the following error when a minion returns _salt_error.

salt ‘*’ cmd.run ‘uptime’

Output:

[ERROR   ] An un-handled exception was caught by salt's global exception handler:
KeyError: 'id'
Traceback (most recent call last):
  File "/usr/bin/salt", line 10, in <module>
    salt_main()
  File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 349, in salt_main
    client.run()
  File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 195, in run
    for full_ret in cmd_func(**kwargs):
  File "/usr/lib/python2.7/site-packages/salt/client/__init__.py", line 595, in cmd_cli
    **kwargs):
  File "/usr/lib/python2.7/site-packages/salt/client/__init__.py", line 1298, in get_cli_event_returns
    expect_minions=(verbose or show_timeout)
  File "/usr/lib/python2.7/site-packages/salt/client/__init__.py", line 921, in get_iter_returns
    ret = {raw['data']['id']: raw['data']['data']}
KeyError: 'id'
Traceback (most recent call last):
  File "/usr/bin/salt", line 10, in <module>
    salt_main()
  File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 349, in salt_main
    client.run()
  File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 195, in run
    for full_ret in cmd_func(**kwargs):
  File "/usr/lib/python2.7/site-packages/salt/client/__init__.py", line 595, in cmd_cli
    **kwargs):
 File "/usr/lib/python2.7/site-packages/salt/client/__init__.py", line 1298, in get_cli_event_returns
    expect_minions=(verbose or show_timeout)
  File "/usr/lib/python2.7/site-packages/salt/client/__init__.py", line 921, in get_iter_returns
    ret = {raw['data']['id']: raw['data']['data']}
KeyError: 'id'

Temp fix is to log the minion_id so that we can fix the minion. More permanent fix is to fix the missing key id from the _salt_error event message, or handle it properly in the salt command line code.

Here is our temp fix:

From /usr/lib/python2.7/site-packages/salt/client/__init__.py line 920, I added the loging line to debug the issue and figure out which minion was causing the problem.

        while True:
            # Process events until timeout is reached or all minions have returned
            for raw in ret_iter:
                # if we got None, then there were no events
                if raw is None:
                    break
                if gather_errors:
                    if raw['tag'] == '_salt_error':
                        log.error('found _salt_error for data: %s' % raw)
                        ret = {raw['data']['id']: raw['data']['data']}
                        yield ret
                if 'minions' in raw.get('data', {}):
                    minions.update(raw['data']['minions'])
                    continue
                if 'return' not in raw['data']:
                    continue
                if kwargs.get('raw', False):
                    found.add(raw['data']['id'])
                    yield raw

junster1 avatar Sep 28 '15 00:09 junster1

@junster1, thanks for the report.

jfindlay avatar Sep 28 '15 16:09 jfindlay

@sejeff @jdconti

junster1 avatar Sep 28 '15 19:09 junster1

I do see this conditional (for _salt_error) in 2015.3 but not 2015.5. Are you certain the bug is there in that version as well? If so, could you please point me to the line number where it's stacktracing on that version. I might just be blind and missing it. :]

cachedout avatar Sep 28 '15 19:09 cachedout

On 2015.5.5 it was a salt-run command that was popping on a KeyError 'id', but I can't seem to reproduce it now.

junster1 avatar Sep 29 '15 15:09 junster1

OK. Since this stacktrace only applies to 2015.5.3, we'll need to see one in 2015.5.5 before we can do much to really address this. We'll wait to see if this comes back.

cachedout avatar Sep 30 '15 19:09 cachedout

I am still seeing this issue with 2015.5.6. I don't have a reliable way of putting a minion into the state that causes this, but I think it would be pretty simple to wrap that statement in a try/except to catch the error on the server side enough that you can at least tell which minion is having the issue, and continue the ouput of the original command.

junster1 avatar Nov 24 '15 18:11 junster1