Skip to content

Commit 5bc3fb2

Browse files
committed
[PGPRO-5421] fix test_wal_file_path_3 portability
1 parent f601238 commit 5bc3fb2

File tree

2 files changed

+52
-43
lines changed

2 files changed

+52
-43
lines changed

tests/archive.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,24 +1914,30 @@ def test_wal_file_path_3(self):
19141914
"""
19151915
fname = self.id().split('.')[3]
19161916
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
1917+
19171918
node = self.make_simple_node(
19181919
base_dir=os.path.join(module_name, fname, 'node'),
1919-
set_replication=True,
1920-
initdb_params=['--data-checksums'],
1921-
pg_options={
1922-
'archive_mode': 'on',
1923-
'wal_keep_size' : '0'})
1920+
initdb_params=['--data-checksums'])
1921+
1922+
node_pg_options = {}
1923+
if node.major_version >= 13:
1924+
node_pg_options['wal_keep_size'] = '0MB'
1925+
else:
1926+
node_pg_options['wal_keep_segments'] = '0'
1927+
self.set_auto_conf(node, node_pg_options)
19241928

19251929
self.init_pb(backup_dir)
19261930
self.add_instance(backup_dir, 'node', node)
1927-
self.set_archiving(backup_dir, 'node', node, compress=True)
19281931

1929-
wal_dir = os.path.join(self.tmp_path, module_name, fname, 'wal_dir')
1930-
os.mkdir(wal_dir)
1931-
self.set_config(
1932-
backup_dir, 'node',
1933-
options=['--log-level-file=VERBOSE'])
1934-
self.set_auto_conf(node, {'archive_command': "cp -v %p {0}/%f".format(wal_dir)})
1932+
wal_dir = os.path.join(self.tmp_path, module_name, fname, 'intermediate_dir')
1933+
shutil.rmtree(wal_dir, ignore_errors=True)
1934+
os.makedirs(wal_dir)
1935+
if os.name == 'posix':
1936+
self.set_archiving(backup_dir, 'node', node, custom_archive_command='cp -v %p {0}/%f'.format(wal_dir))
1937+
elif os.name == 'nt':
1938+
self.set_archiving(backup_dir, 'node', node, custom_archive_command='xcopy /F "%p" "{0}/%f"'.format(wal_dir.replace("\\","\\\\")))
1939+
else:
1940+
self.assertTrue(False, 'Unexpected os family')
19351941

19361942
node.slow_start()
19371943
node.safe_psql(

tests/helpers/ptrack_helpers.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,8 @@ def get_recovery_conf(self, node):
12961296
def set_archiving(
12971297
self, backup_dir, instance, node, replica=False,
12981298
overwrite=False, compress=True, old_binary=False,
1299-
log_level=False, archive_timeout=False):
1299+
log_level=False, archive_timeout=False,
1300+
custom_archive_command=None):
13001301

13011302
# parse postgresql.auto.conf
13021303
options = {}
@@ -1306,45 +1307,47 @@ def set_archiving(
13061307
else:
13071308
options['archive_mode'] = 'on'
13081309

1309-
if os.name == 'posix':
1310-
options['archive_command'] = '"{0}" archive-push -B {1} --instance={2} '.format(
1311-
self.probackup_path, backup_dir, instance)
1312-
1313-
elif os.name == 'nt':
1314-
options['archive_command'] = '"{0}" archive-push -B {1} --instance={2} '.format(
1315-
self.probackup_path.replace("\\","\\\\"),
1316-
backup_dir.replace("\\","\\\\"), instance)
1310+
if custom_archive_command is None:
1311+
if os.name == 'posix':
1312+
options['archive_command'] = '"{0}" archive-push -B {1} --instance={2} '.format(
1313+
self.probackup_path, backup_dir, instance)
13171314

1318-
# don`t forget to kill old_binary after remote ssh release
1319-
if self.remote and not old_binary:
1320-
options['archive_command'] += '--remote-proto=ssh '
1321-
options['archive_command'] += '--remote-host=localhost '
1315+
elif os.name == 'nt':
1316+
options['archive_command'] = '"{0}" archive-push -B {1} --instance={2} '.format(
1317+
self.probackup_path.replace("\\","\\\\"),
1318+
backup_dir.replace("\\","\\\\"), instance)
13221319

1323-
if self.archive_compress and compress:
1324-
options['archive_command'] += '--compress '
1320+
# don`t forget to kill old_binary after remote ssh release
1321+
if self.remote and not old_binary:
1322+
options['archive_command'] += '--remote-proto=ssh '
1323+
options['archive_command'] += '--remote-host=localhost '
13251324

1326-
if overwrite:
1327-
options['archive_command'] += '--overwrite '
1325+
if self.archive_compress and compress:
1326+
options['archive_command'] += '--compress '
13281327

1329-
options['archive_command'] += '--log-level-console=VERBOSE '
1330-
options['archive_command'] += '-j 5 '
1331-
options['archive_command'] += '--batch-size 10 '
1332-
options['archive_command'] += '--no-sync '
1328+
if overwrite:
1329+
options['archive_command'] += '--overwrite '
13331330

1334-
if archive_timeout:
1335-
options['archive_command'] += '--archive-timeout={0} '.format(
1336-
archive_timeout)
1331+
options['archive_command'] += '--log-level-console=VERBOSE '
1332+
options['archive_command'] += '-j 5 '
1333+
options['archive_command'] += '--batch-size 10 '
1334+
options['archive_command'] += '--no-sync '
13371335

1338-
if os.name == 'posix':
1339-
options['archive_command'] += '--wal-file-path=%p --wal-file-name=%f'
1336+
if archive_timeout:
1337+
options['archive_command'] += '--archive-timeout={0} '.format(
1338+
archive_timeout)
13401339

1341-
elif os.name == 'nt':
1342-
options['archive_command'] += '--wal-file-path="%p" --wal-file-name="%f"'
1340+
if os.name == 'posix':
1341+
options['archive_command'] += '--wal-file-path=%p --wal-file-name=%f'
13431342

1344-
if log_level:
1345-
options['archive_command'] += ' --log-level-console={0}'.format(log_level)
1346-
options['archive_command'] += ' --log-level-file={0} '.format(log_level)
1343+
elif os.name == 'nt':
1344+
options['archive_command'] += '--wal-file-path="%p" --wal-file-name="%f"'
13471345

1346+
if log_level:
1347+
options['archive_command'] += ' --log-level-console={0}'.format(log_level)
1348+
options['archive_command'] += ' --log-level-file={0} '.format(log_level)
1349+
else: # custom_archive_command is not None
1350+
options['archive_command'] = custom_archive_command
13481351

13491352
self.set_auto_conf(node, options)
13501353

0 commit comments

Comments
 (0)