Skip to content

Commit

Permalink
allow lists for _run_check
Browse files Browse the repository at this point in the history
added all() for onlyif, unless, and creates
  • Loading branch information
gtmanfred committed Mar 17, 2014
1 parent 4107b62 commit bafd099
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions salt/states/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,28 +279,53 @@ def _run_check(cmd_kwargs, onlyif, unless, group, creates):
'result': False}

if onlyif is not None:
if not isinstance(onlyif, string_types):
if not onlyif:
if isinstance(onlyif, string_types):
if __salt__['cmd.retcode'](onlyif, **cmd_kwargs) != 0:
return {'comment': 'onlyif execution failed',
'result': True}
elif isinstance(onlyif, string_types):
if __salt__['cmd.retcode'](onlyif, **cmd_kwargs) != 0:
elif isinstance(onlyif, list):
if all([
__salt__['cmd.retcode'](
entry,
**cmd_kwargs
) != 0 for entry in onlyif
]):

return {'comment': 'onlyif execution failed',
'result': True}
elif not isinstance(onlyif, string_types):
if not onlyif:
return {'comment': 'onlyif execution failed',
'result': True}

if unless is not None:
if not isinstance(unless, string_types):
if unless:
if isinstance(unless, string_types):
if __salt__['cmd.retcode'](unless, **cmd_kwargs) == 0:
return {'comment': 'unless execution succeeded',
'result': True}
elif isinstance(unless, string_types):
if __salt__['cmd.retcode'](unless, **cmd_kwargs) == 0:
elif isinstance(unless, list):
if all([
__salt__['cmd.retcode'](
entry,
**cmd_kwargs
) == 0 for entry in unless
]):

return {'comment': 'unless execution succeeded',
'result': True}
elif not isinstance(unless, string_types):
if unless:
return {'comment': 'unless execution succeeded',
'result': True}

if isinstance(creates, string_types) and os.path.exists(creates):
return {'comment': '{0} exists'.format(creates),
'result': True}
elif isinstance(creates, list) and all([
os.path.exists(path) for path in creates
]):
return {'comment': 'All files in creates exist'.format(creates),
'result': True}

# No reason to stop, return True
return True
Expand Down

0 comments on commit bafd099

Please sign in to comment.