Skip to content

Commit 50f5665

Browse files
author
Dan
committed
Added test for getting non zero exit code with no stdout. Fixed issue where lack of stdout would cause pssh client to hang
1 parent 9c2b36f commit 50f5665

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pssh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ def exec_command(self, command, sudo=False, user=None, **kwargs):
246246
logger.debug("Running command %s on %s", command, self.host)
247247
channel.exec_command(command, **kwargs)
248248
logger.debug("Command started")
249-
while not (channel.recv_ready() or channel.closed):
249+
while not (channel.recv_ready() or channel.closed or
250+
channel.exit_status_ready()):
250251
gevent.sleep(.2)
251252
return channel, self.host, stdout, stderr
252253

tests/test_pssh_client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,22 @@ def test_pssh_client_exec_command(self):
7171
client.pool.join()
7272
output = client.get_stdout(cmd)
7373
expected = {'127.0.0.1' : {'exit_code' : 0}}
74-
self.assertEqual(output, expected,
74+
self.assertEqual(expected, output,
7575
msg="Got unexpected command output - %s" % (output,))
7676
self.assertTrue(output['127.0.0.1']['exit_code'] == 0)
7777

78+
def test_pssh_client_no_stdout_non_zero_exit_code(self):
79+
client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
80+
pkey=self.user_key)
81+
output = client.run_command('exit 1')
82+
expected_exit_code = 1
83+
exit_code = output['127.0.0.1']['exit_code']
84+
client.pool.join()
85+
self.assertEqual(expected_exit_code, exit_code,
86+
msg="Got unexpected exit code - %s, expected %s" %
87+
(exit_code,
88+
expected_exit_code,))
89+
7890
def test_pssh_client_exec_command_get_buffers(self):
7991
client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
8092
pkey=self.user_key)

0 commit comments

Comments
 (0)