Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3f9c618

Browse files
committed
Merge with master
2 parents 0611d10 + 7847380 commit 3f9c618

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

testgres/node.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ def set_auto_conf(self, options, config='postgresql.auto.conf', rm_options={}):
16411641

16421642
self.os_ops.write(path, auto_conf, truncate=True)
16431643

1644-
def upgrade_from(self, old_node):
1644+
def upgrade_from(self, old_node, options=None):
16451645
"""
16461646
Upgrade this node from an old node using pg_upgrade.
16471647
@@ -1654,6 +1654,9 @@ def upgrade_from(self, old_node):
16541654
if not os.path.exists(self.data_dir):
16551655
self.init()
16561656

1657+
if not options:
1658+
options = []
1659+
16571660
pg_upgrade_binary = self._get_bin_path("pg_upgrade")
16581661

16591662
if not os.path.exists(pg_upgrade_binary):
@@ -1668,6 +1671,7 @@ def upgrade_from(self, old_node):
16681671
"--old-port", str(old_node.port),
16691672
"--new-port", str(self.port),
16701673
]
1674+
upgrade_command += options
16711675

16721676
return self.os_ops.exec_command(upgrade_command)
16731677

testgres/operations/remote_ops.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ def __init__(self, conn_params: ConnectionParams):
4848
super().__init__(conn_params.username)
4949
self.conn_params = conn_params
5050
self.host = conn_params.host
51-
self.ssh_key = conn_params.ssh_key
5251
self.port = conn_params.port
52+
self.ssh_key = conn_params.ssh_key
5353
self.ssh_cmd = ["-o StrictHostKeyChecking=no"]
54+
self.ssh_args = []
5455
if self.ssh_key:
55-
self.ssh_cmd += ["-i", self.ssh_key]
56+
self.ssh_args += ["-i", self.ssh_key]
5657
if self.port:
57-
self.ssh_cmd += ["-p", self.port]
58+
self.ssh_args += ["-p", self.port]
5859
self.remote = True
5960
self.username = conn_params.username or self.get_user()
6061
self.tunnel_process = None
@@ -113,9 +114,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
113114
"""
114115
ssh_cmd = []
115116
if isinstance(cmd, str):
116-
ssh_cmd = ['ssh', f"{self.username}@{self.host}"] + self.ssh_cmd + [cmd]
117+
ssh_cmd = ['ssh', f"{self.username}@{self.host}"] + self.ssh_args + [cmd]
117118
elif isinstance(cmd, list):
118-
ssh_cmd = ['ssh', f"{self.username}@{self.host}"] + self.ssh_cmd + cmd
119+
ssh_cmd = ['ssh', f"{self.username}@{self.host}"] + self.ssh_args + cmd
119120
process = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
120121
if get_process:
121122
return process
@@ -264,9 +265,9 @@ def mkdtemp(self, prefix=None):
264265
- prefix (str): The prefix of the temporary directory name.
265266
"""
266267
if prefix:
267-
command = ["ssh" + f"{self.username}@{self.host}"] + self.ssh_cmd + [f"mktemp -d {prefix}XXXXX"]
268+
command = ["ssh"] + self.ssh_args + [f"{self.username}@{self.host}", f"mktemp -d {prefix}XXXXX"]
268269
else:
269-
command = ["ssh", f"{self.username}@{self.host}"] + self.ssh_cmd + ["mktemp -d"]
270+
command = ["ssh"] + self.ssh_args + [f"{self.username}@{self.host}", "mktemp -d"]
270271

271272
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
272273

@@ -309,11 +310,11 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
309310
mode = "r+b" if binary else "r+"
310311

311312
with tempfile.NamedTemporaryFile(mode=mode, delete=False) as tmp_file:
312-
# Because in scp we set up port using -P option
313-
scp_ssh_cmd = ['-P' if x == '-p' else x for x in self.ssh_cmd]
313+
# For scp the port is specified by a "-P" option
314+
scp_args = ['-P' if x == '-p' else x for x in self.ssh_args]
314315

315316
if not truncate:
316-
scp_cmd = ['scp'] + scp_ssh_cmd + [f"{self.username}@{self.host}:{filename}", tmp_file.name]
317+
scp_cmd = ['scp'] + scp_args + [f"{self.username}@{self.host}:{filename}", tmp_file.name]
317318
subprocess.run(scp_cmd, check=False) # The file might not exist yet
318319
tmp_file.seek(0, os.SEEK_END)
319320

@@ -329,11 +330,11 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
329330
tmp_file.write(data)
330331

331332
tmp_file.flush()
332-
scp_cmd = ['scp'] + scp_ssh_cmd + [tmp_file.name, f"{self.username}@{self.host}:{filename}"]
333+
scp_cmd = ['scp'] + scp_args + [tmp_file.name, f"{self.username}@{self.host}:{filename}"]
333334
subprocess.run(scp_cmd, check=True)
334335

335336
remote_directory = os.path.dirname(filename)
336-
mkdir_cmd = ['ssh', f"{self.username}@{self.host}"] + self.ssh_cmd + [f"mkdir -p {remote_directory}"]
337+
mkdir_cmd = ['ssh'] + self.ssh_args + [f"{self.username}@{self.host}", f"mkdir -p {remote_directory}"]
337338
subprocess.run(mkdir_cmd, check=True)
338339

339340
os.remove(tmp_file.name)
@@ -398,7 +399,7 @@ def get_pid(self):
398399
return int(self.exec_command("echo $$", encoding=get_default_encoding()))
399400

400401
def get_process_children(self, pid):
401-
command = ["ssh", f"{self.username}@{self.host}"] + self.ssh_cmd + [f"pgrep -P {pid}"]
402+
command = ["ssh"] + self.ssh_args + [f"{self.username}@{self.host}", f"pgrep -P {pid}"]
402403

403404
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
404405

testgres/plugins/pg_probackup2/pg_probackup2/app.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(self, test_class: unittest.TestCase,
5656
self.verbose = init_params.verbose
5757
self.archive_compress = init_params.archive_compress
5858
self.test_class.output = None
59+
self.execution_time = None
5960

6061
def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
6162
skip_log_directory=False, expect_error=False, use_backup_dir=True):
@@ -113,16 +114,17 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
113114
cmdline = ['gdbserver'] + ['localhost:' + str(gdb_port)] + cmdline
114115
print("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}".format(gdb_port))
115116

117+
start_time = time.time()
116118
self.test_class.output = subprocess.check_output(
117119
cmdline,
118120
stderr=subprocess.STDOUT,
119121
env=env
120122
).decode('utf-8', errors='replace')
123+
end_time = time.time()
124+
self.execution_time = end_time - start_time
125+
121126
if command[0] == 'backup' and return_id:
122-
# return backup ID
123-
for line in self.test_class.output.splitlines():
124-
if 'INFO: Backup' and 'completed' in line:
125-
result = line.split()[2]
127+
result = self.get_backup_id()
126128
else:
127129
result = self.test_class.output
128130
if expect_error is True:
@@ -139,6 +141,19 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
139141
else:
140142
raise ProbackupException(self.test_class.output, self.test_class.cmd)
141143

144+
def get_backup_id(self):
145+
if init_params.major_version > 2:
146+
pattern = re.compile(r"Backup (.*) completed successfully.")
147+
for line in self.test_class.output.splitlines():
148+
match = pattern.search(line)
149+
if match:
150+
return match.group(1)
151+
else:
152+
for line in self.test_class.output.splitlines():
153+
if 'INFO: Backup' and 'completed' in line:
154+
return line.split()[2]
155+
return None
156+
142157
def init(self, options=None, old_binary=False, skip_log_directory=False, expect_error=False, use_backup_dir=True):
143158
if options is None:
144159
options = []

testgres/plugins/pg_probackup2/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from distutils.core import setup
55

66
setup(
7-
version='0.0.2',
7+
version='0.0.3',
88
name='testgres_pg_probackup2',
99
packages=['pg_probackup2', 'pg_probackup2.storage'],
1010
description='Plugin for testgres that manages pg_probackup2',

0 commit comments

Comments
 (0)