mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
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:
commit
e99863cd1d
@ -20,6 +20,7 @@ import yaml
|
|||||||
import uuid
|
import uuid
|
||||||
import tempfile
|
import tempfile
|
||||||
import binascii
|
import binascii
|
||||||
|
import sys
|
||||||
|
|
||||||
# Import salt libs
|
# Import salt libs
|
||||||
import salt.client.ssh.shell
|
import salt.client.ssh.shell
|
||||||
@ -529,8 +530,13 @@ class SSH(object):
|
|||||||
print('')
|
print('')
|
||||||
sret = {}
|
sret = {}
|
||||||
outputter = self.opts.get('output', 'nested')
|
outputter = self.opts.get('output', 'nested')
|
||||||
|
final_exit = 0
|
||||||
for ret in self.handle_ssh():
|
for ret in self.handle_ssh():
|
||||||
host = next(six.iterkeys(ret))
|
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)
|
self.cache_job(jid, host, ret[host], fun)
|
||||||
ret = self.key_deploy(host, ret)
|
ret = self.key_deploy(host, ret)
|
||||||
if not isinstance(ret[host], dict):
|
if not isinstance(ret[host], dict):
|
||||||
@ -558,6 +564,8 @@ class SSH(object):
|
|||||||
sret,
|
sret,
|
||||||
outputter,
|
outputter,
|
||||||
self.opts)
|
self.opts)
|
||||||
|
if final_exit:
|
||||||
|
sys.exit(salt.defaults.exitcodes.EX_AGGREGATE)
|
||||||
|
|
||||||
|
|
||||||
class Single(object):
|
class Single(object):
|
||||||
@ -711,7 +719,7 @@ class Single(object):
|
|||||||
stdout, stderr, retcode = self.shell.exec_cmd(cmd_str)
|
stdout, stderr, retcode = self.shell.exec_cmd(cmd_str)
|
||||||
|
|
||||||
elif self.fun in self.wfuncs or self.mine:
|
elif self.fun in self.wfuncs or self.mine:
|
||||||
stdout = self.run_wfunc()
|
stdout, retcode = self.run_wfunc()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
stdout, stderr, retcode = self.cmd_block()
|
stdout, stderr, retcode = self.cmd_block()
|
||||||
@ -770,11 +778,12 @@ class Single(object):
|
|||||||
opts_pkg['_caller_cachedir'] = self.opts['cachedir']
|
opts_pkg['_caller_cachedir'] = self.opts['cachedir']
|
||||||
# Use the ID defined in the roster file
|
# Use the ID defined in the roster file
|
||||||
opts_pkg['id'] = self.id
|
opts_pkg['id'] = self.id
|
||||||
|
retcode = opts_pkg['retcode']
|
||||||
|
|
||||||
if '_error' in opts_pkg:
|
if '_error' in opts_pkg:
|
||||||
# Refresh failed
|
# Refresh failed
|
||||||
ret = json.dumps({'local': opts_pkg})
|
ret = json.dumps({'local': opts_pkg})
|
||||||
return ret
|
return ret, retcode
|
||||||
|
|
||||||
pillar = salt.pillar.Pillar(
|
pillar = salt.pillar.Pillar(
|
||||||
opts_pkg,
|
opts_pkg,
|
||||||
@ -852,7 +861,7 @@ class Single(object):
|
|||||||
ret = json.dumps({'local': result['local']})
|
ret = json.dumps({'local': result['local']})
|
||||||
else:
|
else:
|
||||||
ret = json.dumps({'local': {'return': result}})
|
ret = json.dumps({'local': {'return': result}})
|
||||||
return ret
|
return ret, retcode
|
||||||
|
|
||||||
def _cmd_str(self):
|
def _cmd_str(self):
|
||||||
'''
|
'''
|
||||||
|
@ -114,20 +114,23 @@ class FunctionWrapper(object):
|
|||||||
minion_opts=self.minion_opts,
|
minion_opts=self.minion_opts,
|
||||||
**self.kwargs
|
**self.kwargs
|
||||||
)
|
)
|
||||||
stdout, stderr, _ = single.cmd_block()
|
stdout, stderr, retcode = single.cmd_block()
|
||||||
if stderr.count('Permission Denied'):
|
if stderr.count('Permission Denied'):
|
||||||
return {'_error': 'Permission Denied',
|
return {'_error': 'Permission Denied',
|
||||||
'stdout': stdout,
|
'stdout': stdout,
|
||||||
'stderr': stderr}
|
'stderr': stderr
|
||||||
|
'retcode': retcode}
|
||||||
try:
|
try:
|
||||||
ret = json.loads(stdout, object_hook=salt.utils.decode_dict)
|
ret = json.loads(stdout, object_hook=salt.utils.decode_dict)
|
||||||
if len(ret) < 2 and 'local' in ret:
|
if len(ret) < 2 and 'local' in ret:
|
||||||
ret = ret['local']
|
ret = ret['local']
|
||||||
ret = ret.get('return', {})
|
ret = ret.get('return', {})
|
||||||
|
ret.update({'retcode': retcode})
|
||||||
except ValueError:
|
except ValueError:
|
||||||
ret = {'_error': 'Failed to return clean data',
|
ret = {'_error': 'Failed to return clean data',
|
||||||
'stderr': stderr,
|
'stderr': stderr,
|
||||||
'stdout': stdout}
|
'stdout': stdout,
|
||||||
|
'retcode': retcode}
|
||||||
return ret
|
return ret
|
||||||
return caller
|
return caller
|
||||||
|
|
||||||
|
@ -15,6 +15,9 @@ EX_THIN_DEPLOY = 11
|
|||||||
EX_THIN_CHECKSUM = 12
|
EX_THIN_CHECKSUM = 12
|
||||||
EX_MOD_DEPLOY = 13
|
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
|
# The os.EX_* exit codes are Unix only so in the interest of cross-platform
|
||||||
# compatiblility define them explicitly here.
|
# compatiblility define them explicitly here.
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user