Correct the thorium runner

The thorium system is currently unable to invoke any runner (at all).
This is due to the fact that we go thorough the State system
which builds the "chunks" from the state-formatted data:
https://github.com/saltstack/salt/blob/develop/salt/thorium/__init__.py#L166

For example, the following Thorium state:

dummy:
  runner.cmd
    - fun: test.sleep
    - kwargs:
       s_time: 1

Will produce the following state chunks:

[{'name': 'dummy', 'state': 'runner', '__id__': 'dummy', 'kwargs': OrderedDict([('s_time', 1)]), 'fun': 'cmd', '__env__': 'base', '__sls__': u'dummy', 'order': 10000}]

The value of the `fun` field from the state chunks will override
the value specified in the Thorisum state. For the example above,
instead of execution the `test.sleep` runner function, it will
try instead to execute the `cmd` runner function, which will,
of course, fail.
In order to preserve the value of the actual function requested by
the user, we must rename `fun` to `func` to avoid this collision,
which is also in-line with the equivalent `local.cmd` for local
functions: https://github.com/saltstack/salt/blob/develop/salt/thorium/local.py#L14
The state chunks in this case will be:

[{'name': 'dummy', 'state': 'runner', '__id__': 'dummy', 'func': 'test.sleep', 'kwargs': OrderedDict([('s_time', 1)]), 'fun': 'cmd', '__env__': 'base', '__sls__': u'dummy', 'order': 10000}]

Which will correctly try to execute the requested runner function.
This commit is contained in:
Mircea Ulinic 2017-12-01 13:50:56 +00:00 committed by Mircea Ulinic
parent 20391c54c0
commit b72b7c5402
No known key found for this signature in database
GPG key ID: 4286FAD4BACBB073

View file

@ -10,7 +10,7 @@ import salt.runner
def cmd(
name,
fun=None,
func=None,
arg=(),
**kwargs):
'''
@ -22,14 +22,14 @@ def cmd(
run_cloud:
runner.cmd:
- fun: cloud.create
- func: cloud.create
- arg:
- my-ec2-config
- myinstance
run_cloud:
runner.cmd:
- fun: cloud.create
- func: cloud.create
- kwargs:
provider: my-ec2-config
instances: myinstance
@ -38,11 +38,11 @@ def cmd(
'changes': {},
'comment': '',
'result': True}
if fun is None:
fun = name
if func is None:
func = name
client = salt.runner.RunnerClient(__opts__)
low = {'fun': fun,
'arg': arg,
'kwargs': kwargs}
low = {'fun': func,
'arg': arg,
'kwarg': kwargs}
client.cmd_async(low)
return ret