diff --git a/Changelog.rst b/Changelog.rst index d518cd5b..a73ab068 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -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 ------ diff --git a/ci/integration_tests/libssh2_clients/test_single_client.py b/ci/integration_tests/libssh2_clients/test_single_client.py index 24b04489..9b3173a7 100644 --- a/ci/integration_tests/libssh2_clients/test_single_client.py +++ b/ci/integration_tests/libssh2_clients/test_single_client.py @@ -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, diff --git a/pssh/clients/base/single.py b/pssh/clients/base/single.py index cbb6e9ed..05140aec 100644 --- a/pssh/clients/base/single.py +++ b/pssh/clients/base/single.py @@ -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): @@ -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 diff --git a/pssh/clients/native/single.py b/pssh/clients/native/single.py index 9dd0f4b6..15ae40f6 100644 --- a/pssh/clients/native/single.py +++ b/pssh/clients/native/single.py @@ -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. diff --git a/pssh/clients/ssh/single.py b/pssh/clients/ssh/single.py index f37ab6d2..bc4cc2da 100644 --- a/pssh/clients/ssh/single.py +++ b/pssh/clients/ssh/single.py @@ -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 @@ -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.