Skip to content

Commit

Permalink
Merge pull request #25587 from cachedout/issue_16969
Browse files Browse the repository at this point in the history
Fix prereq in salt.state
  • Loading branch information
Mike Place committed Jul 22, 2015
2 parents 9004ce2 + 6f65fbd commit 41b7604
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
16 changes: 6 additions & 10 deletions salt/states/saltmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ def state(
ret['result'] = False
return ret

if test:
cmd_kw['kwarg']['test'] = test
if test or __opts__.get('test'):
cmd_kw['kwarg']['test'] = True

if pillar:
cmd_kw['kwarg']['pillar'] = pillar
Expand All @@ -213,14 +213,6 @@ def state(
ret['result'] = False
return ret

if __opts__['test'] is True:
ret['comment'] = (
'{0} will be run on target {1} as test={2}'
).format(fun == 'state.highstate' and 'Highstate'
or 'States '+','.join(cmd_kw['arg']),
tgt, str(test))
ret['result'] = None
return ret
cmd_ret = __salt__['saltutil.cmd'](tgt, fun, **cmd_kw)

changes = {}
Expand Down Expand Up @@ -289,6 +281,10 @@ def state(
).splitlines()
)
ret['comment'] += '\n'
if test or __opts__.get('test'):
if ret['changes'] and ret['result'] is True:
# Test mode with changes is the only case where result should ever be none
ret['result'] = None
return ret


Expand Down
11 changes: 8 additions & 3 deletions tests/unit/states/saltmod_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from salt.states import saltmod

saltmod.__opts__ = {}
saltmod.__salt__ = {}
saltmod.__salt__ = {'saltutil.cmd': MagicMock()}
saltmod.__env__ = {}


Expand All @@ -49,6 +49,12 @@ def test_state(self):
'result': False,
'comment': comt}

test_ret = {'name': name,
'changes': {},
'result': True,
'comment': 'States ran successfully.'
}

self.assertDictEqual(saltmod.state(name, tgt, allow_fail='a'), ret)

comt = ('No highstate or sls specified, no execution made')
Expand All @@ -60,10 +66,9 @@ def test_state(self):
self.assertDictEqual(saltmod.state(name, tgt, highstate=True,
concurrent='a'), ret)

comt = ('Highstate will be run on target minion1 as test=False')
ret.update({'comment': comt, 'result': None})
with patch.dict(saltmod.__opts__, {'test': True}):
self.assertDictEqual(saltmod.state(name, tgt, highstate=True), ret)
self.assertDictEqual(saltmod.state(name, tgt, highstate=True), test_ret)

ret.update({'comment': 'States ran successfully.', 'result': True})
with patch.dict(saltmod.__opts__, {'test': False}):
Expand Down

0 comments on commit 41b7604

Please sign in to comment.