From 7592ef9606e7f07e1217a9c66b73c80e8d9b35af Mon Sep 17 00:00:00 2001 From: Nathan Grennan Date: Mon, 27 Apr 2015 13:16:56 -0700 Subject: [PATCH 1/8] Fixing return code to be "1" instead of 0 when the return code of a run is something other than 0 --- salt/client/ssh/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index a1121b7630..50507fe42e 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -20,6 +20,7 @@ import yaml import uuid import tempfile import binascii +import sys # Import salt libs import salt.client.ssh.shell @@ -526,6 +527,11 @@ class SSH(object): outputter = self.opts.get('output', 'nested') for ret in self.handle_ssh(): host = next(six.iterkeys(ret)) + final_exit = 0 + host_ret = ret[host].get('retcode') + if host_ret != 0: + final_exit = 1 + self.cache_job(jid, host, ret[host], fun) ret = self.key_deploy(host, ret) if not isinstance(ret[host], dict): @@ -554,6 +560,7 @@ class SSH(object): outputter, self.opts) + sys.exit(final_exit) class Single(object): ''' From b2a888edf6459fc080c24827011d7a2ac7be1bfc Mon Sep 17 00:00:00 2001 From: ngrennan-inflection Date: Wed, 29 Apr 2015 16:43:07 -0700 Subject: [PATCH 2/8] Moving final_exit out of the loop --- salt/client/ssh/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index 50507fe42e..f2f8194614 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -525,9 +525,9 @@ class SSH(object): print('') sret = {} outputter = self.opts.get('output', 'nested') + final_exit = 0 for ret in self.handle_ssh(): host = next(six.iterkeys(ret)) - final_exit = 0 host_ret = ret[host].get('retcode') if host_ret != 0: final_exit = 1 From 43a6511353cd2c794138a522bf2fe7aa017af138 Mon Sep 17 00:00:00 2001 From: ngrennan-inflection Date: Wed, 29 Apr 2015 16:44:17 -0700 Subject: [PATCH 3/8] Adding extra line to make pylint happy --- salt/client/ssh/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index f2f8194614..8576d3d47e 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -561,6 +561,7 @@ class SSH(object): self.opts) sys.exit(final_exit) + class Single(object): ''' From 593491fb57880a60a85fc3b36c97792b9a882ceb Mon Sep 17 00:00:00 2001 From: ngrennan-inflection Date: Wed, 29 Apr 2015 16:47:01 -0700 Subject: [PATCH 4/8] Adding zero to avoid error --- salt/client/ssh/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index 8576d3d47e..2fce73c60d 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -528,7 +528,7 @@ class SSH(object): final_exit = 0 for ret in self.handle_ssh(): host = next(six.iterkeys(ret)) - host_ret = ret[host].get('retcode') + host_ret = ret[host].get('retcode', 0) if host_ret != 0: final_exit = 1 From 305d7431b333ba8bc60442934d4dac5eba752b0e Mon Sep 17 00:00:00 2001 From: Nathan Grennan Date: Mon, 4 May 2015 15:21:51 -0700 Subject: [PATCH 5/8] Adding retcode for salt-ssh in some cases --- salt/client/ssh/__init__.py | 5 +++-- salt/client/ssh/wrapper/__init__.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index 50507fe42e..59e85997bc 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -707,7 +707,7 @@ class Single(object): stdout, stderr, retcode = self.shell.exec_cmd(cmd_str) elif self.fun in self.wfuncs or self.mine: - stdout = self.run_wfunc() + stdout, retcode = self.run_wfunc() else: stdout, stderr, retcode = self.cmd_block() @@ -769,7 +769,8 @@ class Single(object): if '_error' in opts_pkg: # Refresh failed ret = json.dumps({'local': opts_pkg}) - return ret + retcode = opts_pkg['retcode'] + return ret, retcode pillar = salt.pillar.Pillar( opts_pkg, diff --git a/salt/client/ssh/wrapper/__init__.py b/salt/client/ssh/wrapper/__init__.py index 5d1edc1ed8..02f5032fda 100644 --- a/salt/client/ssh/wrapper/__init__.py +++ b/salt/client/ssh/wrapper/__init__.py @@ -110,7 +110,7 @@ class FunctionWrapper(object): fsclient=self.fsclient, **self.kwargs ) - stdout, stderr, _ = single.cmd_block() + stdout, stderr, retcode = single.cmd_block() if stderr.count('Permission Denied'): return {'_error': 'Permission Denied', 'stdout': stdout, @@ -123,7 +123,8 @@ class FunctionWrapper(object): except ValueError: ret = {'_error': 'Failed to return clean data', 'stderr': stderr, - 'stdout': stdout} + 'stdout': stdout, + 'retcode': retcode} return ret return caller From 16ac1d87fe7f6d10022c55a7e242824f238113fa Mon Sep 17 00:00:00 2001 From: Nathan Grennan Date: Mon, 4 May 2015 15:28:07 -0700 Subject: [PATCH 6/8] Cleaning up extra spaces --- salt/client/ssh/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index 65d1a166a5..23f86013d6 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -561,7 +561,7 @@ class SSH(object): self.opts) sys.exit(final_exit) - + class Single(object): ''' From 041bdbff181691baf48c7d0d7900f9281bdd66bb Mon Sep 17 00:00:00 2001 From: Nathan Grennan Date: Mon, 4 May 2015 15:44:27 -0700 Subject: [PATCH 7/8] Adding EX_AGGREGATE exit code and using it --- salt/client/ssh/__init__.py | 4 ++-- salt/defaults/exitcodes.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index 23f86013d6..be0c55493d 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -559,8 +559,8 @@ class SSH(object): sret, outputter, self.opts) - - sys.exit(final_exit) + if final_exit: + sys.exit(salt.defaults.exitcodes.EX_AGGREGATE) class Single(object): diff --git a/salt/defaults/exitcodes.py b/salt/defaults/exitcodes.py index d4c116b770..f6ed730aca 100644 --- a/salt/defaults/exitcodes.py +++ b/salt/defaults/exitcodes.py @@ -15,6 +15,9 @@ EX_THIN_DEPLOY = 11 EX_THIN_CHECKSUM = 12 EX_MOD_DEPLOY = 13 +# One of a collection failed +EX_AGGREGATE = 20 + # The os.EX_* exit codes are Unix only so in the interest of cross-platform # compatiblility define them explicitly here. # From d02d36525e1e1d061df82ef33bfe7cf719e9c581 Mon Sep 17 00:00:00 2001 From: Nathan Grennan Date: Tue, 5 May 2015 14:00:53 -0700 Subject: [PATCH 8/8] Fixing retcode for normal run with no errors --- salt/client/ssh/__init__.py | 4 ++-- salt/client/ssh/wrapper/__init__.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index be0c55493d..adcd089a73 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -766,11 +766,11 @@ class Single(object): opts_pkg['_caller_cachedir'] = self.opts['cachedir'] # Use the ID defined in the roster file opts_pkg['id'] = self.id + retcode = opts_pkg['retcode'] if '_error' in opts_pkg: # Refresh failed ret = json.dumps({'local': opts_pkg}) - retcode = opts_pkg['retcode'] return ret, retcode pillar = salt.pillar.Pillar( @@ -848,7 +848,7 @@ class Single(object): ret = json.dumps({'local': result['local']}) else: ret = json.dumps({'local': {'return': result}}) - return ret + return ret, retcode def _cmd_str(self): ''' diff --git a/salt/client/ssh/wrapper/__init__.py b/salt/client/ssh/wrapper/__init__.py index 02f5032fda..d615d41c7a 100644 --- a/salt/client/ssh/wrapper/__init__.py +++ b/salt/client/ssh/wrapper/__init__.py @@ -114,12 +114,14 @@ class FunctionWrapper(object): if stderr.count('Permission Denied'): return {'_error': 'Permission Denied', 'stdout': stdout, - 'stderr': stderr} + 'stderr': stderr + 'retcode': retcode} try: ret = json.loads(stdout, object_hook=salt.utils.decode_dict) if len(ret) < 2 and 'local' in ret: ret = ret['local'] ret = ret.get('return', {}) + ret.update({'retcode': retcode}) except ValueError: ret = {'_error': 'Failed to return clean data', 'stderr': stderr,