Skip to content

Commit 3130318

Browse files
authored
Removed deprecated since 2.0.0 functions and parameters. Updated tests (#314)
1 parent 7232d85 commit 3130318

File tree

6 files changed

+35
-75
lines changed

6 files changed

+35
-75
lines changed

Changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Changes
88
-------
99

1010
* ``user`` keyword argument no longer required on Windows - exception is raised if user cannot be identified.
11+
* Removed deprecated since ``2.0.0`` functions and parameters.
1112

1213
2.5.4
1314
+++++

pssh/clients/base/parallel.py

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import gevent.pool
2323

24-
from warnings import warn
2524
from gevent import joinall, spawn, Timeout as GTimeout
2625
from gevent.hub import Hub
2726

@@ -171,7 +170,7 @@ def join_shells(self, shells, timeout=None):
171170

172171
def run_command(self, command, user=None, stop_on_errors=True,
173172
host_args=None, use_pty=False, shell=None,
174-
encoding='utf-8', return_list=True,
173+
encoding='utf-8',
175174
*args, **kwargs):
176175
if host_args:
177176
try:
@@ -194,11 +193,9 @@ def run_command(self, command, user=None, stop_on_errors=True,
194193
for host_i, host in enumerate(self.hosts)]
195194
self.cmds = cmds
196195
joinall(cmds, timeout=self.timeout)
197-
return self._get_output_from_cmds(cmds, raise_error=stop_on_errors,
198-
return_list=return_list)
196+
return self._get_output_from_cmds(cmds, raise_error=stop_on_errors)
199197

200-
def _get_output_from_cmds(self, cmds, raise_error=False,
201-
return_list=True):
198+
def _get_output_from_cmds(self, cmds, raise_error=False):
202199
_cmds = [spawn(self._get_output_from_greenlet, cmd, raise_error=raise_error)
203200
for cmd in cmds]
204201
finished = joinall(_cmds, raise_error=True)
@@ -217,33 +214,19 @@ def _get_output_from_greenlet(self, cmd, raise_error=False):
217214
return HostOutput(host, None, None, None,
218215
exception=ex)
219216

220-
def get_last_output(self, cmds=None, timeout=None,
221-
return_list=True):
217+
def get_last_output(self, cmds=None):
222218
"""Get output for last commands executed by ``run_command``.
223219
224220
:param cmds: Commands to get output for. Defaults to ``client.cmds``
225221
:type cmds: list(:py:class:`gevent.Greenlet`)
226-
:param timeout: No-op - to be removed.
227-
:param return_list: No-op - list of ``HostOutput`` always returned.
228-
Parameter kept for backwards compatibility - to be removed in future
229-
releases.
230-
:type return_list: bool
231222
232223
:rtype: dict or list
233224
"""
234225
cmds = self.cmds if cmds is None else cmds
235226
if cmds is None:
236227
return
237228
return self._get_output_from_cmds(
238-
cmds, return_list=return_list,
239-
raise_error=False)
240-
241-
def reset_output_generators(self, host_out, timeout=None,
242-
client=None, channel=None,
243-
encoding='utf-8'):
244-
"""No-op - to be removed."""
245-
warn("This function is a no-op and deprecated. "
246-
"It will be removed in future releases")
229+
cmds, raise_error=False)
247230

248231
def _get_host_config_values(self, host_i, host):
249232
if self.host_config is None:
@@ -308,8 +291,7 @@ def _consume_output(self, stdout, stderr):
308291
for line in stderr:
309292
pass
310293

311-
def join(self, output=None, consume_output=False, timeout=None,
312-
encoding='utf-8'):
294+
def join(self, output=None, consume_output=False, timeout=None):
313295
"""Wait until all remote commands in output have finished.
314296
Does *not* block other commands from running in parallel.
315297
@@ -328,9 +310,6 @@ def join(self, output=None, consume_output=False, timeout=None,
328310
Since self.timeout is passed onto each individual SSH session it is
329311
**not** used for any parallel functions like `run_command` or `join`.
330312
:type timeout: int
331-
:param encoding: Unused - encoding from each ``HostOutput`` is used instead.
332-
To be removed in future releases.
333-
:type encoding: str
334313
335314
:raises: :py:class:`pssh.exceptions.Timeout` on timeout requested and
336315
reached with commands still running.
@@ -341,7 +320,7 @@ def join(self, output=None, consume_output=False, timeout=None,
341320
elif not isinstance(output, list):
342321
raise ValueError("Unexpected output object type")
343322
cmds = [self.pool.spawn(self._join, host_out, timeout=timeout,
344-
consume_output=consume_output, encoding=encoding)
323+
consume_output=consume_output)
345324
for host_i, host_out in enumerate(output)]
346325
# Errors raised by self._join should be propagated.
347326
finished_cmds = joinall(cmds, raise_error=True, timeout=timeout)

pssh/clients/native/parallel.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, hosts, user=None, password=None, port=22, pkey=None,
3535
allow_agent=True, host_config=None, retry_delay=RETRY_DELAY,
3636
proxy_host=None, proxy_port=None,
3737
proxy_user=None, proxy_password=None, proxy_pkey=None,
38-
forward_ssh_agent=False, tunnel_timeout=None,
38+
forward_ssh_agent=False,
3939
keepalive_seconds=60, identity_auth=True):
4040
"""
4141
:param hosts: Hosts to connect to
@@ -109,7 +109,6 @@ def __init__(self, hosts, user=None, password=None, port=22, pkey=None,
109109
Defaults to False if not set.
110110
Requires agent forwarding implementation in libssh2 version used.
111111
:type forward_ssh_agent: bool
112-
:param tunnel_timeout: No-op - to be removed.
113112
114113
:raises: :py:class:`pssh.exceptions.PKeyFileError` on errors finding
115114
provided private key.
@@ -131,8 +130,8 @@ def __init__(self, hosts, user=None, password=None, port=22, pkey=None,
131130

132131
def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
133132
use_pty=False, host_args=None, shell=None,
134-
encoding='utf-8', timeout=None, read_timeout=None,
135-
return_list=False):
133+
encoding='utf-8', read_timeout=None,
134+
):
136135
"""Run command on all hosts in parallel, honoring self.pool_size,
137136
and return output.
138137
@@ -181,14 +180,6 @@ def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
181180
raise :py:class:`pssh.exceptions.Timeout`
182181
after ``timeout`` seconds when set if remote output is not ready.
183182
:type read_timeout: float
184-
:param timeout: Deprecated - use read_timeout. Same as
185-
read_timeout and kept for backwards compatibility - to be removed
186-
in future release.
187-
:type timeout: float
188-
:param return_list: No-op - list of ``HostOutput`` always returned.
189-
Parameter kept for backwards compatibility - to be removed in future
190-
releases.
191-
:type return_list: bool
192183
:rtype: list(:py:class:`pssh.output.HostOutput`)
193184
194185
:raises: :py:class:`pssh.exceptions.AuthenticationError` on
@@ -214,7 +205,7 @@ def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
214205
self, command, stop_on_errors=stop_on_errors, host_args=host_args,
215206
user=user, shell=shell, sudo=sudo,
216207
encoding=encoding, use_pty=use_pty,
217-
return_list=return_list, read_timeout=read_timeout if read_timeout else timeout,
208+
read_timeout=read_timeout,
218209
)
219210

220211
def __del__(self):

pssh/clients/ssh/parallel.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ def __init__(self, hosts, user=None, password=None, port=22, pkey=None,
143143

144144
def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
145145
use_pty=False, host_args=None, shell=None,
146-
encoding='utf-8', timeout=None, read_timeout=None,
147-
return_list=False):
146+
encoding='utf-8', read_timeout=None,
147+
):
148148
"""Run command on all hosts in parallel, honoring self.pool_size,
149149
and return output.
150150
@@ -193,14 +193,6 @@ def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
193193
raise :py:class:`pssh.exceptions.Timeout`
194194
after ``timeout`` number seconds if remote output is not ready.
195195
:type read_timeout: float
196-
:param timeout: Deprecated - use read_timeout. Same as
197-
read_timeout and kept for backwards compatibility - to be removed
198-
in future release.
199-
:type timeout: float
200-
:param return_list: No-op - list of ``HostOutput`` always returned.
201-
Parameter kept for backwards compatibility - to be removed in future
202-
releases.
203-
:type return_list: bool
204196
:rtype: list(:py:class:`pssh.output.HostOutput`)
205197
206198
:raises: :py:class:`pssh.exceptions.AuthenticationError` on
@@ -225,8 +217,7 @@ def run_command(self, command, sudo=False, user=None, stop_on_errors=True,
225217
self, command, stop_on_errors=stop_on_errors, host_args=host_args,
226218
user=user, shell=shell, sudo=sudo,
227219
encoding=encoding, use_pty=use_pty,
228-
return_list=return_list,
229-
read_timeout=read_timeout if read_timeout else timeout,
220+
read_timeout=read_timeout,
230221
)
231222

232223
def _make_ssh_client(self, host_i, host):

tests/native/test_parallel_client.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def test_client_join_stdout(self):
199199
self.assertTrue(len(_output) == len(output))
200200

201201
def test_pssh_client_no_stdout_non_zero_exit_code_immediate_exit(self):
202-
output = self.client.run_command('exit 1', return_list=True)
202+
output = self.client.run_command('exit 1')
203203
expected_exit_code = 1
204204
self.client.join(output)
205205
exit_code = output[0].exit_code
@@ -209,7 +209,7 @@ def test_pssh_client_no_stdout_non_zero_exit_code_immediate_exit(self):
209209
expected_exit_code,))
210210

211211
def test_pssh_client_no_stdout_non_zero_exit_code_immediate_exit_no_join(self):
212-
output = self.client.run_command('exit 1', return_list=True)
212+
output = self.client.run_command('exit 1')
213213
expected_exit_code = 1
214214
for host_out in output:
215215
for line in host_out.stdout:
@@ -891,7 +891,7 @@ def test_identical_hosts_in_host_list(self):
891891
client = ParallelSSHClient(hosts, port=self.port,
892892
pkey=self.user_key,
893893
num_retries=1)
894-
output = client.run_command(self.cmd, stop_on_errors=False, return_list=True)
894+
output = client.run_command(self.cmd, stop_on_errors=False)
895895
client.join(output)
896896
self.assertEqual(len(hosts), len(output),
897897
msg="Host list contains %s identical hosts, only got output for %s" % (
@@ -1347,7 +1347,7 @@ def test_unknown_host_failure(self):
13471347
def test_open_channel_failure(self):
13481348
client = ParallelSSHClient([self.host], port=self.port,
13491349
pkey=self.user_key)
1350-
output = client.run_command(self.cmd, return_list=True)
1350+
output = client.run_command(self.cmd)
13511351
client.join(output)
13521352
output[0].client.session.disconnect()
13531353
self.assertRaises(SessionError, output[0].client.open_session)
@@ -1411,7 +1411,7 @@ def test_join_timeout_set_no_timeout(self):
14111411
def test_read_timeout(self):
14121412
client = ParallelSSHClient([self.host], port=self.port,
14131413
pkey=self.user_key)
1414-
output = client.run_command('sleep .3; echo me; echo me; echo me', timeout=.2)
1414+
output = client.run_command('sleep .3; echo me; echo me; echo me', read_timeout=.2)
14151415
for host_out in output:
14161416
self.assertRaises(Timeout, list, host_out.stdout)
14171417
self.assertFalse(client.finished(output))
@@ -1425,7 +1425,7 @@ def test_read_timeout(self):
14251425
def test_partial_read_timeout_close_cmd(self):
14261426
self.assertTrue(self.client.finished())
14271427
output = self.client.run_command('while true; do echo a line; sleep .1; done',
1428-
use_pty=True, timeout=.15)
1428+
use_pty=True, read_timeout=.15)
14291429
stdout = []
14301430
try:
14311431
with GTimeout(seconds=.25):
@@ -1473,8 +1473,6 @@ def test_partial_read_timeout_join_no_output(self):
14731473
else:
14741474
raise Exception("Should have timed out")
14751475
self.assertTrue(len(stdout) > 0)
1476-
# Should be no-op
1477-
self.client.reset_output_generators(output[0], timeout=None)
14781476
# Setting timeout
14791477
output[0].read_timeout = .2
14801478
stdout = []
@@ -1522,7 +1520,7 @@ def test_file_read_no_timeout(self):
15221520
with open(_file, 'wb') as fh:
15231521
fh.writelines(contents)
15241522
try:
1525-
output = self.client.run_command('cat %s' % (_file,), timeout=10)
1523+
output = self.client.run_command('cat %s' % (_file,), read_timeout=10)
15261524
_out = list(output[0].stdout)
15271525
finally:
15281526
os.unlink(_file)
@@ -1830,11 +1828,11 @@ def test_multiple_join_timeout(self):
18301828
client = ParallelSSHClient([self.host], port=self.port,
18311829
pkey=self.user_key)
18321830
for _ in range(5):
1833-
output = client.run_command(self.cmd, return_list=True)
1831+
output = client.run_command(self.cmd)
18341832
client.join(output, timeout=1, consume_output=True)
18351833
for host_out in output:
18361834
self.assertTrue(host_out.client.finished(host_out.channel))
1837-
output = client.run_command('sleep .2', return_list=True)
1835+
output = client.run_command('sleep .2')
18381836
self.assertRaises(Timeout, client.join, output, timeout=.1, consume_output=True)
18391837
for host_out in output:
18401838
self.assertFalse(host_out.client.finished(host_out.channel))
@@ -1843,12 +1841,12 @@ def test_multiple_run_command_timeout(self):
18431841
client = ParallelSSHClient([self.host], port=self.port,
18441842
pkey=self.user_key)
18451843
for _ in range(5):
1846-
output = client.run_command('pwd', return_list=True, timeout=1)
1844+
output = client.run_command('pwd', read_timeout=1)
18471845
for host_out in output:
18481846
stdout = list(host_out.stdout)
18491847
self.assertTrue(len(stdout) > 0)
18501848
self.assertTrue(host_out.client.finished(host_out.channel))
1851-
output = client.run_command('sleep .25; echo me', return_list=True, timeout=.1)
1849+
output = client.run_command('sleep .25; echo me', read_timeout=.1)
18521850
for host_out in output:
18531851
self.assertRaises(Timeout, list, host_out.stdout)
18541852
client.join(output)
@@ -1893,7 +1891,7 @@ def test_read_stdout_no_timeout(self):
18931891
cmd = 'sleep .1; echo me; sleep .1; echo me'
18941892
read_timeout = 1
18951893
output = self.client.run_command(
1896-
cmd, timeout=read_timeout, stop_on_errors=False)
1894+
cmd, read_timeout=read_timeout, stop_on_errors=False)
18971895
for host_out in output:
18981896
dt, timed_out = self.read_stream_dt(host_out, host_out.stdout, read_timeout)
18991897
self.assertFalse(timed_out)
@@ -1907,7 +1905,7 @@ def test_read_timeout_no_timeouts(self):
19071905
read_timeout = 1
19081906
# No timeouts
19091907
output = self.client.run_command(
1910-
cmd, timeout=read_timeout, stop_on_errors=False, return_list=True)
1908+
cmd, read_timeout=read_timeout, stop_on_errors=False)
19111909
for host_out in output:
19121910
dt, timed_out = self.read_stream_dt(host_out, host_out.stdout, read_timeout)
19131911
self.assertTrue(dt.total_seconds() < read_timeout)
@@ -1917,11 +1915,11 @@ def test_read_timeout_no_timeouts(self):
19171915
self.assertTrue(dt.total_seconds() < read_timeout)
19181916

19191917
def test_read_stdout_timeout_stderr_no_timeout(self):
1918+
"""No timeouts for stderr only"""
19201919
cmd = 'sleep .1; echo me >&2; sleep .1; echo me >&2; sleep .1'
19211920
read_timeout = .25
1922-
# No timeouts for stderr only
19231921
output = self.client.run_command(
1924-
cmd, timeout=read_timeout, stop_on_errors=False)
1922+
cmd, read_timeout=read_timeout, stop_on_errors=False)
19251923
for host_out in output:
19261924
dt, timed_out = self.read_stream_dt(host_out, host_out.stdout, read_timeout)
19271925
self.assertTrue(timed_out)

tests/ssh/test_parallel_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def test_escaped_quotes(self):
370370
def test_read_timeout(self):
371371
client = ParallelSSHClient([self.host], port=self.port,
372372
pkey=self.user_key)
373-
output = client.run_command('sleep .3; echo me; echo me; echo me', timeout=.2)
373+
output = client.run_command('sleep .3; echo me; echo me; echo me', read_timeout=.2)
374374
for host_out in output:
375375
self.assertRaises(Timeout, list, host_out.stdout)
376376
self.assertFalse(output[0].channel.is_eof())
@@ -412,7 +412,7 @@ def test_file_read_no_timeout(self):
412412
with open(_file, 'wb') as fh:
413413
fh.writelines(contents)
414414
try:
415-
output = self.client.run_command('cat %s' % (_file,), timeout=10)
415+
output = self.client.run_command('cat %s' % (_file,), read_timeout=10)
416416
_out = list(output[0].stdout)
417417
finally:
418418
os.unlink(_file)
@@ -439,7 +439,7 @@ def test_gssapi_auth(self):
439439
self.assertRaises(AuthenticationException, client.run_command, self.cmd)
440440

441441
def test_long_running_cmd_join_timeout(self):
442-
output = self.client.run_command('sleep 1', return_list=True)
442+
output = self.client.run_command('sleep 1')
443443
self.assertRaises(Timeout, self.client.join, output, timeout=0.2)
444444

445445
def test_default_finished(self):
@@ -459,11 +459,11 @@ def test_multiple_join_timeout(self):
459459
client = ParallelSSHClient([self.host], port=self.port,
460460
pkey=self.user_key)
461461
for _ in range(5):
462-
output = client.run_command(self.cmd, return_list=True)
462+
output = client.run_command(self.cmd)
463463
client.join(output, timeout=1, consume_output=True)
464464
for host_out in output:
465465
self.assertTrue(host_out.client.finished(host_out.channel))
466-
output = client.run_command('sleep .2', return_list=True)
466+
output = client.run_command('sleep .2')
467467
self.assertRaises(Timeout, client.join, output, timeout=.1, consume_output=True)
468468
for host_out in output:
469469
self.assertFalse(host_out.client.finished(host_out.channel))

0 commit comments

Comments
 (0)