Skip to content

Commit 4f5e23c

Browse files
author
vshepard
committed
Update establish_ssh_tunnel
1 parent 013b359 commit 4f5e23c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

testgres/operations/remote_ops.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def is_port_open(host, port):
7474
except socket.error:
7575
return False
7676

77-
def establish_ssh_tunnel(self, local_port, remote_port):
77+
def establish_ssh_tunnel(self, local_port, remote_port, host='localhost'):
7878
"""
7979
Establish an SSH tunnel from a local port to a remote PostgreSQL port.
8080
"""
81-
ssh_cmd = ['-N', '-L', f"{local_port}:localhost:{remote_port}"]
81+
ssh_cmd = ['-N', '-L', f"{local_port}:{host}:{remote_port}"]
8282
self.tunnel_process = self.exec_command(ssh_cmd, get_process=True, timeout=300)
8383
timeout = 10
8484
start_time = time.time()
@@ -410,7 +410,7 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
410410
"""
411411
local_port = reserve_port()
412412
self.tunnel_port = local_port
413-
self.establish_ssh_tunnel(local_port=local_port, remote_port=port)
413+
self.establish_ssh_tunnel(local_port=local_port, remote_port=port, host=host)
414414
try:
415415
conn = pglib.connect(
416416
host=host,
@@ -423,8 +423,8 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
423423
print("Database connection established successfully.")
424424
return conn
425425
except Exception as e:
426-
print(f"Error connecting to the database: {str(e)}")
426+
print(f"!!!Error connecting to the database: {str(e)}")
427427
if self.tunnel_process:
428428
self.tunnel_process.terminate()
429-
print("SSH tunnel closed due to connection failure.")
429+
print("!!!SSH tunnel closed due to connection failure.")
430430
raise

0 commit comments

Comments
 (0)