Skip to content

Commit

Permalink
Added proxy with remote server failure test
Browse files Browse the repository at this point in the history
  • Loading branch information
pkittenis committed Feb 1, 2017
1 parent 7d3dd9f commit 495b777
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pssh/ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def exec_command(self, command, sudo=False, user=None,
channel.settimeout(self.channel_timeout)
if environment:
channel.update_environment(environment)
stdout, stderr, stdin = channel.makefile('rb'), channel.makefile_stderr('rb'), \
channel.makefile('wb')
stdout, stderr, stdin = channel.makefile('rb'), \
channel.makefile_stderr('rb'), channel.makefile('wb')
for _char in ['\\', '"', '$', '`']:
command = command.replace(_char, r'\%s' % (_char,))
shell = '$SHELL -c' if not shell else shell
Expand Down Expand Up @@ -383,7 +383,8 @@ def copy_file(self, local_file, remote_file, recurse=False,
try:
sftp.put(local_file, remote_file)
except Exception as error:
logger.error("Error occured copying file %s to remote destination %s:%s - %s",
logger.error("Error occured copying file %s to remote destination "
"%s:%s - %s",
local_file, self.host, remote_file, error)
raise error
logger.info("Copied local file %s to remote destination %s:%s",
Expand Down
17 changes: 17 additions & 0 deletions tests/test_pssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,23 @@ def test_ssh_proxy(self):
server.kill()
proxy_server.kill()

def test_ssh_proxy_target_host_failure(self):
del self.client
self.client = None
self.server.kill()
proxy_host = '127.0.0.2'
proxy_server, proxy_server_port = start_server_from_ip(proxy_host)
client = ParallelSSHClient([self.host], port=self.listen_port,
pkey=self.user_key,
proxy_host=proxy_host,
proxy_port=proxy_server_port,
)
try:
self.assertRaises(ConnectionErrorException, client.run_command, self.fake_cmd)
finally:
del client
proxy_server.kill()

def test_ssh_proxy_auth(self):
"""Test connecting to remote destination via SSH proxy
client -> proxy -> destination
Expand Down

0 comments on commit 495b777

Please sign in to comment.