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.config
|
||||||
import salt.runner
|
import salt.runner
|
||||||
import salt.utils
|
import salt.utils
|
||||||
|
import salt.utils.args
|
||||||
import salt.utils.process
|
import salt.utils.process
|
||||||
import salt.utils.minion
|
import salt.utils.minion
|
||||||
import salt.utils.event
|
import salt.utils.event
|
||||||
@ -1059,13 +1060,13 @@ def cmd_iter(tgt,
|
|||||||
yield ret
|
yield ret
|
||||||
|
|
||||||
|
|
||||||
def runner(_fun, **kwargs):
|
def runner(name, **kwargs):
|
||||||
'''
|
'''
|
||||||
Execute a runner module (this function must be run on the master)
|
Execute a runner module (this function must be run on the master)
|
||||||
|
|
||||||
.. versionadded:: 2014.7.0
|
.. versionadded:: 2014.7.0
|
||||||
|
|
||||||
_fun
|
name
|
||||||
The name of the function to run
|
The name of the function to run
|
||||||
|
|
||||||
kwargs
|
kwargs
|
||||||
@ -1077,6 +1078,7 @@ def runner(_fun, **kwargs):
|
|||||||
|
|
||||||
salt '*' saltutil.runner jobs.list_jobs
|
salt '*' saltutil.runner jobs.list_jobs
|
||||||
'''
|
'''
|
||||||
|
saltenv = kwargs.pop('__env__', 'base')
|
||||||
kwargs = salt.utils.clean_kwargs(**kwargs)
|
kwargs = salt.utils.clean_kwargs(**kwargs)
|
||||||
|
|
||||||
if 'master_job_cache' not in __opts__:
|
if 'master_job_cache' not in __opts__:
|
||||||
@ -1087,10 +1089,15 @@ def runner(_fun, **kwargs):
|
|||||||
else:
|
else:
|
||||||
rclient = salt.runner.RunnerClient(__opts__)
|
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)
|
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
|
salt '*' saltutil.wheel key.accept jerry
|
||||||
'''
|
'''
|
||||||
|
saltenv = kwargs.pop('__env__', 'base')
|
||||||
|
|
||||||
if __opts__['__role'] == 'minion':
|
if __opts__['__role'] == 'minion':
|
||||||
master_config = os.path.join(os.path.dirname(__opts__['conf_file']),
|
master_config = os.path.join(os.path.dirname(__opts__['conf_file']),
|
||||||
'master')
|
'master')
|
||||||
@ -1133,10 +1142,22 @@ def wheel(_fun, *args, **kwargs):
|
|||||||
valid_kwargs[key] = val
|
valid_kwargs[key] = val
|
||||||
|
|
||||||
try:
|
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:
|
except SaltInvocationError:
|
||||||
raise CommandExecutionError('This command can only be executed on a minion '
|
raise CommandExecutionError(
|
||||||
'that is located on the master.')
|
'This command can only be executed on a minion that is located on '
|
||||||
|
'the master.'
|
||||||
|
)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -577,7 +577,9 @@ def runner(name, **kwargs):
|
|||||||
- name: manage.up
|
- name: manage.up
|
||||||
'''
|
'''
|
||||||
ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}
|
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['result'] = True
|
||||||
ret['comment'] = "Runner function '{0}' executed.".format(name)
|
ret['comment'] = "Runner function '{0}' executed.".format(name)
|
||||||
@ -607,7 +609,9 @@ def wheel(name, **kwargs):
|
|||||||
- match: frank
|
- match: frank
|
||||||
'''
|
'''
|
||||||
ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}
|
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['result'] = True
|
||||||
ret['comment'] = "Wheel function '{0}' executed.".format(name)
|
ret['comment'] = "Wheel function '{0}' executed.".format(name)
|
||||||
|
@ -966,7 +966,7 @@ def format_call(fun,
|
|||||||
|
|
||||||
aspec = salt.utils.args.get_function_argspec(fun)
|
aspec = salt.utils.args.get_function_argspec(fun)
|
||||||
|
|
||||||
arg_data = arg_lookup(fun)
|
arg_data = arg_lookup(fun, aspec)
|
||||||
args = arg_data['args']
|
args = arg_data['args']
|
||||||
kwargs = arg_data['kwargs']
|
kwargs = arg_data['kwargs']
|
||||||
|
|
||||||
@ -1074,13 +1074,14 @@ def format_call(fun,
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def arg_lookup(fun):
|
def arg_lookup(fun, aspec=None):
|
||||||
'''
|
'''
|
||||||
Return a dict containing the arguments and default arguments to the
|
Return a dict containing the arguments and default arguments to the
|
||||||
function.
|
function.
|
||||||
'''
|
'''
|
||||||
ret = {'kwargs': {}}
|
ret = {'kwargs': {}}
|
||||||
aspec = salt.utils.args.get_function_argspec(fun)
|
if aspec is None:
|
||||||
|
aspec = salt.utils.args.get_function_argspec(fun)
|
||||||
if aspec.defaults:
|
if aspec.defaults:
|
||||||
ret['kwargs'] = dict(zip(aspec.args[::-1], aspec.defaults[::-1]))
|
ret['kwargs'] = dict(zip(aspec.args[::-1], aspec.defaults[::-1]))
|
||||||
ret['args'] = [arg for arg in aspec.args if arg not in ret['kwargs']]
|
ret['args'] = [arg for arg in aspec.args if arg not in ret['kwargs']]
|
||||||
|
Loading…
Reference in New Issue
Block a user