mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Allow failhard to work with the salt-api. Gracefully stop iteration during failhard.
This commit is contained in:
parent
8caacf0146
commit
7f155ba69a
@ -21,7 +21,9 @@ from salt.utils import print_cli
|
||||
import salt.ext.six as six
|
||||
from salt.ext.six.moves import range
|
||||
# pylint: enable=import-error,no-name-in-module,redefined-builtin
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class Batch(object):
|
||||
'''
|
||||
@ -245,8 +247,12 @@ class Batch(object):
|
||||
if bwait:
|
||||
wait.append(datetime.now() + timedelta(seconds=bwait))
|
||||
# Munge retcode into return data
|
||||
failhard = False
|
||||
if 'retcode' in data and isinstance(data['ret'], dict) and 'retcode' not in data['ret']:
|
||||
data['ret']['retcode'] = data['retcode']
|
||||
if self.opts.get('failhard') and data['ret']['retcode'] > 0:
|
||||
failhard = True
|
||||
|
||||
if self.opts.get('raw'):
|
||||
ret[minion] = data
|
||||
yield data
|
||||
@ -264,6 +270,9 @@ class Batch(object):
|
||||
data,
|
||||
out,
|
||||
self.opts)
|
||||
if failhard:
|
||||
log.error('ERROR: Minion {} returned with non-zero exit code. Batch run stopped due to failhard'.format(minion))
|
||||
raise StopIteration
|
||||
|
||||
# remove inactive iterators from the iters list
|
||||
for queue in minion_tracker:
|
||||
|
@ -262,14 +262,6 @@ class SaltCMD(parsers.SaltCMDOptionParser):
|
||||
if job_retcode > retcode:
|
||||
# Exit with the highest retcode we find
|
||||
retcode = job_retcode
|
||||
if self.options.failhard:
|
||||
if retcode != 0:
|
||||
sys.stderr.write(
|
||||
'{0}\nERROR: Minions returned with non-zero exit code.\n'.format(
|
||||
res
|
||||
)
|
||||
)
|
||||
sys.exit(retcode)
|
||||
sys.exit(retcode)
|
||||
|
||||
def _print_errors_summary(self, errors):
|
||||
|
@ -560,6 +560,7 @@ class LocalClient(object):
|
||||
'tgt_type': tgt_type,
|
||||
'ret': ret,
|
||||
'batch': batch,
|
||||
'failhard': kwargs.get('failhard', False),
|
||||
'raw': kwargs.get('raw', False)}
|
||||
|
||||
if 'timeout' in kwargs:
|
||||
|
Loading…
Reference in New Issue
Block a user