Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c079c8

Browse files
committed
Merge default-ssh-user into multihost-catchup
2 parents d4685c6 + 00f7fd5 commit 2c079c8

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

testgres/operations/remote_ops.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def __init__(self, conn_params: ConnectionParams):
4646
self.host = conn_params.host
4747
self.ssh_key = conn_params.ssh_key
4848
self.port = conn_params.port
49-
self.ssh_cmd = ["-o StrictHostKeyChecking=no"]
49+
self.ssh_args = []
5050
if self.ssh_key:
51-
self.ssh_cmd += ["-i", self.ssh_key]
51+
self.ssh_args += ["-i", self.ssh_key]
5252
if self.port:
53-
self.ssh_cmd += ["-p", self.port]
53+
self.ssh_args += ["-p", self.port]
5454
self.remote = True
5555
self.username = conn_params.username
5656
self.ssh_dest = f"{self.username}@{self.host}" if self.username else self.host
@@ -93,9 +93,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
9393
"""
9494
ssh_cmd = []
9595
if isinstance(cmd, str):
96-
ssh_cmd = ['ssh', self.ssh_dest] + self.ssh_cmd + [cmd]
96+
ssh_cmd = ['ssh'] + self.ssh_args + [self.ssh_dest + cmd]
9797
elif isinstance(cmd, list):
98-
ssh_cmd = ['ssh', self.ssh_dest] + self.ssh_cmd + cmd
98+
ssh_cmd = ['ssh'] + self.ssh_args + [self.ssh_dest] + cmd
9999
process = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
100100
if get_process:
101101
return process
@@ -240,9 +240,9 @@ def mkdtemp(self, prefix=None):
240240
- prefix (str): The prefix of the temporary directory name.
241241
"""
242242
if prefix:
243-
command = ["ssh"] + self.ssh_cmd + [self.ssh_dest, f"mktemp -d {prefix}XXXXX"]
243+
command = ["ssh"] + self.ssh_args + [self.ssh_dest, f"mktemp -d {prefix}XXXXX"]
244244
else:
245-
command = ["ssh"] + self.ssh_cmd + [self.ssh_dest, "mktemp -d"]
245+
command = ["ssh"] + self.ssh_args + [self.ssh_dest, "mktemp -d"]
246246

247247
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
248248

@@ -289,7 +289,7 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
289289
scp_ssh_cmd = ['-P' if x == '-p' else x for x in self.ssh_cmd]
290290

291291
if not truncate:
292-
scp_cmd = ['scp'] + self.ssh_cmd + [f"{self.ssh_dest}:{filename}", tmp_file.name]
292+
scp_cmd = ['scp'] + self.ssh_args + [f"{self.ssh_dest}:{filename}", tmp_file.name]
293293
subprocess.run(scp_cmd, check=False) # The file might not exist yet
294294
tmp_file.seek(0, os.SEEK_END)
295295

@@ -305,11 +305,11 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
305305
tmp_file.write(data)
306306

307307
tmp_file.flush()
308-
scp_cmd = ['scp'] + self.ssh_cmd + [tmp_file.name, f"{self.ssh_dest}:{filename}"]
308+
scp_cmd = ['scp'] + self.ssh_args + [tmp_file.name, f"{self.ssh_dest}:{filename}"]
309309
subprocess.run(scp_cmd, check=True)
310310

311311
remote_directory = os.path.dirname(filename)
312-
mkdir_cmd = ['ssh'] + self.ssh_cmd + [self.ssh_dest, f"mkdir -p {remote_directory}"]
312+
mkdir_cmd = ['ssh'] + self.ssh_args + [self.ssh_dest, f"mkdir -p {remote_directory}"]
313313
subprocess.run(mkdir_cmd, check=True)
314314

315315
os.remove(tmp_file.name)
@@ -374,7 +374,7 @@ def get_pid(self):
374374
return int(self.exec_command("echo $$", encoding=get_default_encoding()))
375375

376376
def get_process_children(self, pid):
377-
command = ["ssh"] + self.ssh_cmd + [self.ssh_dest, f"pgrep -P {pid}"]
377+
command = ["ssh"] + self.ssh_args + [self.ssh_dest, f"pgrep -P {pid}"]
378378

379379
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
380380

0 commit comments

Comments
 (0)