mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #35050 from terminalmage/fix-saltdev-arg
[orchestration] Properly handle runner/wheel funcs which accept a 'saltdev' argument
This commit is contained in:
commit
848bf0272f
@ -45,6 +45,7 @@ import salt.client.ssh.client
|
||||
import salt.config
|
||||
import salt.runner
|
||||
import salt.utils
|
||||
import salt.utils.args
|
||||
import salt.utils.process
|
||||
import salt.utils.minion
|
||||
import salt.utils.event
|
||||
@ -1059,13 +1060,13 @@ def cmd_iter(tgt,
|
||||
yield ret
|
||||
|
||||
|
||||
def runner(_fun, **kwargs):
|
||||
def runner(name, **kwargs):
|
||||
'''
|
||||
Execute a runner module (this function must be run on the master)
|
||||
|
||||
.. versionadded:: 2014.7.0
|
||||
|
||||
_fun
|
||||
name
|
||||
The name of the function to run
|
||||
|
||||
kwargs
|
||||
@ -1077,6 +1078,7 @@ def runner(_fun, **kwargs):
|
||||
|
||||
salt '*' saltutil.runner jobs.list_jobs
|
||||
'''
|
||||
saltenv = kwargs.pop('__env__', 'base')
|
||||
kwargs = salt.utils.clean_kwargs(**kwargs)
|
||||
|
||||
if 'master_job_cache' not in __opts__:
|
||||
@ -1087,10 +1089,15 @@ def runner(_fun, **kwargs):
|
||||
else:
|
||||
rclient = salt.runner.RunnerClient(__opts__)
|
||||
|
||||
return rclient.cmd(_fun, kwarg=kwargs)
|
||||
if name in rclient.functions:
|
||||
aspec = salt.utils.args.get_function_argspec(rclient.functions[name])
|
||||
if 'saltenv' in aspec.args:
|
||||
kwargs['saltenv'] = saltenv
|
||||
|
||||
return rclient.cmd(name, kwarg=kwargs)
|
||||
|
||||
|
||||
def wheel(_fun, *args, **kwargs):
|
||||
def wheel(name, *args, **kwargs):
|
||||
'''
|
||||
Execute a wheel module (this function must be run on the master)
|
||||
|
||||
@ -1114,6 +1121,8 @@ def wheel(_fun, *args, **kwargs):
|
||||
|
||||
salt '*' saltutil.wheel key.accept jerry
|
||||
'''
|
||||
saltenv = kwargs.pop('__env__', 'base')
|
||||
|
||||
if __opts__['__role'] == 'minion':
|
||||
master_config = os.path.join(os.path.dirname(__opts__['conf_file']),
|
||||
'master')
|
||||
@ -1133,10 +1142,22 @@ def wheel(_fun, *args, **kwargs):
|
||||
valid_kwargs[key] = val
|
||||
|
||||
try:
|
||||
ret = wheel_client.cmd(_fun, arg=args, pub_data=pub_data, kwarg=valid_kwargs)
|
||||
if name in wheel_client.functions:
|
||||
aspec = salt.utils.args.get_function_argspec(
|
||||
wheel_client.functions[name]
|
||||
)
|
||||
if 'saltenv' in aspec.args:
|
||||
valid_kwargs['saltenv'] = saltenv
|
||||
|
||||
ret = wheel_client.cmd(name,
|
||||
arg=args,
|
||||
pub_data=pub_data,
|
||||
kwarg=valid_kwargs)
|
||||
except SaltInvocationError:
|
||||
raise CommandExecutionError('This command can only be executed on a minion '
|
||||
'that is located on the master.')
|
||||
raise CommandExecutionError(
|
||||
'This command can only be executed on a minion that is located on '
|
||||
'the master.'
|
||||
)
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -577,7 +577,9 @@ def runner(name, **kwargs):
|
||||
- name: manage.up
|
||||
'''
|
||||
ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}
|
||||
out = __salt__['saltutil.runner'](name, **kwargs)
|
||||
out = __salt__['saltutil.runner'](name,
|
||||
__env__=__env__,
|
||||
**kwargs)
|
||||
|
||||
ret['result'] = True
|
||||
ret['comment'] = "Runner function '{0}' executed.".format(name)
|
||||
@ -607,7 +609,9 @@ def wheel(name, **kwargs):
|
||||
- match: frank
|
||||
'''
|
||||
ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}
|
||||
out = __salt__['saltutil.wheel'](name, **kwargs)
|
||||
out = __salt__['saltutil.wheel'](name,
|
||||
__env__=__env__,
|
||||
**kwargs)
|
||||
|
||||
ret['result'] = True
|
||||
ret['comment'] = "Wheel function '{0}' executed.".format(name)
|
||||
|
@ -966,7 +966,7 @@ def format_call(fun,
|
||||
|
||||
aspec = salt.utils.args.get_function_argspec(fun)
|
||||
|
||||
arg_data = arg_lookup(fun)
|
||||
arg_data = arg_lookup(fun, aspec)
|
||||
args = arg_data['args']
|
||||
kwargs = arg_data['kwargs']
|
||||
|
||||
@ -1074,12 +1074,13 @@ def format_call(fun,
|
||||
return ret
|
||||
|
||||
|
||||
def arg_lookup(fun):
|
||||
def arg_lookup(fun, aspec=None):
|
||||
'''
|
||||
Return a dict containing the arguments and default arguments to the
|
||||
function.
|
||||
'''
|
||||
ret = {'kwargs': {}}
|
||||
if aspec is None:
|
||||
aspec = salt.utils.args.get_function_argspec(fun)
|
||||
if aspec.defaults:
|
||||
ret['kwargs'] = dict(zip(aspec.args[::-1], aspec.defaults[::-1]))
|
||||
|
Loading…
Reference in New Issue
Block a user