From 03127dcfaea1442db2ddd2b964705e3f377c58a8 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 24 Sep 2015 08:56:20 -0700 Subject: [PATCH] remove the stdin return value from connection plugin exec_command() methods The value was useless -- unused by the callers and always hardcoded to the empty string. --- lib/ansible/plugins/action/__init__.py | 2 +- lib/ansible/plugins/connection/__init__.py | 6 +++++- lib/ansible/plugins/connection/accelerate.py | 2 +- lib/ansible/plugins/connection/chroot.py | 2 +- lib/ansible/plugins/connection/docker.py | 2 +- lib/ansible/plugins/connection/funcd.py | 2 +- lib/ansible/plugins/connection/jail.py | 2 +- lib/ansible/plugins/connection/libvirt_lxc.py | 2 +- lib/ansible/plugins/connection/local.py | 2 +- lib/ansible/plugins/connection/paramiko_ssh.py | 2 +- lib/ansible/plugins/connection/ssh.py | 2 +- lib/ansible/plugins/connection/winrm.py | 2 +- lib/ansible/plugins/connection/zone.py | 2 +- test/units/plugins/action/test_action.py | 2 +- 14 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 744eea7f8b..ee104bd139 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -467,7 +467,7 @@ class ActionBase: cmd = self._play_context.make_become_cmd(cmd, executable=executable) self._display.debug("executing the command %s through the connection" % cmd) - rc, stdin, stdout, stderr = self._connection.exec_command(cmd, tmp, in_data=in_data, sudoable=sudoable) + rc, stdout, stderr = self._connection.exec_command(cmd, tmp, in_data=in_data, sudoable=sudoable) self._display.debug("command execution done") if not isinstance(stdout, string_types): diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py index 1c11bcb936..9bd3375730 100644 --- a/lib/ansible/plugins/connection/__init__.py +++ b/lib/ansible/plugins/connection/__init__.py @@ -123,7 +123,11 @@ class ConnectionBase(with_metaclass(ABCMeta, object)): @ensure_connect @abstractmethod def exec_command(self, cmd, tmp_path, in_data=None, executable=None, sudoable=True): - """Run a command on the remote host""" + """Run a command on the remote host + + :returns: a tuple of (return code, stdout, stderr) The return code is + an int while stdout and stderr are both byte strings. + """ pass @ensure_connect diff --git a/lib/ansible/plugins/connection/accelerate.py b/lib/ansible/plugins/connection/accelerate.py index d0bd5ad3d1..67c070dc71 100644 --- a/lib/ansible/plugins/connection/accelerate.py +++ b/lib/ansible/plugins/connection/accelerate.py @@ -281,7 +281,7 @@ class Connection(ConnectionBase): vvvv("%s: received the response" % self.host) break - return (response.get('rc',None), '', response.get('stdout',''), response.get('stderr','')) + return (response.get('rc', None), response.get('stdout', ''), response.get('stderr', '')) def put_file(self, in_path, out_path): diff --git a/lib/ansible/plugins/connection/chroot.py b/lib/ansible/plugins/connection/chroot.py index 6ef3a61cb5..82b3bbd383 100644 --- a/lib/ansible/plugins/connection/chroot.py +++ b/lib/ansible/plugins/connection/chroot.py @@ -116,7 +116,7 @@ class Connection(ConnectionBase): p = self._buffered_exec_command(cmd, tmp_path, become_user, sudoable, executable, in_data) stdout, stderr = p.communicate() - return (p.returncode, '', stdout, stderr) + return (p.returncode, stdout, stderr) def put_file(self, in_path, out_path): ''' transfer a file from local to chroot ''' diff --git a/lib/ansible/plugins/connection/docker.py b/lib/ansible/plugins/connection/docker.py index 1103327470..9fa9da8c6d 100644 --- a/lib/ansible/plugins/connection/docker.py +++ b/lib/ansible/plugins/connection/docker.py @@ -111,7 +111,7 @@ class Connection(ConnectionBase): stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() - return (p.returncode, '', stdout, stderr) + return (p.returncode, stdout, stderr) # Docker doesn't have native support for copying files into running # containers, so we use docker exec to implement this diff --git a/lib/ansible/plugins/connection/funcd.py b/lib/ansible/plugins/connection/funcd.py index 92bda4bb34..4d73fc4717 100644 --- a/lib/ansible/plugins/connection/funcd.py +++ b/lib/ansible/plugins/connection/funcd.py @@ -65,7 +65,7 @@ class Connection(object): # totally ignores privlege escalation vvv("EXEC %s" % (cmd), host=self.host) p = self.client.command.run(cmd)[self.host] - return (p[0], '', p[1], p[2]) + return (p[0], p[1], p[2]) def _normalize_path(self, path, prefix): if not path.startswith(os.path.sep): diff --git a/lib/ansible/plugins/connection/jail.py b/lib/ansible/plugins/connection/jail.py index d12318391c..71430e72bc 100644 --- a/lib/ansible/plugins/connection/jail.py +++ b/lib/ansible/plugins/connection/jail.py @@ -133,7 +133,7 @@ class Connection(object): p = self._buffered_exec_command(cmd, tmp_path, become_user, sudoable, executable, in_data) stdout, stderr = p.communicate() - return (p.returncode, '', stdout, stderr) + return (p.returncode, stdout, stderr) def put_file(self, in_path, out_path): ''' transfer a file from local to jail ''' diff --git a/lib/ansible/plugins/connection/libvirt_lxc.py b/lib/ansible/plugins/connection/libvirt_lxc.py index 1905eb6a66..162c94f3d0 100644 --- a/lib/ansible/plugins/connection/libvirt_lxc.py +++ b/lib/ansible/plugins/connection/libvirt_lxc.py @@ -88,7 +88,7 @@ class Connection(object): stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() - return (p.returncode, '', stdout, stderr) + return (p.returncode, stdout, stderr) def _normalize_path(self, path, prefix): if not path.startswith(os.path.sep): diff --git a/lib/ansible/plugins/connection/local.py b/lib/ansible/plugins/connection/local.py index 1b5a0efe29..060b383a35 100644 --- a/lib/ansible/plugins/connection/local.py +++ b/lib/ansible/plugins/connection/local.py @@ -98,7 +98,7 @@ class Connection(ConnectionBase): self._display.debug("done communicating") self._display.debug("done with local.exec_command()") - return (p.returncode, '', stdout, stderr) + return (p.returncode, stdout, stderr) def put_file(self, in_path, out_path): ''' transfer a file from local to local ''' diff --git a/lib/ansible/plugins/connection/paramiko_ssh.py b/lib/ansible/plugins/connection/paramiko_ssh.py index 9e0353159c..dca04d05cb 100644 --- a/lib/ansible/plugins/connection/paramiko_ssh.py +++ b/lib/ansible/plugins/connection/paramiko_ssh.py @@ -256,7 +256,7 @@ class Connection(ConnectionBase): stdout = ''.join(chan.makefile('rb', bufsize)) stderr = ''.join(chan.makefile_stderr('rb', bufsize)) - return (chan.recv_exit_status(), '', no_prompt_out + stdout, no_prompt_out + stderr) + return (chan.recv_exit_status(), no_prompt_out + stdout, no_prompt_out + stderr) def put_file(self, in_path, out_path): ''' transfer a file from local to remote ''' diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 3add0298b2..fbc2793738 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -304,7 +304,7 @@ class Connection(ConnectionBase): (returncode, stdout, stderr) = self._run(cmd, in_data, sudoable=sudoable) - return (returncode, '', stdout, stderr) + return (returncode, stdout, stderr) def put_file(self, in_path, out_path): ''' transfer a file from local to remote ''' diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py index d1a6f57c53..1242cfeaf5 100644 --- a/lib/ansible/plugins/connection/winrm.py +++ b/lib/ansible/plugins/connection/winrm.py @@ -202,7 +202,7 @@ class Connection(ConnectionBase): raise AnsibleError("failed to exec cmd %s" % cmd) result.std_out = to_unicode(result.std_out) result.std_err = to_unicode(result.std_err) - return (result.status_code, '', result.std_out, result.std_err) + return (result.status_code, result.std_out, result.std_err) def put_file(self, in_path, out_path): super(Connection, self).put_file(in_path, out_path) diff --git a/lib/ansible/plugins/connection/zone.py b/lib/ansible/plugins/connection/zone.py index 82256742a1..120e6969b3 100644 --- a/lib/ansible/plugins/connection/zone.py +++ b/lib/ansible/plugins/connection/zone.py @@ -146,7 +146,7 @@ class Connection(object): p = self._buffered_exec_command(cmd, tmp_path, become_user, sudoable, executable, in_data) stdout, stderr = p.communicate() - return (p.returncode, '', stdout, stderr) + return (p.returncode, stdout, stderr) def put_file(self, in_path, out_path): ''' transfer a file from local to zone ''' diff --git a/test/units/plugins/action/test_action.py b/test/units/plugins/action/test_action.py index 24fd325993..68f787641f 100644 --- a/test/units/plugins/action/test_action.py +++ b/test/units/plugins/action/test_action.py @@ -32,7 +32,7 @@ class TestActionBase(unittest.TestCase): def test_sudo_only_if_user_differs(self): play_context = PlayContext() action_base = ActionBase(None, None, play_context, None, None, None) - action_base._connection = Mock(exec_command=Mock(return_value=(0, '', '', ''))) + action_base._connection = Mock(exec_command=Mock(return_value=(0, '', ''))) play_context.become = True play_context.become_user = play_context.remote_user = 'root'