Skip to content

Commit 9c263a0

Browse files
author
Dan
committed
Added unit test for running cmd without shell. Updated documentation. More sleeps to avoid race condition in proxy test
1 parent 9fdf8cf commit 9c263a0

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

pssh/pssh_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ def run_command(self, *args, **kwargs):
249249
Defaults to True. With stop_on_errors set to False, exceptions are instead \
250250
added to output of `run_command`. See example usage below.
251251
:type stop_on_errors: bool
252-
:param kwargs: Keyword arguments for command
253-
:type kwargs: dict
252+
:param use_shell: (Optional) Run command with or without shell. Defaults \
253+
to True - use shell defined in user login to run command string
254+
:type use_shell: bool
254255
:rtype: Dictionary with host as key as per \
255256
:mod:`pssh.pssh_client.ParallelSSHClient.get_output`
256257

tests/test_pssh_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ def test_ssh_proxy(self):
472472
proxy_server_socket = make_socket('127.0.0.2')
473473
proxy_server_port = proxy_server_socket.getsockname()[1]
474474
proxy_server = start_server(proxy_server_socket)
475+
gevent.sleep(2)
475476
client = ParallelSSHClient([self.host], port=self.listen_port,
476477
pkey=self.user_key,
477478
proxy_host='127.0.0.2',

tests/test_ssh_client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,30 @@ def test_ssh_client_pty(self):
247247
del channel
248248
del client
249249

250+
def test_ssh_client_pty(self):
251+
"""Test that running command sans shell works as expected
252+
and that shell commands fail accordingly"""
253+
client = SSHClient(self.host, port=self.listen_port,
254+
pkey=self.user_key)
255+
channel, host, stdout, stderr = client.exec_command(self.fake_cmd, use_shell=False)
256+
output = list(stdout)
257+
stderr = list(stderr)
258+
expected = []
259+
exit_code = channel.recv_exit_status()
260+
self.assertEqual(expected, output,
261+
msg = "Got unexpected command output - %s" % (output,))
262+
self.assertTrue(exit_code==127,
263+
msg="Expected cmd not found error code 127, got %s instead" % (
264+
exit_code,))
265+
channel, host, stdout, stderr = client.exec_command('id', use_shell=False)
266+
output = list(stdout)
267+
exit_code = channel.recv_exit_status()
268+
self.assertTrue(output,
269+
msg="Got no output from cmd executed without shell")
270+
self.assertTrue(exit_code==0,
271+
msg="Cmd executed with shell failed with error code %s" % (
272+
exit_code,))
273+
del client
274+
250275
if __name__ == '__main__':
251276
unittest.main()

0 commit comments

Comments
 (0)