Skip to content

Commit 94215a2

Browse files
committed
Merge branch 'master' into multihost-catchup
2 parents 5707835 + 4543f80 commit 94215a2

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

testgres/node.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def __init__(self, name=None, base_dir=None, port=None, conn_params: ConnectionP
157157

158158
self.host = self.os_ops.host
159159
self.port = port or reserve_port()
160+
160161
self.ssh_key = self.os_ops.ssh_key
161162

162163
# defaults for __exit__()

testgres/operations/remote_ops.py

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import getpass
22
import os
3-
import socket
3+
import logging
4+
import platform
45
import subprocess
56
import tempfile
6-
import platform
77

88
# we support both pg8000 and psycopg2
99
try:
@@ -55,35 +55,10 @@ def __init__(self, conn_params: ConnectionParams):
5555
self.remote = True
5656
self.username = conn_params.username or getpass.getuser()
5757
self.ssh_dest = f"{self.username}@{self.host}" if conn_params.username else self.host
58-
#self.add_known_host(self.host)
59-
self.tunnel_process = None
60-
self.tunnel_port = None
6158

6259
def __enter__(self):
6360
return self
6461

65-
def __exit__(self, exc_type, exc_val, exc_tb):
66-
self.close_ssh_tunnel()
67-
68-
@staticmethod
69-
def is_port_open(host, port):
70-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
71-
sock.settimeout(1) # Таймаут для попытки соединения
72-
try:
73-
sock.connect((host, port))
74-
return True
75-
except socket.error:
76-
return False
77-
78-
def close_ssh_tunnel(self):
79-
if self.tunnel_process:
80-
self.tunnel_process.terminate()
81-
self.tunnel_process.wait()
82-
print("SSH tunnel closed.")
83-
del self.tunnel_process
84-
else:
85-
print("No active tunnel to close.")
86-
8762
def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
8863
encoding=None, shell=True, text=False, input=None, stdin=None, stdout=None,
8964
stderr=None, get_process=None, timeout=None):
@@ -94,9 +69,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
9469
"""
9570
ssh_cmd = []
9671
if isinstance(cmd, str):
97-
ssh_cmd = ['ssh'] + self.ssh_args + [self.ssh_dest, cmd]
72+
ssh_cmd = ['ssh', self.ssh_dest] + self.ssh_args + [cmd]
9873
elif isinstance(cmd, list):
99-
ssh_cmd = ['ssh'] + self.ssh_args + [self.ssh_dest] + cmd
74+
ssh_cmd = ['ssh', self.ssh_dest] + self.ssh_args + cmd
10075
process = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
10176
if get_process:
10277
return process

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy