Skip to content

Commit b53749f

Browse files
author
Dan
committed
Removed deprecated API endpoints. Resolves #73
1 parent 8260638 commit b53749f

File tree

2 files changed

+9
-120
lines changed

2 files changed

+9
-120
lines changed

pssh/pssh_client.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -594,22 +594,6 @@ def run_command(self, *args, **kwargs):
594594
raise
595595
return output
596596

597-
def exec_command(self, *args, **kwargs):
598-
"""Run command on all hosts in parallel, honoring `self.pool_size`
599-
600-
**Deprecated by** :mod:`pssh.pssh_client.ParallelSSHClient.run_command`
601-
602-
:param args: Position arguments for command
603-
:type args: tuple
604-
:param kwargs: Keyword arguments for command
605-
:type kwargs: dict
606-
607-
:rtype: List of :mod:`gevent.Greenlet`"""
608-
warnings.warn("This method is being deprecated and will be removed in \
609-
future releases - use self.run_command instead", DeprecationWarning)
610-
return [self.pool.spawn(self._exec_command, host, *args, **kwargs)
611-
for host in self.hosts]
612-
613597
def _get_host_config_values(self, host):
614598
_user = self.host_config.get(host, {}).get('user', self.user)
615599
_port = self.host_config.get(host, {}).get('port', self.port)
@@ -767,47 +751,6 @@ def _get_exit_code(self, channel):
767751
channel.close()
768752
return channel.recv_exit_status()
769753

770-
def get_stdout(self, greenlet, return_buffers=False):
771-
"""Get/print stdout from greenlet and return exit code for host
772-
773-
**Deprecated** - use :mod:`pssh.pssh_client.ParallelSSHClient.get_output` instead.
774-
775-
:param greenlet: Greenlet object containing an \
776-
SSH channel reference, hostname, stdout and stderr buffers
777-
:type greenlet: :mod:`gevent.Greenlet`
778-
:param return_buffers: Flag to turn on returning stdout and stderr \
779-
buffers along with exit code. Defaults to off.
780-
:type return_buffers: bool
781-
:rtype: Dictionary containing ``{host: {'exit_code': exit code}}`` entry \
782-
for example ``{'myhost1': {'exit_code': 0}}``
783-
:rtype: With ``return_buffers=True``: ``{'myhost1': {'exit_code': 0,
784-
'channel' : None or SSH channel of command if command is still executing,
785-
'stdout' : <iterable>,
786-
'stderr' : <iterable>,}}``
787-
"""
788-
warnings.warn("This method is being deprecated and will be removed in"
789-
"future releases - use self.get_output instead", DeprecationWarning)
790-
gevent.sleep(.2)
791-
channel, host, stdout, stderr, stdin = greenlet.get()
792-
if channel.exit_status_ready():
793-
channel.close()
794-
else:
795-
logger.debug("Command still executing on get_stdout call - not closing channel and returning None as exit code.")
796-
# If channel is not closed we cannot get full stdout/stderr so must return buffers
797-
return_buffers = True
798-
# Channel must be closed or reading stdout/stderr will block forever
799-
if not return_buffers and channel.closed:
800-
for _ in stdout:
801-
pass
802-
for _ in stderr:
803-
pass
804-
return {host: {'exit_code': channel.recv_exit_status(),}}
805-
gevent.sleep(.2)
806-
return {host: {'exit_code': channel.recv_exit_status() if channel.exit_status_ready() else None,
807-
'channel' : channel if not channel.closed else None,
808-
'stdout' : stdout,
809-
'stderr' : stderr, }}
810-
811754
def copy_file(self, local_file, remote_file, recurse=False):
812755
"""Copy local file to remote file in parallel
813756

tests/test_pssh_client.py

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@ def tearDown(self):
6868
del self.listen_socket
6969
del self.client
7070

71-
def test_pssh_client_exec_command(self):
72-
cmd = self.client.exec_command(self.fake_cmd)[0]
73-
output = self.client.get_stdout(cmd)
74-
self.assertTrue(self.host in output,
75-
msg="No output for host")
76-
self.assertTrue(output[self.host]['exit_code'] == 0)
77-
7871
def test_pssh_client_no_stdout_non_zero_exit_code_immediate_exit(self):
7972
output = self.client.run_command('exit 1')
8073
expected_exit_code = 1
@@ -85,31 +78,6 @@ def test_pssh_client_no_stdout_non_zero_exit_code_immediate_exit(self):
8578
(exit_code,
8679
expected_exit_code,))
8780

88-
def test_pssh_client_exec_command_get_buffers(self):
89-
client = ParallelSSHClient([self.host], port=self.listen_port,
90-
pkey=self.user_key,
91-
agent=self.agent)
92-
cmd = client.exec_command(self.fake_cmd)[0]
93-
output = client.get_stdout(cmd, return_buffers=True)
94-
expected_exit_code = 0
95-
expected_stdout = [self.fake_resp]
96-
expected_stderr = []
97-
exit_code = output[self.host]['exit_code']
98-
stdout = list(output[self.host]['stdout'])
99-
stderr = list(output[self.host]['stderr'])
100-
self.assertEqual(expected_exit_code, exit_code,
101-
msg="Got unexpected exit code - %s, expected %s" %
102-
(exit_code,
103-
expected_exit_code,))
104-
self.assertEqual(expected_stdout, stdout,
105-
msg="Got unexpected stdout - %s, expected %s" %
106-
(stdout,
107-
expected_stdout,))
108-
self.assertEqual(expected_stderr, stderr,
109-
msg="Got unexpected stderr - %s, expected %s" %
110-
(stderr,
111-
expected_stderr,))
112-
11381
def test_pssh_client_run_command_get_output(self):
11482
client = ParallelSSHClient([self.host], port=self.listen_port,
11583
pkey=self.user_key,
@@ -175,21 +143,15 @@ def test_pssh_client_run_long_command(self):
175143
del client
176144

177145
def test_pssh_client_auth_failure(self):
178-
listen_socket = make_socket(self.host)
179-
listen_port = listen_socket.getsockname()[1]
180-
server = start_server(listen_socket, fail_auth=True)
146+
self.server.kill()
147+
server_socket = make_socket(self.host)
148+
listen_port = server_socket.getsockname()[1]
149+
server = start_server(server_socket, fail_auth=True)
181150
client = ParallelSSHClient([self.host], port=listen_port,
182151
pkey=self.user_key,
183152
agent=self.agent)
184-
cmd = client.exec_command(self.fake_cmd)[0]
185-
# Handle exception
186-
try:
187-
cmd.get()
188-
raise Exception("Expected AuthenticationException, got none")
189-
except AuthenticationException:
190-
pass
153+
self.assertRaises(AuthenticationException, client.run_command, self.fake_cmd)
191154
del client
192-
server.kill()
193155

194156
def test_pssh_client_hosts_list_part_failure(self):
195157
"""Test getting output for remainder of host list in the case where one
@@ -238,6 +200,7 @@ def test_pssh_client_ssh_exception(self):
238200
server.kill()
239201

240202
def test_pssh_client_timeout(self):
203+
self.server.kill()
241204
listen_socket = make_socket(self.host)
242205
listen_port = listen_socket.getsockname()[1]
243206
server_timeout=0.2
@@ -258,40 +221,23 @@ def test_pssh_client_timeout(self):
258221
raise server.exception
259222
except gevent.Timeout:
260223
pass
261-
# chan_timeout = output[self.host]['channel'].gettimeout()
262-
# self.assertEqual(client_timeout, chan_timeout,
263-
# msg="Channel timeout %s does not match requested timeout %s" %(
264-
# chan_timeout, client_timeout,))
265224
del client
266225
server.kill()
267226

268-
def test_pssh_client_exec_command_password(self):
227+
def test_pssh_client_run_command_password(self):
269228
"""Test password authentication. Embedded server accepts any password
270229
even empty string"""
271230
client = ParallelSSHClient([self.host], port=self.listen_port,
272231
password='')
273-
cmd = client.exec_command(self.fake_cmd)[0]
274-
output = client.get_stdout(cmd)
232+
output = client.run_command(self.fake_cmd)
233+
client.join(output)
275234
self.assertTrue(self.host in output,
276235
msg="No output for host")
277236
self.assertTrue(output[self.host]['exit_code'] == 0,
278237
msg="Expected exit code 0, got %s" % (
279238
output[self.host]['exit_code'],))
280239
del client
281240

282-
def test_pssh_client_long_running_command(self):
283-
expected_lines = 5
284-
client = ParallelSSHClient([self.host], port=self.listen_port,
285-
pkey=self.user_key)
286-
cmd = client.exec_command(self.long_cmd(expected_lines))[0]
287-
output = client.get_stdout(cmd, return_buffers=True)
288-
self.assertTrue(self.host in output, msg="Got no output for command")
289-
stdout = list(output[self.host]['stdout'])
290-
self.assertTrue(len(stdout) == expected_lines,
291-
msg="Expected %s lines of response, got %s" % (
292-
expected_lines, len(stdout)))
293-
del client
294-
295241
def test_pssh_client_long_running_command_exit_codes(self):
296242
expected_lines = 5
297243
client = ParallelSSHClient([self.host], port=self.listen_port,

0 commit comments

Comments
 (0)