Proper handling of watch with onlyif/unless

This fixes #16647
This commit is contained in:
Mathieu Le Marec - Pasquet 2014-10-15 17:50:46 +02:00 committed by rallytime
parent 623a11d067
commit b837be080c
4 changed files with 16 additions and 3 deletions

View File

@ -635,7 +635,9 @@ class State(object):
cmd = self.functions['cmd.retcode'](entry, ignore_retcode=True, **cmd_opts)
log.debug('Last command return code: {0}'.format(cmd))
if cmd != 0 and ret['result'] is False:
ret.update({'comment': 'onlyif execution failed', 'result': True})
ret.update({'comment': 'onlyif execution failed',
'skip_watch': True,
'result': True})
return ret
elif cmd == 0:
ret.update({'comment': 'onlyif execution succeeded', 'result': False})
@ -650,7 +652,9 @@ class State(object):
cmd = self.functions['cmd.retcode'](entry, ignore_retcode=True, **cmd_opts)
log.debug('Last command return code: {0}'.format(cmd))
if cmd == 0 and ret['result'] is False:
ret.update({'comment': 'unless execution succeeded', 'result': True})
ret.update({'comment': 'unless execution succeeded',
'skip_watch': True,
'result': True})
elif cmd != 0:
ret.update({'comment': 'unless execution failed', 'result': False})
return ret
@ -1854,7 +1858,7 @@ class State(object):
self.__run_num += 1
elif status == 'change' and not low.get('__prereq__'):
ret = self.call(low, chunks, running)
if not ret['changes']:
if not ret['changes'] and not ret.get('skip_watch', False):
low = low.copy()
low['sfun'] = low['fun']
low['fun'] = 'mod_watch'

View File

@ -301,6 +301,7 @@ def mod_run_check(cmd_kwargs, onlyif, unless, group, creates):
log.debug('Last command return code: {0}'.format(cmd))
if cmd != 0:
return {'comment': 'onlyif execution failed',
'skip_watch': True,
'result': True}
elif isinstance(onlyif, list):
for entry in onlyif:
@ -308,11 +309,13 @@ def mod_run_check(cmd_kwargs, onlyif, unless, group, creates):
log.debug('Last command return code: {0}'.format(cmd))
if cmd != 0:
return {'comment': 'onlyif execution failed',
'skip_watch': True,
'result': True}
elif not isinstance(onlyif, string_types):
if not onlyif:
log.debug('Command not run: onlyif did not evaluate to string_type')
return {'comment': 'onlyif execution failed',
'skip_watch': True,
'result': True}
if unless is not None:
@ -321,6 +324,7 @@ def mod_run_check(cmd_kwargs, onlyif, unless, group, creates):
log.debug('Last command return code: {0}'.format(cmd))
if cmd == 0:
return {'comment': 'unless execution succeeded',
'skip_watch': True,
'result': True}
elif isinstance(unless, list):
for entry in unless:
@ -328,11 +332,13 @@ def mod_run_check(cmd_kwargs, onlyif, unless, group, creates):
log.debug('Last command return code: {0}'.format(cmd))
if cmd == 0:
return {'comment': 'unless execution succeeded',
'skip_watch': True,
'result': True}
elif not isinstance(unless, string_types):
if unless:
log.debug('Command not run: unless did not evaluate to string_type')
return {'comment': 'unless execution succeeded',
'skip_watch': True,
'result': True}
if isinstance(creates, string_types) and os.path.exists(creates):

View File

@ -4021,6 +4021,7 @@ def mod_run_check_cmd(cmd, filename):
_cmd = '{0} {1}'.format(cmd, filename)
if __salt__['cmd.retcode'](_cmd) != 0:
return {'comment': 'check_cmd execution failed',
'skip_watch': True,
'result': True}
# No reason to stop, return True

View File

@ -582,11 +582,13 @@ def mod_run_check(cmd_kwargs, onlyif, unless):
if onlyif:
if __salt__['cmd.retcode'](onlyif, **cmd_kwargs) != 0:
return {'comment': 'onlyif execution failed',
'skip_watch': True,
'result': True}
if unless:
if __salt__['cmd.retcode'](unless, **cmd_kwargs) == 0:
return {'comment': 'unless execution succeeded',
'skip_watch': True,
'result': True}
# No reason to stop, return True