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

Commita128b12

Browse files
authored
Remove SSH tunnel (#136)
1 parent4543f80 commita128b12

File tree

4 files changed

+37
-54
lines changed

4 files changed

+37
-54
lines changed

‎testgres/node.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,9 @@ def get_auth_method(t):
528528
u"host\treplication\tall\t127.0.0.1/32\t{}\n".format(auth_host),
529529
u"host\treplication\tall\t::1/128\t\t{}\n".format(auth_host),
530530
u"host\treplication\tall\t{}/24\t\t{}\n".format(subnet_base,auth_host),
531-
u"host\tall\tall\t{}/24\t\t{}\n".format(subnet_base,auth_host)
531+
u"host\tall\tall\t{}/24\t\t{}\n".format(subnet_base,auth_host),
532+
u"host\tall\tall\tall\t{}\n".format(auth_host),
533+
u"host\treplication\tall\tall\t{}\n".format(auth_host)
532534
]# yapf: disable
533535

534536
# write missing lines
@@ -1671,9 +1673,15 @@ def _get_bin_path(self, filename):
16711673

16721674
classNodeApp:
16731675

1674-
def__init__(self,test_path,nodes_to_cleanup,os_ops=LocalOperations()):
1675-
self.test_path=test_path
1676-
self.nodes_to_cleanup=nodes_to_cleanup
1676+
def__init__(self,test_path=None,nodes_to_cleanup=None,os_ops=LocalOperations()):
1677+
iftest_path:
1678+
ifos.path.isabs(test_path):
1679+
self.test_path=test_path
1680+
else:
1681+
self.test_path=os.path.join(os_ops.cwd(),test_path)
1682+
else:
1683+
self.test_path=os_ops.cwd()
1684+
self.nodes_to_cleanup=nodes_to_cleanupifnodes_to_cleanupelse []
16771685
self.os_ops=os_ops
16781686

16791687
defmake_empty(

‎testgres/operations/os_ops.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
importgetpass
12
importlocale
3+
importsys
24

35
try:
46
importpsycopg2aspglib# noqa: F401
@@ -24,7 +26,7 @@ def get_default_encoding():
2426
classOsOperations:
2527
def__init__(self,username=None):
2628
self.ssh_key=None
27-
self.username=username
29+
self.username=usernameorgetpass.getuser()
2830

2931
# Command execution
3032
defexec_command(self,cmd,**kwargs):
@@ -34,6 +36,13 @@ def exec_command(self, cmd, **kwargs):
3436
defenviron(self,var_name):
3537
raiseNotImplementedError()
3638

39+
defcwd(self):
40+
ifsys.platform=='linux':
41+
cmd='pwd'
42+
elifsys.platform=='win32':
43+
cmd='cd'
44+
returnself.exec_command(cmd).decode().rstrip()
45+
3746
deffind_executable(self,executable):
3847
raiseNotImplementedError()
3948

‎testgres/operations/remote_ops.py

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
importgetpass
22
importos
3-
importlogging
43
importplatform
54
importsubprocess
65
importtempfile
@@ -55,40 +54,10 @@ def __init__(self, conn_params: ConnectionParams):
5554
self.remote=True
5655
self.username=conn_params.usernameorgetpass.getuser()
5756
self.ssh_dest=f"{self.username}@{self.host}"ifconn_params.usernameelseself.host
58-
self.add_known_host(self.host)
59-
self.tunnel_process=None
6057

6158
def__enter__(self):
6259
returnself
6360

64-
def__exit__(self,exc_type,exc_val,exc_tb):
65-
self.close_ssh_tunnel()
66-
67-
defestablish_ssh_tunnel(self,local_port,remote_port):
68-
"""
69-
Establish an SSH tunnel from a local port to a remote PostgreSQL port.
70-
"""
71-
ssh_cmd= ['-N','-L',f"{local_port}:localhost:{remote_port}"]
72-
self.tunnel_process=self.exec_command(ssh_cmd,get_process=True,timeout=300)
73-
74-
defclose_ssh_tunnel(self):
75-
ifhasattr(self,'tunnel_process'):
76-
self.tunnel_process.terminate()
77-
self.tunnel_process.wait()
78-
delself.tunnel_process
79-
else:
80-
print("No active tunnel to close.")
81-
82-
defadd_known_host(self,host):
83-
known_hosts_path=os.path.expanduser("~/.ssh/known_hosts")
84-
cmd='ssh-keyscan -H %s >> %s'% (host,known_hosts_path)
85-
86-
try:
87-
subprocess.check_call(cmd,shell=True)
88-
logging.info("Successfully added %s to known_hosts."%host)
89-
exceptsubprocess.CalledProcessErrorase:
90-
raiseException("Failed to add %s to known_hosts. Error: %s"% (host,str(e)))
91-
9261
defexec_command(self,cmd,wait_exit=False,verbose=False,expect_error=False,
9362
encoding=None,shell=True,text=False,input=None,stdin=None,stdout=None,
9463
stderr=None,get_process=None,timeout=None):
@@ -293,6 +262,7 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
293262
withtempfile.NamedTemporaryFile(mode=mode,delete=False)astmp_file:
294263
# For scp the port is specified by a "-P" option
295264
scp_args= ['-P'ifx=='-p'elsexforxinself.ssh_args]
265+
296266
ifnottruncate:
297267
scp_cmd= ['scp']+scp_args+ [f"{self.ssh_dest}:{filename}",tmp_file.name]
298268
subprocess.run(scp_cmd,check=False)# The file might not exist yet
@@ -391,18 +361,11 @@ def get_process_children(self, pid):
391361

392362
# Database control
393363
defdb_connect(self,dbname,user,password=None,host="localhost",port=5432):
394-
"""
395-
Established SSH tunnel and Connects to a PostgreSQL
396-
"""
397-
self.establish_ssh_tunnel(local_port=port,remote_port=5432)
398-
try:
399-
conn=pglib.connect(
400-
host=host,
401-
port=port,
402-
database=dbname,
403-
user=user,
404-
password=password,
405-
)
406-
returnconn
407-
exceptExceptionase:
408-
raiseException(f"Could not connect to the database. Error:{e}")
364+
conn=pglib.connect(
365+
host=host,
366+
port=port,
367+
database=dbname,
368+
user=user,
369+
password=password,
370+
)
371+
returnconn

‎testgres/plugins/pg_probackup2/pg_probackup2/app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ def __str__(self):
4343
classProbackupApp:
4444

4545
def__init__(self,test_class:unittest.TestCase,
46-
pg_node,pb_log_path,test_env,auto_compress_alg,backup_dir):
46+
pg_node,pb_log_path,test_env,auto_compress_alg,backup_dir,probackup_path=None):
4747
self.test_class=test_class
4848
self.pg_node=pg_node
4949
self.pb_log_path=pb_log_path
5050
self.test_env=test_env
5151
self.auto_compress_alg=auto_compress_alg
5252
self.backup_dir=backup_dir
53-
self.probackup_path=init_params.probackup_path
53+
self.probackup_path=probackup_pathorinit_params.probackup_path
5454
self.probackup_old_path=init_params.probackup_old_path
5555
self.remote=init_params.remote
5656
self.verbose=init_params.verbose
@@ -388,6 +388,7 @@ def catchup_node(
388388
backup_mode,source_pgdata,destination_node,
389389
options=None,
390390
remote_host='localhost',
391+
remote_port=None,
391392
expect_error=False,
392393
gdb=False
393394
):
@@ -401,7 +402,9 @@ def catchup_node(
401402
'--destination-pgdata={0}'.format(destination_node.data_dir)
402403
]
403404
ifself.remote:
404-
cmd_list+= ['--remote-proto=ssh','--remote-host=%s'%remote_host]
405+
cmd_list+= ['--remote-proto=ssh',f'--remote-host={remote_host}']
406+
ifremote_port:
407+
cmd_list.append(f'--remote-port={remote_port}')
405408
ifself.verbose:
406409
cmd_list+= [
407410
'--log-level-file=VERBOSE',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp