Skip to content

Commit 987dd58

Browse files
authored
Deprecated execute function on single clients, updated changelog (#403)
* Deprecated execute function on single clients * Added test * Updated changelog
1 parent 0567bda commit 987dd58

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

Changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Changes
1818
write function.
1919
* ``SSHClient``, ``TunnelServer`` and ``LocalForwarder`` now use their own gevent pools for greenlets spawned so they
2020
are cleaned up correctly at shutdown.
21+
* ``SSHClient.execute`` is now deprecated in favour of ``SSHClient.run_command``.
2122

2223
Fixes
2324
------

ci/integration_tests/libssh2_clients/test_single_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ def test_execute(self):
184184
self.assertEqual(expected, output)
185185
self.assertEqual(expected_stderr, stderr)
186186

187+
def test_execute_depr(self):
188+
chan = self.client.execute(self.cmd)
189+
self.assertIsNotNone(chan)
190+
187191
def test_alias(self):
188192
client = SSHClient(self.host, port=self.port,
189193
pkey=self.user_key, num_retries=1,

pssh/clients/base/single.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ def _make_output_readers(self, channel, stdout_buffer, stderr_buffer):
486486
raise NotImplementedError
487487

488488
def execute(self, cmd, use_pty=False, channel=None):
489+
"""
490+
Deprecated - use ``run_command`` instead which returns a ``HostOutput`` object.
491+
"""
492+
warn("Deprecated - use run_command instead.", DeprecationWarning)
493+
return self._execute(cmd, use_pty=use_pty, channel=channel)
494+
495+
def _execute(self, cmd, use_pty=False, channel=None):
489496
raise NotImplementedError
490497

491498
def read_stderr(self, stderr_buffer, timeout=None):
@@ -620,7 +627,7 @@ def run_command(self, command, sudo=False, user=None,
620627
_command += "%s '%s'" % (_shell, command,)
621628
_command = _command.encode(encoding)
622629
with GTimeout(seconds=self.timeout):
623-
channel = self.execute(_command, use_pty=use_pty)
630+
channel = self._execute(_command, use_pty=use_pty)
624631
_timeout = read_timeout if read_timeout else timeout
625632
host_out = self._make_host_output(channel, encoding, _timeout)
626633
return host_out

pssh/clients/native/single.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def _make_output_readers(self, channel, stdout_buffer, stderr_buffer):
338338
self._read_output_to_buffer, channel.read_stderr, stderr_buffer)
339339
return _stdout_reader, _stderr_reader
340340

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

pssh/clients/ssh/single.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717

1818
import logging
19-
2019
from gevent import sleep, spawn, Timeout as GTimeout, joinall
2120
from gevent.socket import SHUT_RDWR
2221
from ssh import options
@@ -236,7 +235,7 @@ def _make_output_readers(self, channel, stdout_buffer, stderr_buffer):
236235
self._read_output_to_buffer, channel, stderr_buffer, is_stderr=True)
237236
return _stdout_reader, _stderr_reader
238237

239-
def execute(self, cmd, use_pty=False, channel=None):
238+
def _execute(self, cmd, use_pty=False, channel=None):
240239
"""Execute command on remote host.
241240
242241
:param cmd: The command string to execute.

0 commit comments

Comments
 (0)