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

Commit 934f540

Browse files
committed
try to fix tests with new class
1 parent beef059 commit 934f540

File tree

2 files changed

+88
-55
lines changed

2 files changed

+88
-55
lines changed

testgres/probackup.py

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from time import sleep
1616
from sys import exit, argv, version_info
1717

18+
#from testgres.utils import get_pg_edition
19+
from testgres.utils import is_enterprise, is_nls_enabled
1820

1921
class ProbackupException(Exception):
2022
def __init__(self, message, cmd):
@@ -25,6 +27,8 @@ def __str__(self):
2527
return '\n ERROR: {0}\n CMD: {1}'.format(repr(self.message), self.cmd)
2628

2729

30+
31+
2832
class ProbackupTest(object):
2933
# Class attributes
3034
enterprise = is_enterprise()
@@ -104,6 +108,8 @@ def __init__(self, *args, **kwargs):
104108
if self.verbose:
105109
print('PGPROBACKUPBIN is not an executable file')
106110

111+
print('@@@', self.probackup_path)
112+
107113
if not self.probackup_path:
108114
probackup_path_tmp = os.path.join(
109115
testgres.get_pg_config()['BINDIR'], 'pg_probackup')
@@ -1482,7 +1488,7 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
14821488
directory_dict['pgdata'] = pgdata
14831489
directory_dict['files'] = {}
14841490
directory_dict['dirs'] = {}
1485-
for root, dirs, files in os.walk(pgdata, followlinks=True):
1491+
for root, dirs, files in os.walk(pgdata, followlinks=true):
14861492
dirs[:] = [d for d in dirs if d not in dirs_to_ignore]
14871493
for file in files:
14881494
if (
@@ -1493,7 +1499,7 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
14931499

14941500
file_fullpath = os.path.join(root, file)
14951501
file_relpath = os.path.relpath(file_fullpath, pgdata)
1496-
directory_dict['files'][file_relpath] = {'is_datafile': False}
1502+
directory_dict['files'][file_relpath] = {'is_datafile': false}
14971503
with open(file_fullpath, 'rb') as f:
14981504
directory_dict['files'][file_relpath]['md5'] = hashlib.md5(f.read()).hexdigest()
14991505
f.close()
@@ -1502,30 +1508,30 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
15021508

15031509
# crappy algorithm
15041510
if file.isdigit():
1505-
directory_dict['files'][file_relpath]['is_datafile'] = True
1511+
directory_dict['files'][file_relpath]['is_datafile'] = true
15061512
size_in_pages = os.path.getsize(file_fullpath)/8192
15071513
directory_dict['files'][file_relpath][
15081514
'md5_per_page'] = self.get_md5_per_page_for_fork(
15091515
file_fullpath, size_in_pages
15101516
)
15111517

1512-
for root, dirs, files in os.walk(pgdata, topdown=False, followlinks=True):
1518+
for root, dirs, files in os.walk(pgdata, topdown=false, followlinks=true):
15131519
for directory in dirs:
15141520
directory_path = os.path.join(root, directory)
15151521
directory_relpath = os.path.relpath(directory_path, pgdata)
15161522

1517-
found = False
1523+
found = false
15181524
for d in dirs_to_ignore:
15191525
if d in directory_relpath:
1520-
found = True
1526+
found = true
15211527
break
15221528

15231529
# check if directory already here as part of larger directory
15241530
if not found:
15251531
for d in directory_dict['dirs']:
1526-
# print("OLD dir {0}".format(d))
1532+
# print("old dir {0}".format(d))
15271533
if directory_relpath in d:
1528-
found = True
1534+
found = true
15291535
break
15301536

15311537
if not found:
@@ -1548,13 +1554,13 @@ def get_known_bugs_comparision_exclusion_dict(self, node):
15481554
""" get dict of known datafiles difference, that can be used in compare_pgdata() """
15491555
comparision_exclusion_dict = dict()
15501556

1551-
# bug in spgist metapage update (PGPRO-5707)
1557+
# bug in spgist metapage update (pgpro-5707)
15521558
spgist_filelist = node.safe_psql(
15531559
"postgres",
1554-
"SELECT pg_catalog.pg_relation_filepath(pg_class.oid) "
1555-
"FROM pg_am, pg_class "
1556-
"WHERE pg_am.amname = 'spgist' "
1557-
"AND pg_class.relam = pg_am.oid"
1560+
"select pg_catalog.pg_relation_filepath(pg_class.oid) "
1561+
"from pg_am, pg_class "
1562+
"where pg_am.amname = 'spgist' "
1563+
"and pg_class.relam = pg_am.oid"
15581564
).decode('utf-8').rstrip().splitlines()
15591565
for filename in spgist_filelist:
15601566
comparision_exclusion_dict[filename] = set([0])
@@ -1564,49 +1570,49 @@ def get_known_bugs_comparision_exclusion_dict(self, node):
15641570

15651571
def compare_pgdata(self, original_pgdata, restored_pgdata, exclusion_dict = dict()):
15661572
"""
1567-
return dict with directory content. DO IT BEFORE RECOVERY
1573+
return dict with directory content. do it before recovery
15681574
exclusion_dict is used for exclude files (and it block_no) from comparision
15691575
it is a dict with relative filenames as keys and set of block numbers as values
15701576
"""
1571-
fail = False
1572-
error_message = 'Restored PGDATA is not equal to original!\n'
1577+
fail = false
1578+
error_message = 'restored pgdata is not equal to original!\n'
15731579

1574-
# Compare directories
1580+
# compare directories
15751581
for directory in restored_pgdata['dirs']:
15761582
if directory not in original_pgdata['dirs']:
1577-
fail = True
1578-
error_message += '\nDirectory was not present'
1579-
error_message += ' in original PGDATA: {0}\n'.format(
1583+
fail = true
1584+
error_message += '\ndirectory was not present'
1585+
error_message += ' in original pgdata: {0}\n'.format(
15801586
os.path.join(restored_pgdata['pgdata'], directory))
15811587
else:
15821588
if (
15831589
restored_pgdata['dirs'][directory]['mode'] !=
15841590
original_pgdata['dirs'][directory]['mode']
15851591
):
1586-
fail = True
1587-
error_message += '\nDir permissions mismatch:\n'
1588-
error_message += ' Dir old: {0} Permissions: {1}\n'.format(
1592+
fail = true
1593+
error_message += '\ndir permissions mismatch:\n'
1594+
error_message += ' dir old: {0} permissions: {1}\n'.format(
15891595
os.path.join(original_pgdata['pgdata'], directory),
15901596
original_pgdata['dirs'][directory]['mode'])
1591-
error_message += ' Dir new: {0} Permissions: {1}\n'.format(
1597+
error_message += ' dir new: {0} permissions: {1}\n'.format(
15921598
os.path.join(restored_pgdata['pgdata'], directory),
15931599
restored_pgdata['dirs'][directory]['mode'])
15941600

15951601
for directory in original_pgdata['dirs']:
15961602
if directory not in restored_pgdata['dirs']:
1597-
fail = True
1598-
error_message += '\nDirectory dissappeared'
1599-
error_message += ' in restored PGDATA: {0}\n'.format(
1603+
fail = true
1604+
error_message += '\ndirectory dissappeared'
1605+
error_message += ' in restored pgdata: {0}\n'.format(
16001606
os.path.join(restored_pgdata['pgdata'], directory))
16011607

16021608
for file in restored_pgdata['files']:
1603-
# File is present in RESTORED PGDATA
1604-
# but not present in ORIGINAL
1609+
# file is present in restored pgdata
1610+
# but not present in original
16051611
# only backup_label is allowed
16061612
if file not in original_pgdata['files']:
1607-
fail = True
1608-
error_message += '\nFile is not present'
1609-
error_message += ' in original PGDATA: {0}\n'.format(
1613+
fail = true
1614+
error_message += '\nfile is not present'
1615+
error_message += ' in original pgdata: {0}\n'.format(
16101616
os.path.join(restored_pgdata['pgdata'], file))
16111617

16121618
for file in original_pgdata['files']:
@@ -1616,12 +1622,12 @@ def compare_pgdata(self, original_pgdata, restored_pgdata, exclusion_dict = dict
16161622
restored_pgdata['files'][file]['mode'] !=
16171623
original_pgdata['files'][file]['mode']
16181624
):
1619-
fail = True
1620-
error_message += '\nFile permissions mismatch:\n'
1621-
error_message += ' File_old: {0} Permissions: {1:o}\n'.format(
1625+
fail = true
1626+
error_message += '\nfile permissions mismatch:\n'
1627+
error_message += ' file_old: {0} permissions: {1:o}\n'.format(
16221628
os.path.join(original_pgdata['pgdata'], file),
16231629
original_pgdata['files'][file]['mode'])
1624-
error_message += ' File_new: {0} Permissions: {1:o}\n'.format(
1630+
error_message += ' file_new: {0} permissions: {1:o}\n'.format(
16251631
os.path.join(restored_pgdata['pgdata'], file),
16261632
restored_pgdata['files'][file]['mode'])
16271633

@@ -1630,11 +1636,11 @@ def compare_pgdata(self, original_pgdata, restored_pgdata, exclusion_dict = dict
16301636
restored_pgdata['files'][file]['md5']
16311637
):
16321638
if file not in exclusion_dict:
1633-
fail = True
1639+
fail = true
16341640
error_message += (
1635-
'\nFile Checksum mismatch.\n'
1636-
'File_old: {0}\nChecksum_old: {1}\n'
1637-
'File_new: {2}\nChecksum_new: {3}\n').format(
1641+
'\nfile checksum mismatch.\n'
1642+
'file_old: {0}\nchecksum_old: {1}\n'
1643+
'file_new: {2}\nchecksum_new: {3}\n').format(
16381644
os.path.join(original_pgdata['pgdata'], file),
16391645
original_pgdata['files'][file]['md5'],
16401646
os.path.join(restored_pgdata['pgdata'], file),
@@ -1645,8 +1651,8 @@ def compare_pgdata(self, original_pgdata, restored_pgdata, exclusion_dict = dict
16451651
for page in original_pgdata['files'][file]['md5_per_page']:
16461652
if page not in restored_pgdata['files'][file]['md5_per_page']:
16471653
error_message += (
1648-
'\n Page {0} dissappeared.\n '
1649-
'File: {1}\n').format(
1654+
'\n page {0} dissappeared.\n '
1655+
'file: {1}\n').format(
16501656
page,
16511657
os.path.join(
16521658
restored_pgdata['pgdata'],
@@ -1660,12 +1666,12 @@ def compare_pgdata(self, original_pgdata, restored_pgdata, exclusion_dict = dict
16601666
original_pgdata['files'][file]['md5_per_page'][page] !=
16611667
restored_pgdata['files'][file]['md5_per_page'][page]
16621668
):
1663-
fail = True
1669+
fail = true
16641670
error_message += (
1665-
'\n Page checksum mismatch: {0}\n '
1666-
' PAGE Checksum_old: {1}\n '
1667-
' PAGE Checksum_new: {2}\n '
1668-
' File: {3}\n'
1671+
'\n page checksum mismatch: {0}\n '
1672+
' page checksum_old: {1}\n '
1673+
' page checksum_new: {2}\n '
1674+
' file: {3}\n'
16691675
).format(
16701676
page,
16711677
original_pgdata['files'][file][
@@ -1677,27 +1683,27 @@ def compare_pgdata(self, original_pgdata, restored_pgdata, exclusion_dict = dict
16771683
)
16781684
for page in restored_pgdata['files'][file]['md5_per_page']:
16791685
if page not in original_pgdata['files'][file]['md5_per_page']:
1680-
error_message += '\n Extra page {0}\n File: {1}\n'.format(
1686+
error_message += '\n extra page {0}\n file: {1}\n'.format(
16811687
page,
16821688
os.path.join(
16831689
restored_pgdata['pgdata'], file))
16841690

16851691
else:
16861692
error_message += (
1687-
'\nFile disappearance.\n '
1688-
'File: {0}\n').format(
1693+
'\nfile disappearance.\n '
1694+
'file: {0}\n').format(
16891695
os.path.join(restored_pgdata['pgdata'], file)
16901696
)
1691-
fail = True
1692-
self.assertFalse(fail, error_message)
1697+
fail = true
1698+
self.assertfalse(fail, error_message)
16931699

16941700
def gdb_attach(self, pid):
1695-
return GDBobj([str(pid)], self, attach=True)
1701+
return gdbobj([str(pid)], self, attach=true)
16961702

16971703
def _check_gdb_flag_or_skip_test(self):
16981704
if not self.gdb:
1699-
self.skipTest(
1700-
"Specify PGPROBACKUP_GDB and build without "
1705+
self.skiptest(
1706+
"specify pgprobackup_gdb and build without "
17011707
"optimizations for run this test"
17021708
)
17031709

testgres/utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,30 @@ def clean_on_error(node):
261261
# TODO: should we wrap this in try-block?
262262
node.cleanup()
263263
raise
264+
265+
266+
def is_enterprise():
267+
# pg_config --help
268+
# DDD move to the common helpers
269+
cmd = [os.environ['PG_CONFIG'], '--configure']
270+
271+
p = subprocess.Popen(
272+
cmd,
273+
stdout=subprocess.PIPE,
274+
stderr=subprocess.PIPE
275+
)
276+
277+
#p.communicate()[0]
278+
279+
return b'postgrespro.ru' in p.communicate()[0]
280+
281+
282+
def is_nls_enabled():
283+
cmd = [os.environ['PG_CONFIG'], '--configure']
284+
285+
p = subprocess.Popen(
286+
cmd,
287+
stdout=subprocess.PIPE,
288+
stderr=subprocess.PIPE
289+
)
290+
return b'enable-nls' in p.communicate()[0]

0 commit comments

Comments
 (0)