Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2621724

Browse files
committed
Do not use a tunnel
1 parent0611d10 commit2621724

File tree

1 file changed

+8
-44
lines changed

1 file changed

+8
-44
lines changed

‎testgres/operations/remote_ops.py

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
importplatform
66
importtime
77

8-
from ..utilsimportreserve_port
9-
108
# we support both pg8000 and psycopg2
119
try:
1210
importpsycopg2aspglib
@@ -17,7 +15,6 @@
1715
raiseImportError("You must have psycopg2 or pg8000 modules installed")
1816

1917
from ..exceptionsimportExecUtilException
20-
from ..utilsimportreserve_port
2118
from .os_opsimportOsOperations,ConnectionParams,get_default_encoding
2219

2320
error_markers= [b'error',b'Permission denied',b'fatal',b'No such file or directory']
@@ -76,24 +73,6 @@ def is_port_open(host, port):
7673
exceptsocket.error:
7774
returnFalse
7875

79-
defestablish_ssh_tunnel(self,local_port,remote_port,host):
80-
"""
81-
Establish an SSH tunnel from a local port to a remote PostgreSQL port.
82-
"""
83-
ifhost!='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}"]
87-
self.tunnel_process=self.exec_command(ssh_cmd,get_process=True,timeout=300)
88-
timeout=10
89-
start_time=time.time()
90-
whiletime.time()-start_time<timeout:
91-
ifself.is_port_open('localhost',local_port):
92-
print("SSH tunnel established.")
93-
return
94-
time.sleep(0.5)
95-
raiseException("Failed to establish SSH tunnel within the timeout period.")
96-
9776
defclose_ssh_tunnel(self):
9877
ifself.tunnel_process:
9978
self.tunnel_process.terminate()
@@ -410,26 +389,11 @@ def get_process_children(self, pid):
410389

411390
# Database control
412391
defdb_connect(self,dbname,user,password=None,host="localhost",port=5432):
413-
"""
414-
Establish SSH tunnel and connect to a PostgreSQL database.
415-
"""
416-
local_port=reserve_port()
417-
self.tunnel_port=local_port
418-
self.establish_ssh_tunnel(local_port=local_port,remote_port=port,host=host)
419-
try:
420-
conn=pglib.connect(
421-
host='localhost',
422-
port=local_port,
423-
database=dbname,
424-
user=user,
425-
password=password,
426-
timeout=10
427-
)
428-
print("Database connection established successfully.")
429-
returnconn
430-
exceptExceptionase:
431-
print(f"Error connecting to the database:{str(e)}")
432-
ifself.tunnel_process:
433-
self.tunnel_process.terminate()
434-
print("SSH tunnel closed due to connection failure.")
435-
raise
392+
conn=pglib.connect(
393+
host=host,
394+
port=port,
395+
database=dbname,
396+
user=user,
397+
password=password,
398+
)
399+
returnconn

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp