Make it possible to use prereq with test and saltmod state mods

this requisite passes a __prerequired__ kwarg so these need to support
**kwargs for that reason.

This also changes the comment for salt.function in test mode because
it's inaccurate and doesn't make sense.

Conflicts:
  - salt/states/test.py
This commit is contained in:
Erik Johnson 2018-09-28 21:27:43 -05:00 committed by Ch3LL
parent ceb3f4d91f
commit ed214c4cdb
No known key found for this signature in database
GPG key ID: 132B55A7C13EFA73
3 changed files with 17 additions and 19 deletions

View file

@ -427,7 +427,8 @@ def function(
kwarg=None,
timeout=None,
batch=None,
subset=None):
subset=None,
**kwargs): # pylint: disable=unused-argument
'''
Execute a single module function on a remote minion via salt or salt-ssh
@ -478,15 +479,15 @@ def function(
'''
func_ret = {'name': name,
'changes': {},
'comment': '',
'result': True}
'changes': {},
'comment': '',
'result': True}
if kwarg is None:
kwarg = {}
if isinstance(arg, six.string_types):
func_ret['warnings'] = ['Please specify \'arg\' as a list, not a string. '
'Modifying in place, but please update SLS file '
'to remove this warning.']
func_ret['warnings'] = [
'Please specify \'arg\' as a list of arguments.'
]
arg = arg.split()
cmd_kw = {'arg': arg or [], 'kwarg': kwarg, 'ret': ret, 'timeout': timeout}
@ -509,9 +510,8 @@ def function(
fun = name
if __opts__['test'] is True:
func_ret['comment'] = (
'Function {0} will be executed on target {1} as test={2}'
).format(fun, tgt, six.text_type(False))
func_ret['comment'] = \
'Function {0} would be executed on target {1}'.format(fun, tgt)
func_ret['result'] = None
return func_ret
try:
@ -751,7 +751,7 @@ def runner(name, **kwargs):
return ret
def parallel_runners(name, runners):
def parallel_runners(name, runners, **kwargs): # pylint: disable=unused-argument
'''
Executes multiple runner modules on the master in parallel.

View file

@ -67,7 +67,7 @@ def nop(name, **kwargs):
return succeed_without_changes(name)
def succeed_without_changes(name, **kwargs):
def succeed_without_changes(name, **kwargs): # pylint: disable=unused-argument
'''
Returns successful.
@ -85,7 +85,7 @@ def succeed_without_changes(name, **kwargs):
return ret
def fail_without_changes(name, **kwargs):
def fail_without_changes(name, **kwargs): # pylint: disable=unused-argument
'''
Returns failure.
@ -108,7 +108,7 @@ def fail_without_changes(name, **kwargs):
return ret
def succeed_with_changes(name, **kwargs):
def succeed_with_changes(name, **kwargs): # pylint: disable=unused-argument
'''
Returns successful and changes is not empty
@ -141,7 +141,7 @@ def succeed_with_changes(name, **kwargs):
return ret
def fail_with_changes(name, **kwargs):
def fail_with_changes(name, **kwargs): # pylint: disable=unused-argument
'''
Returns failure and changes is not empty.

View file

@ -175,13 +175,11 @@ class SaltmodTestCase(TestCase, LoaderModuleMockMixin):
name = 'state'
tgt = 'larry'
comt = ('Function state will be executed'
' on target {0} as test=False'.format(tgt))
ret = {'name': name,
'changes': {},
'result': None,
'comment': comt}
'comment': 'Function state would be executed '
'on target {0}'.format(tgt)}
with patch.dict(saltmod.__opts__, {'test': True}):
self.assertDictEqual(saltmod.function(name, tgt), ret)