Skip to content

Commit

Permalink
Fix variable shadowing
Browse files Browse the repository at this point in the history
ret was used to pass in returners, but then immediately overwritten as the return for the method. This ended up causing problems because the return dict was being passed downstream as the returners string
  • Loading branch information
jacksontj committed Dec 3, 2015
1 parent 7bb83cc commit d968d69
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions salt/states/saltmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,22 +345,22 @@ def function(
ssh
Set to `True` to use the ssh client instead of the standard salt client
'''
ret = {'name': name,
func_ret = {'name': name,
'changes': {},
'comment': '',
'result': True}
if kwarg is None:
kwarg = {}
if isinstance(arg, str):
ret['warnings'] = ['Please specify \'arg\' as a list, not a string. '
func_ret['warnings'] = ['Please specify \'arg\' as a list, not a string. '
'Modifying in place, but please update SLS file '
'to remove this warning.']
arg = arg.split()

cmd_kw = {'arg': arg or [], 'kwarg': kwarg, 'ret': ret, 'timeout': timeout}

if expr_form and tgt_type:
ret['warnings'] = [
func_ret['warnings'] = [
'Please only use \'tgt_type\' or \'expr_form\' not both. '
'Preferring \'tgt_type\' over \'expr_form\''
]
Expand All @@ -379,17 +379,17 @@ def function(
cmd_kw['_cmd_meta'] = True
fun = name
if __opts__['test'] is True:
ret['comment'] = (
func_ret['comment'] = (
'Function {0} will be executed on target {1} as test={2}'
).format(fun, tgt, str(False))
ret['result'] = None
return ret
func_ret['result'] = None
return func_ret
try:
cmd_ret = __salt__['saltutil.cmd'](tgt, fun, **cmd_kw)
except Exception as exc:
ret['result'] = False
ret['comment'] = str(exc)
return ret
func_ret['result'] = False
func_ret['comment'] = str(exc)
return func_ret

changes = {}
fail = set()
Expand All @@ -400,15 +400,15 @@ def function(
elif isinstance(fail_minions, string_types):
fail_minions = [minion.strip() for minion in fail_minions.split(',')]
elif not isinstance(fail_minions, list):
ret.setdefault('warnings', []).append(
func_ret.setdefault('warnings', []).append(
'\'fail_minions\' needs to be a list or a comma separated '
'string. Ignored.'
)
fail_minions = ()
for minion, mdata in six.iteritems(cmd_ret):
m_ret = False
if mdata.get('retcode'):
ret['result'] = False
func_ret['result'] = False
fail.add(minion)
if mdata.get('failed', False):
m_func = False
Expand All @@ -425,31 +425,31 @@ def function(
continue
changes[minion] = m_ret
if not cmd_ret:
ret['result'] = False
ret['command'] = 'No minions responded'
func_ret['result'] = False
func_ret['command'] = 'No minions responded'
else:
if changes:
ret['changes'] = {'out': 'highstate', 'ret': changes}
func_ret['changes'] = {'out': 'highstate', 'ret': changes}
if fail:
ret['result'] = False
ret['comment'] = 'Running function {0} failed on minions: {1}'.format(name, ', '.join(fail))
func_ret['result'] = False
func_ret['comment'] = 'Running function {0} failed on minions: {1}'.format(name, ', '.join(fail))
else:
ret['comment'] = 'Function ran successfully.'
func_ret['comment'] = 'Function ran successfully.'
if changes:
ret['comment'] += ' Function {0} ran on {1}.'.format(name, ', '.join(changes))
func_ret['comment'] += ' Function {0} ran on {1}.'.format(name, ', '.join(changes))
if failures:
ret['comment'] += '\nFailures:\n'
func_ret['comment'] += '\nFailures:\n'
for minion, failure in six.iteritems(failures):
ret['comment'] += '\n'.join(
func_ret['comment'] += '\n'.join(
(' ' * 4 + l)
for l in salt.output.out_format(
{minion: failure},
'highstate',
__opts__,
).splitlines()
)
ret['comment'] += '\n'
return ret
func_ret['comment'] += '\n'
return func_ret


def wait_for_event(
Expand Down

0 comments on commit d968d69

Please sign in to comment.