Skip to content

Commit 495b777

Browse files
author
Dan
committed
Added proxy with remote server failure test
1 parent 7d3dd9f commit 495b777

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

pssh/ssh_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ def exec_command(self, command, sudo=False, user=None,
243243
channel.settimeout(self.channel_timeout)
244244
if environment:
245245
channel.update_environment(environment)
246-
stdout, stderr, stdin = channel.makefile('rb'), channel.makefile_stderr('rb'), \
247-
channel.makefile('wb')
246+
stdout, stderr, stdin = channel.makefile('rb'), \
247+
channel.makefile_stderr('rb'), channel.makefile('wb')
248248
for _char in ['\\', '"', '$', '`']:
249249
command = command.replace(_char, r'\%s' % (_char,))
250250
shell = '$SHELL -c' if not shell else shell
@@ -383,7 +383,8 @@ def copy_file(self, local_file, remote_file, recurse=False,
383383
try:
384384
sftp.put(local_file, remote_file)
385385
except Exception as error:
386-
logger.error("Error occured copying file %s to remote destination %s:%s - %s",
386+
logger.error("Error occured copying file %s to remote destination "
387+
"%s:%s - %s",
387388
local_file, self.host, remote_file, error)
388389
raise error
389390
logger.info("Copied local file %s to remote destination %s:%s",

tests/test_pssh_client.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,23 @@ def test_ssh_proxy(self):
577577
server.kill()
578578
proxy_server.kill()
579579

580+
def test_ssh_proxy_target_host_failure(self):
581+
del self.client
582+
self.client = None
583+
self.server.kill()
584+
proxy_host = '127.0.0.2'
585+
proxy_server, proxy_server_port = start_server_from_ip(proxy_host)
586+
client = ParallelSSHClient([self.host], port=self.listen_port,
587+
pkey=self.user_key,
588+
proxy_host=proxy_host,
589+
proxy_port=proxy_server_port,
590+
)
591+
try:
592+
self.assertRaises(ConnectionErrorException, client.run_command, self.fake_cmd)
593+
finally:
594+
del client
595+
proxy_server.kill()
596+
580597
def test_ssh_proxy_auth(self):
581598
"""Test connecting to remote destination via SSH proxy
582599
client -> proxy -> destination

0 commit comments

Comments
 (0)