mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +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
|
import salt.ext.six as six
|
||||||
from salt.ext.six.moves import range
|
from salt.ext.six.moves import range
|
||||||
# pylint: enable=import-error,no-name-in-module,redefined-builtin
|
# pylint: enable=import-error,no-name-in-module,redefined-builtin
|
||||||
|
import logging
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Batch(object):
|
class Batch(object):
|
||||||
'''
|
'''
|
||||||
@ -245,8 +247,12 @@ class Batch(object):
|
|||||||
if bwait:
|
if bwait:
|
||||||
wait.append(datetime.now() + timedelta(seconds=bwait))
|
wait.append(datetime.now() + timedelta(seconds=bwait))
|
||||||
# Munge retcode into return data
|
# Munge retcode into return data
|
||||||
|
failhard = False
|
||||||
if 'retcode' in data and isinstance(data['ret'], dict) and 'retcode' not in data['ret']:
|
if 'retcode' in data and isinstance(data['ret'], dict) and 'retcode' not in data['ret']:
|
||||||
data['ret']['retcode'] = data['retcode']
|
data['ret']['retcode'] = data['retcode']
|
||||||
|
if self.opts.get('failhard') and data['ret']['retcode'] > 0:
|
||||||
|
failhard = True
|
||||||
|
|
||||||
if self.opts.get('raw'):
|
if self.opts.get('raw'):
|
||||||
ret[minion] = data
|
ret[minion] = data
|
||||||
yield data
|
yield data
|
||||||
@ -264,6 +270,9 @@ class Batch(object):
|
|||||||
data,
|
data,
|
||||||
out,
|
out,
|
||||||
self.opts)
|
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
|
# remove inactive iterators from the iters list
|
||||||
for queue in minion_tracker:
|
for queue in minion_tracker:
|
||||||
|
@ -262,14 +262,6 @@ class SaltCMD(parsers.SaltCMDOptionParser):
|
|||||||
if job_retcode > retcode:
|
if job_retcode > retcode:
|
||||||
# Exit with the highest retcode we find
|
# Exit with the highest retcode we find
|
||||||
retcode = job_retcode
|
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)
|
sys.exit(retcode)
|
||||||
|
|
||||||
def _print_errors_summary(self, errors):
|
def _print_errors_summary(self, errors):
|
||||||
|
@ -560,6 +560,7 @@ class LocalClient(object):
|
|||||||
'tgt_type': tgt_type,
|
'tgt_type': tgt_type,
|
||||||
'ret': ret,
|
'ret': ret,
|
||||||
'batch': batch,
|
'batch': batch,
|
||||||
|
'failhard': kwargs.get('failhard', False),
|
||||||
'raw': kwargs.get('raw', False)}
|
'raw': kwargs.get('raw', False)}
|
||||||
|
|
||||||
if 'timeout' in kwargs:
|
if 'timeout' in kwargs:
|
||||||
|
Loading…
Reference in New Issue
Block a user