File 0009-The-functions-in-the-state-module-that-return-a-retc.patch of Package salt.3314
From 8d77e22c0c570a0a725216f70c41d4fe00a184ca Mon Sep 17 00:00:00 2001
From: "Gareth J. Greenaway" <gareth@wiked.org>
Date: Sat, 6 Feb 2016 15:52:17 -0800
Subject: [PATCH 09/22] 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
---
salt/modules/state.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/salt/modules/state.py b/salt/modules/state.py
index 9cb195b..27e588c 100644
--- a/salt/modules/state.py
+++ b/salt/modules/state.py
@@ -70,6 +70,10 @@ def _set_retcode(ret):
'''
Set the return code based on the data back from the state system
'''
+
+ # Set default retcode to 0
+ __context__['retcode'] = 0
+
if isinstance(ret, list):
__context__['retcode'] = 1
return
@@ -576,7 +580,6 @@ def highstate(test=None,
serial = salt.payload.Serial(__opts__)
cache_file = os.path.join(__opts__['cachedir'], 'highstate.p')
-
_set_retcode(ret)
# Work around Windows multiprocessing bug, set __opts__['test'] back to
# value from before this function was run.
@@ -770,7 +773,6 @@ def sls(mods,
except (IOError, OSError):
msg = 'Unable to write to SLS cache file {0}. Check permission.'
log.error(msg.format(cache_file))
-
_set_retcode(ret)
# Work around Windows multiprocessing bug, set __opts__['test'] back to
# value from before this function was run.
@@ -876,8 +878,7 @@ def show_highstate(queue=False, **kwargs):
ret = st_.compile_highstate()
finally:
st_.pop_active()
- if isinstance(ret, list):
- __context__['retcode'] = 1
+ _set_retcode(ret)
return ret
--
2.1.4