Skip to content

Commit c88cf22

Browse files
committed
tests: added restore.RestoreTest.test_pg_11_group_access
1 parent e1c4f8f commit c88cf22

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
12221222
directory_dict = {}
12231223
directory_dict['pgdata'] = pgdata
12241224
directory_dict['files'] = {}
1225-
directory_dict['dirs'] = []
1225+
directory_dict['dirs'] = {}
12261226
for root, dirs, files in os.walk(pgdata, followlinks=True):
12271227
dirs[:] = [d for d in dirs if d not in dirs_to_ignore]
12281228
for file in files:
@@ -1267,7 +1267,18 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
12671267
break
12681268

12691269
if not found:
1270-
directory_dict['dirs'].append(directory_relpath)
1270+
directory_dict['dirs'][directory_relpath] = {}
1271+
1272+
# get permissions for every file and directory
1273+
for file in directory_dict['dirs']:
1274+
full_path = os.path.join(pgdata, file)
1275+
directory_dict['dirs'][file]['mode'] = os.stat(
1276+
full_path).st_mode
1277+
1278+
for file in directory_dict['files']:
1279+
full_path = os.path.join(pgdata, file)
1280+
directory_dict['files'][file]['mode'] = os.stat(
1281+
full_path).st_mode
12711282

12721283
return directory_dict
12731284

@@ -1283,6 +1294,21 @@ def compare_pgdata(self, original_pgdata, restored_pgdata):
12831294
error_message += '\nDirectory was not present'
12841295
error_message += ' in original PGDATA: {0}\n'.format(
12851296
os.path.join(restored_pgdata['pgdata'], directory))
1297+
else:
1298+
if (
1299+
restored_pgdata['dirs'][directory]['mode'] !=
1300+
original_pgdata['dirs'][directory]['mode']
1301+
):
1302+
fail = True
1303+
error_message += '\nDir permissions mismatch:\n'
1304+
error_message += ' Dir old: {0} Permissions: {1}\n'.format(
1305+
os.path.join(original_pgdata['pgdata'], directory),
1306+
original_pgdata['dirs'][directory]['mode'])
1307+
error_message += ' Dir new: {0} Permissions: {1}\n'.format(
1308+
os.path.join(restored_pgdata['pgdata'], directory),
1309+
restored_pgdata['dirs'][directory]['mode'])
1310+
1311+
12861312

12871313
for directory in original_pgdata['dirs']:
12881314
if directory not in restored_pgdata['dirs']:
@@ -1305,6 +1331,19 @@ def compare_pgdata(self, original_pgdata, restored_pgdata):
13051331
for file in original_pgdata['files']:
13061332
if file in restored_pgdata['files']:
13071333

1334+
if (
1335+
restored_pgdata['files'][file]['mode'] !=
1336+
original_pgdata['files'][file]['mode']
1337+
):
1338+
fail = True
1339+
error_message += '\nFile permissions mismatch:\n'
1340+
error_message += ' File_old: {0} Permissions: {1}\n'.format(
1341+
os.path.join(original_pgdata['pgdata'], file),
1342+
original_pgdata['files'][file]['mode'])
1343+
error_message += ' File_new: {0} Permissions: {1}\n'.format(
1344+
os.path.join(restored_pgdata['pgdata'], file),
1345+
restored_pgdata['files'][file]['mode'])
1346+
13081347
if (
13091348
original_pgdata['files'][file]['md5'] !=
13101349
restored_pgdata['files'][file]['md5']

tests/restore.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,3 +2152,44 @@ def test_smart_restore(self):
21522152

21532153
# Clean after yourself
21542154
self.del_test_dir(module_name, fname)
2155+
2156+
# @unittest.skip("skip")
2157+
def test_pg_11_group_access(self):
2158+
"""
2159+
test group access for PG >= 11
2160+
"""
2161+
fname = self.id().split('.')[3]
2162+
node = self.make_simple_node(
2163+
base_dir=os.path.join(module_name, fname, 'node'),
2164+
set_replication=True,
2165+
initdb_params=[
2166+
'--data-checksums',
2167+
'--allow-group-access'])
2168+
2169+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
2170+
self.init_pb(backup_dir)
2171+
self.add_instance(backup_dir, 'node', node)
2172+
node.slow_start()
2173+
2174+
if self.get_version(node) < self.version_to_num('11.0'):
2175+
return unittest.skip('You need PostgreSQL >= 11 for this test')
2176+
2177+
# take FULL backup
2178+
self.backup_node(backup_dir, 'node', node, options=['--stream'])
2179+
2180+
pgdata = self.pgdata_content(node.data_dir)
2181+
2182+
# restore backup
2183+
node_restored = self.make_simple_node(
2184+
base_dir=os.path.join(module_name, fname, 'node_restored'))
2185+
node_restored.cleanup()
2186+
2187+
self.restore_node(
2188+
backup_dir, 'node', node_restored)
2189+
2190+
# compare pgdata permissions
2191+
pgdata_restored = self.pgdata_content(node_restored.data_dir)
2192+
self.compare_pgdata(pgdata, pgdata_restored)
2193+
2194+
# Clean after yourself
2195+
self.del_test_dir(module_name, fname)

0 commit comments

Comments
 (0)