From 386375a5ea3c1751a15567233414ccd9c3a693e0 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Fri, 9 May 2014 09:04:10 -0600 Subject: [PATCH 1/3] Friendly error message on insufficient permissions. Better wording. --- salt/client/ssh/__init__.py | 5 ++++- salt/scripts.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index d3aef688e0..49ff726441 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -182,7 +182,10 @@ class SSH(object): ) ) if not os.path.isfile(priv): - salt.client.ssh.shell.gen_key(priv) + try: + salt.client.ssh.shell.gen_key(priv) + except OSError: + raise salt.exceptions.SaltClientError('salt-ssh could not be run because it could not generate keys.\n\nYou can probably resolve this by executing this script with increased permissions via sudo or by running as root.\nYou could also use the \'-c\' option to supply a configuration directory that you have permissions to read and write to.') self.defaults = { 'user': self.opts.get( 'ssh_user', diff --git a/salt/scripts.py b/salt/scripts.py index 3a7b73957e..5435336162 100644 --- a/salt/scripts.py +++ b/salt/scripts.py @@ -11,6 +11,7 @@ import time # Import salt libs import salt +import salt.exceptions import salt.cli try: import salt.cloud.cli @@ -121,6 +122,8 @@ def salt_ssh(): client.run() except KeyboardInterrupt: raise SystemExit('\nExiting gracefully on Ctrl-c') + except salt.exceptions.SaltClientError as err: + raise SystemExit(err) def salt_cloud(): From 608d6d18556f815438f9c009467639119fe74010 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Fri, 9 May 2014 09:26:41 -0600 Subject: [PATCH 2/3] Display error if we have no matching targets in roster. --- salt/client/ssh/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index 49ff726441..ea7a1f5fa6 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -344,6 +344,8 @@ class SSH(object): returned = set() rets = set() init = False + if not self.targets: + raise salt.exceptions.SaltClientError('No matching targets found in roster.') while True: if len(running) < self.opts.get('ssh_max_procs', 25) and not init: try: From bacd5be8ca943c43d25ed5f8bff2c96713360570 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Fri, 9 May 2014 11:00:42 -0600 Subject: [PATCH 3/3] Restore salt-ssh to working order * Removed misleading (to me at least) messages from stderr. * Added explicit exits to the sh shim * Fix index error where we incorrectly detect master deploy msg. --- salt/client/ssh/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index ea7a1f5fa6..3e5de01ad1 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -127,10 +127,10 @@ main() if "$py_cmd" -c 'import sys; sys.exit(not sys.hexversion >= 0x02060000);' >/dev/null 2>&1; then local py_cmd_path py_cmd_path=`"$py_cmd" -c 'import sys; print sys.executable;'` - echo "FOUND: $py_cmd_path" >&2 exec $SUDO "$py_cmd_path" -c 'exec """{{SSH_PY_CODE}}""".decode("base64")' -- {{SSH_PY_ARGS}} + exit 0 else - echo "WARNING: $py_cmd not found or too old" >&2 + continue fi done @@ -726,7 +726,7 @@ class Single(object): else: # RSTR was found in stdout but not stderr - which means there # is a SHIM command for the master. - shim_command = re.split(r'\r?\n', stdout, 1)[0].strip() + shim_command = re.split(r'\r?\n', stdout, 1)[1].strip() if 'deploy' == shim_command and retcode == salt.exitcodes.EX_THIN_DEPLOY: self.deploy() stdout, stderr, retcode = self.shell.exec_cmd(cmd_str)