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.
This commit is contained in:
Toshio Kuratomi 2015-09-24 08:56:20 -07:00
parent 9d47eabfa4
commit 03127dcfae
14 changed files with 18 additions and 14 deletions

View file

@ -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):

View file

@ -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

View file

@ -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):

View file

@ -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 '''

View file

@ -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

View file

@ -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):

View file

@ -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 '''

View file

@ -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):

View file

@ -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 '''

View file

@ -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 '''

View file

@ -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 '''

View file

@ -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)

View file

@ -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 '''

View file

@ -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'