Skip to content

Commit eef5769

Browse files
committed
tests: pgdata_compare now detect missing or redundant directories
1 parent 9484b6d commit eef5769

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ def del_test_dir(self, module_name, fname):
10471047
except:
10481048
pass
10491049

1050-
def pgdata_content(self, directory, ignore_ptrack=True):
1050+
def pgdata_content(self, pgdata, ignore_ptrack=True):
10511051
""" return dict with directory content. "
10521052
" TAKE IT AFTER CHECKPOINT or BACKUP"""
10531053
dirs_to_ignore = [
@@ -1064,9 +1064,10 @@ def pgdata_content(self, directory, ignore_ptrack=True):
10641064
# '_ptrack'
10651065
# )
10661066
directory_dict = {}
1067-
directory_dict['pgdata'] = directory
1067+
directory_dict['pgdata'] = pgdata
10681068
directory_dict['files'] = {}
1069-
for root, dirs, files in os.walk(directory, followlinks=True):
1069+
directory_dict['dirs'] = []
1070+
for root, dirs, files in os.walk(pgdata, followlinks=True):
10701071
dirs[:] = [d for d in dirs if d not in dirs_to_ignore]
10711072
for file in files:
10721073
if (
@@ -1076,7 +1077,7 @@ def pgdata_content(self, directory, ignore_ptrack=True):
10761077
continue
10771078

10781079
file_fullpath = os.path.join(root, file)
1079-
file_relpath = os.path.relpath(file_fullpath, directory)
1080+
file_relpath = os.path.relpath(file_fullpath, pgdata)
10801081
directory_dict['files'][file_relpath] = {'is_datafile': False}
10811082
directory_dict['files'][file_relpath]['md5'] = hashlib.md5(
10821083
open(file_fullpath, 'rb').read()).hexdigest()
@@ -1089,12 +1090,51 @@ def pgdata_content(self, directory, ignore_ptrack=True):
10891090
file_fullpath, size_in_pages
10901091
)
10911092

1093+
for root, dirs, files in os.walk(pgdata, topdown=False, followlinks=True):
1094+
for directory in dirs:
1095+
directory_path = os.path.join(root, directory)
1096+
directory_relpath = os.path.relpath(directory_path, pgdata)
1097+
1098+
found = False
1099+
for d in dirs_to_ignore:
1100+
if d in directory_relpath:
1101+
found = True
1102+
break
1103+
1104+
# check if directory already here as part of larger directory
1105+
if not found:
1106+
for d in directory_dict['dirs']:
1107+
# print("OLD dir {0}".format(d))
1108+
if directory_relpath in d:
1109+
found = True
1110+
break
1111+
1112+
if not found:
1113+
directory_dict['dirs'].append(directory_relpath)
1114+
10921115
return directory_dict
10931116

10941117
def compare_pgdata(self, original_pgdata, restored_pgdata):
10951118
""" return dict with directory content. DO IT BEFORE RECOVERY"""
10961119
fail = False
10971120
error_message = 'Restored PGDATA is not equal to original!\n'
1121+
1122+
# Compare directories
1123+
for directory in restored_pgdata['dirs']:
1124+
if directory not in original_pgdata['dirs']:
1125+
fail = True
1126+
error_message += '\nDirectory is not present'
1127+
error_message += ' in original PGDATA: {0}\n'.format(
1128+
os.path.join(restored_pgdata['pgdata'], directory))
1129+
1130+
for directory in original_pgdata['dirs']:
1131+
if directory not in restored_pgdata['dirs']:
1132+
fail = True
1133+
error_message += '\nDirectory dissappeared'
1134+
error_message += ' in restored PGDATA: {0}\n'.format(
1135+
os.path.join(restored_pgdata['pgdata'], directory))
1136+
1137+
10981138
for file in restored_pgdata['files']:
10991139
# File is present in RESTORED PGDATA
11001140
# but not present in ORIGINAL

0 commit comments

Comments
 (0)