The functions in the state module that return a retcode when something goes wrong, eg. a 1 or a 2, do not return a 0 when things go the way they're supposed to go. With the recent changes to the scheduler to ensure that the retcode is returned this is problematic and results in exceptions when a state function is run from the schedule. This simple fix ensures a default retcode of 0 exists, it is then override in the _set_retcode function if there is an issue with the run

This commit is contained in:
Gareth J. Greenaway 2016-02-06 15:52:17 -08:00
parent ef02779391
commit 5f2f0f60c0

View file

@ -233,6 +233,11 @@ def high(data, test=False, queue=False, **kwargs):
st_ = salt.state.State(__opts__, pillar)
ret = st_.call_high(data)
# Set default retcode to 0
# then override in _set_retcode
__context__['retcode'] = 0
_set_retcode(ret)
return ret
@ -273,6 +278,11 @@ def template(tem, queue=False, **kwargs):
__context__['retcode'] = 1
return errors
ret = st_.state.call_high(high_state)
# Set default retcode to 0
# then override in _set_retcode
__context__['retcode'] = 0
_set_retcode(ret)
return ret
@ -295,6 +305,11 @@ def template_str(tem, queue=False, **kwargs):
except NameError:
st_ = salt.state.State(__opts__)
ret = st_.call_template_str(tem)
# Set default retcode to 0
# then override in _set_retcode
__context__['retcode'] = 0
_set_retcode(ret)
return ret
@ -577,6 +592,10 @@ def highstate(test=None,
serial = salt.payload.Serial(__opts__)
cache_file = os.path.join(__opts__['cachedir'], 'highstate.p')
# Set default retcode to 0
# then override in _set_retcode
__context__['retcode'] = 0
_set_retcode(ret)
# Work around Windows multiprocessing bug, set __opts__['test'] back to
# value from before this function was run.
@ -771,6 +790,10 @@ def sls(mods,
msg = 'Unable to write to SLS cache file {0}. Check permission.'
log.error(msg.format(cache_file))
# Set default retcode to 0
# then override in _set_retcode
__context__['retcode'] = 0
_set_retcode(ret)
# Work around Windows multiprocessing bug, set __opts__['test'] back to
# value from before this function was run.
@ -842,6 +865,11 @@ def top(topfn,
)
finally:
st_.pop_active()
# Set default retcode to 0
# then override in _set_retcode
__context__['retcode'] = 0
_set_retcode(ret)
# Work around Windows multiprocessing bug, set __opts__['test'] back to
# value from before this function was run.
@ -1166,6 +1194,11 @@ def single(fun, name, test=None, queue=False, **kwargs):
st_._mod_init(kwargs)
ret = {'{0[state]}_|-{0[__id__]}_|-{0[name]}_|-{0[fun]}'.format(kwargs):
st_.call(kwargs)}
# Set default retcode to 0
# then override in _set_retcode
__context__['retcode'] = 0
_set_retcode(ret)
# Work around Windows multiprocessing bug, set __opts__['test'] back to
# value from before this function was run.