Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Changes
write function.
* ``SSHClient``, ``TunnelServer`` and ``LocalForwarder`` now use their own gevent pools for greenlets spawned so they
are cleaned up correctly at shutdown.
* ``SSHClient.execute`` is now deprecated in favour of ``SSHClient.run_command``.

Fixes
------
Expand Down
4 changes: 4 additions & 0 deletions ci/integration_tests/libssh2_clients/test_single_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ def test_execute(self):
self.assertEqual(expected, output)
self.assertEqual(expected_stderr, stderr)

def test_execute_depr(self):
chan = self.client.execute(self.cmd)
self.assertIsNotNone(chan)

def test_alias(self):
client = SSHClient(self.host, port=self.port,
pkey=self.user_key, num_retries=1,
Expand Down
9 changes: 8 additions & 1 deletion pssh/clients/base/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,13 @@ def _make_output_readers(self, channel, stdout_buffer, stderr_buffer):
raise NotImplementedError

def execute(self, cmd, use_pty=False, channel=None):
"""
Deprecated - use ``run_command`` instead which returns a ``HostOutput`` object.
"""
warn("Deprecated - use run_command instead.", DeprecationWarning)
return self._execute(cmd, use_pty=use_pty, channel=channel)

def _execute(self, cmd, use_pty=False, channel=None):
raise NotImplementedError

def read_stderr(self, stderr_buffer, timeout=None):
Expand Down Expand Up @@ -620,7 +627,7 @@ def run_command(self, command, sudo=False, user=None,
_command += "%s '%s'" % (_shell, command,)
_command = _command.encode(encoding)
with GTimeout(seconds=self.timeout):
channel = self.execute(_command, use_pty=use_pty)
channel = self._execute(_command, use_pty=use_pty)
_timeout = read_timeout if read_timeout else timeout
host_out = self._make_host_output(channel, encoding, _timeout)
return host_out
Expand Down
2 changes: 1 addition & 1 deletion pssh/clients/native/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def _make_output_readers(self, channel, stdout_buffer, stderr_buffer):
self._read_output_to_buffer, channel.read_stderr, stderr_buffer)
return _stdout_reader, _stderr_reader

def execute(self, cmd, use_pty=False, channel=None):
def _execute(self, cmd, use_pty=False, channel=None):
"""
Use ``run_command`` which returns a ``HostOutput`` object rather than this function directly.

Expand Down
3 changes: 1 addition & 2 deletions pssh/clients/ssh/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import logging

from gevent import sleep, spawn, Timeout as GTimeout, joinall
from gevent.socket import SHUT_RDWR
from ssh import options
Expand Down Expand Up @@ -236,7 +235,7 @@ def _make_output_readers(self, channel, stdout_buffer, stderr_buffer):
self._read_output_to_buffer, channel, stderr_buffer, is_stderr=True)
return _stdout_reader, _stderr_reader

def execute(self, cmd, use_pty=False, channel=None):
def _execute(self, cmd, use_pty=False, channel=None):
"""Execute command on remote host.

:param cmd: The command string to execute.
Expand Down