Merge pull request #23105 from ngrennan-inflection/salt-ssh-return-code

Fixing return code to be "1" instead of 0 when the return code of a run is something other than 0
This commit is contained in:
Mike Place 2015-06-17 12:37:23 -06:00
commit e99863cd1d
3 changed files with 21 additions and 6 deletions

View File

@ -20,6 +20,7 @@ import yaml
import uuid
import tempfile
import binascii
import sys
# Import salt libs
import salt.client.ssh.shell
@ -529,8 +530,13 @@ class SSH(object):
print('')
sret = {}
outputter = self.opts.get('output', 'nested')
final_exit = 0
for ret in self.handle_ssh():
host = next(six.iterkeys(ret))
host_ret = ret[host].get('retcode', 0)
if host_ret != 0:
final_exit = 1
self.cache_job(jid, host, ret[host], fun)
ret = self.key_deploy(host, ret)
if not isinstance(ret[host], dict):
@ -558,6 +564,8 @@ class SSH(object):
sret,
outputter,
self.opts)
if final_exit:
sys.exit(salt.defaults.exitcodes.EX_AGGREGATE)
class Single(object):
@ -711,7 +719,7 @@ class Single(object):
stdout, stderr, retcode = self.shell.exec_cmd(cmd_str)
elif self.fun in self.wfuncs or self.mine:
stdout = self.run_wfunc()
stdout, retcode = self.run_wfunc()
else:
stdout, stderr, retcode = self.cmd_block()
@ -770,11 +778,12 @@ class Single(object):
opts_pkg['_caller_cachedir'] = self.opts['cachedir']
# Use the ID defined in the roster file
opts_pkg['id'] = self.id
retcode = opts_pkg['retcode']
if '_error' in opts_pkg:
# Refresh failed
ret = json.dumps({'local': opts_pkg})
return ret
return ret, retcode
pillar = salt.pillar.Pillar(
opts_pkg,
@ -852,7 +861,7 @@ class Single(object):
ret = json.dumps({'local': result['local']})
else:
ret = json.dumps({'local': {'return': result}})
return ret
return ret, retcode
def _cmd_str(self):
'''

View File

@ -114,20 +114,23 @@ class FunctionWrapper(object):
minion_opts=self.minion_opts,
**self.kwargs
)
stdout, stderr, _ = single.cmd_block()
stdout, stderr, retcode = single.cmd_block()
if stderr.count('Permission Denied'):
return {'_error': 'Permission Denied',
'stdout': stdout,
'stderr': stderr}
'stderr': stderr
'retcode': retcode}
try:
ret = json.loads(stdout, object_hook=salt.utils.decode_dict)
if len(ret) < 2 and 'local' in ret:
ret = ret['local']
ret = ret.get('return', {})
ret.update({'retcode': retcode})
except ValueError:
ret = {'_error': 'Failed to return clean data',
'stderr': stderr,
'stdout': stdout}
'stdout': stdout,
'retcode': retcode}
return ret
return caller

View File

@ -15,6 +15,9 @@ EX_THIN_DEPLOY = 11
EX_THIN_CHECKSUM = 12
EX_MOD_DEPLOY = 13
# One of a collection failed
EX_AGGREGATE = 20
# The os.EX_* exit codes are Unix only so in the interest of cross-platform
# compatiblility define them explicitly here.
#