Skip to content

Commit 37323ab

Browse files
author
vshepard
committed
Update establish_ssh_tunnel
1 parent fffb23c commit 37323ab

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Diff for: testgres/operations/remote_ops.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ def is_port_open(host, port):
7676
except socket.error:
7777
return False
7878

79-
def establish_ssh_tunnel(self, local_port, remote_port):
79+
def establish_ssh_tunnel(self, local_port, remote_port, host):
8080
"""
8181
Establish an SSH tunnel from a local port to a remote PostgreSQL port.
8282
"""
83-
ssh_cmd = ['-N', '-L', f"{local_port}:localhost:{remote_port}"]
83+
if host != 'localhost':
84+
ssh_cmd = ['-N', '-L', f"localhost:{local_port}:{host}:{remote_port}"]
85+
else:
86+
ssh_cmd = ['-N', '-L', f"{local_port}:{host}:{remote_port}"]
8487
self.tunnel_process = self.exec_command(ssh_cmd, get_process=True, timeout=300)
8588
timeout = 10
8689
start_time = time.time()
@@ -412,10 +415,10 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
412415
"""
413416
local_port = reserve_port()
414417
self.tunnel_port = local_port
415-
self.establish_ssh_tunnel(local_port=local_port, remote_port=port)
418+
self.establish_ssh_tunnel(local_port=local_port, remote_port=port, host=host)
416419
try:
417420
conn = pglib.connect(
418-
host=host,
421+
host='localhost',
419422
port=local_port,
420423
database=dbname,
421424
user=user,

0 commit comments

Comments
 (0)