Skip to content

Commit

Permalink
[BACKPORT] Fix empty fun_agrs field in Reactor generated events
Browse files Browse the repository at this point in the history
  • Loading branch information
vutny committed Aug 23, 2016
1 parent 9fe0972 commit 78d16a8
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions salt/client/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ def low(self, fun, low, print_event=True):
jid = low.get('__jid__', salt.utils.jid.gen_jid())
tag = low.get('__tag__', tagify(jid, prefix=self.tag_prefix))

# This avoids including kwargs dict as args list in low data.
# We only need to update event data.
fun_args = low.get('args', [])
data = {'fun': '{0}.{1}'.format(self.client, fun),
'fun_args': fun_args + ([low['kwargs']] if low.get('kwargs', False) else []),
'jid': jid,
'user': low.get('__user__', 'UNKNOWN'),
}
Expand All @@ -280,11 +276,13 @@ def low(self, fun, low, print_event=True):
# Suppress printing of return event (this keeps us from printing
# runner/wheel output during orchestration).
print_func = None

namespaced_event = salt.utils.event.NamespacedEvent(
event,
tag,
print_func=print_func
)

# TODO: document these, and test that they exist
# TODO: Other things to inject??
func_globals = {'__jid__': jid,
Expand All @@ -295,8 +293,6 @@ def low(self, fun, low, print_event=True):
'__jid_event__': weakref.proxy(namespaced_event),
}

func_globals['__jid_event__'].fire_event(data, 'new')

try:
verify_fun(self.functions, fun)

Expand Down Expand Up @@ -332,6 +328,7 @@ def low(self, fun, low, print_event=True):
args = f_call.get('args', ())
else:
args = low['args']

if 'kwargs' not in low:
if f_call is None:
f_call = salt.utils.format_call(
Expand All @@ -351,6 +348,10 @@ def low(self, fun, low, print_event=True):
else:
kwargs = low['kwargs']

# Update the event data with loaded args and kwargs
data['fun_args'] = args + ([kwargs] if kwargs else [])
func_globals['__jid_event__'].fire_event(data, 'new')

# Initialize a context for executing the method.
with tornado.stack_context.StackContext(self.functions.context_dict.clone):
data['return'] = self.functions[fun](*args, **kwargs)
Expand All @@ -360,26 +361,30 @@ def low(self, fun, low, print_event=True):
data['return'] = str(ex)
else:
data['return'] = 'Exception occurred in {0} {1}: {2}'.format(
self.client,
fun,
traceback.format_exc(),
)
self.client,
fun,
traceback.format_exc(),
)
data['success'] = False

namespaced_event.fire_event(data, 'ret')

try:
salt.utils.job.store_job(
self.opts,
{'id': self.opts['id'],
'tgt': self.opts['id'],
'jid': data['jid'],
'return': data,
},
{
'id': self.opts['id'],
'tgt': self.opts['id'],
'jid': data['jid'],
'return': data,
},
event=None,
mminion=self.mminion,
)
except salt.exceptions.SaltCacheError:
log.error('Could not store job cache info. Job details for this run may be unavailable.')
log.error('Could not store job cache info. '
'Job details for this run may be unavailable.')

# if we fired an event, make sure to delete the event object.
# This will ensure that we call destroy, which will do the 0MQ linger
log.info('Runner completed: {0}'.format(data['jid']))
Expand Down

0 comments on commit 78d16a8

Please sign in to comment.