Skip to content

Commit 2329af3

Browse files
committed
tests: added test_validate_specific_error_intermediate_backups()
1 parent f7ed67a commit 2329af3

File tree

1 file changed

+87
-7
lines changed

1 file changed

+87
-7
lines changed

tests/validate_test.py

Lines changed: 87 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,12 @@ def test_validate_corrupted_intermediate_backups(self):
412412
self.del_test_dir(module_name, fname)
413413

414414
# @unittest.skip("skip")
415-
def test_validate_error_intermediate_backups(self):
415+
def test_validate_specific_error_intermediate_backups(self):
416416
"""
417417
make archive node, take FULL, PAGE1, PAGE2 backups,
418418
change backup status of FULL and PAGE1 to ERROR,
419419
run validate on PAGE1
420-
purpouse of this test is to be sure that not only
420+
purpose of this test is to be sure that not only
421421
CORRUPT backup descendants can be orphanized
422422
"""
423423
fname = self.id().split('.')[3]
@@ -450,8 +450,6 @@ def test_validate_error_intermediate_backups(self):
450450
with open(control_path, 'r') as f:
451451
actual_control = f.read()
452452

453-
print(actual_control)
454-
455453
new_control_file = ''
456454
for line in actual_control.splitlines():
457455
new_control_file += line.replace(
@@ -463,9 +461,6 @@ def test_validate_error_intermediate_backups(self):
463461
f.flush()
464462
f.close()
465463

466-
print('HELLO')
467-
print(new_control_file)
468-
469464
# Validate PAGE1
470465
try:
471466
self.validate_pb(
@@ -505,6 +500,91 @@ def test_validate_error_intermediate_backups(self):
505500
# Clean after yourself
506501
self.del_test_dir(module_name, fname)
507502

503+
# @unittest.skip("skip")
504+
def test_validate_error_intermediate_backups(self):
505+
"""
506+
make archive node, take FULL, PAGE1, PAGE2 backups,
507+
change backup status of FULL and PAGE1 to ERROR,
508+
run validate on instance
509+
purpose of this test is to be sure that not only
510+
CORRUPT backup descendants can be orphanized
511+
"""
512+
fname = self.id().split('.')[3]
513+
node = self.make_simple_node(
514+
base_dir=os.path.join(module_name, fname, 'node'),
515+
initdb_params=['--data-checksums'],
516+
pg_options={'wal_level': 'replica'}
517+
)
518+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
519+
self.init_pb(backup_dir)
520+
self.add_instance(backup_dir, 'node', node)
521+
self.set_archiving(backup_dir, 'node', node)
522+
node.slow_start()
523+
524+
# FULL
525+
backup_id_1 = self.backup_node(backup_dir, 'node', node)
526+
527+
# PAGE1
528+
backup_id_2 = self.backup_node(
529+
backup_dir, 'node', node, backup_type='page')
530+
531+
# PAGE2
532+
backup_id_3 = self.backup_node(
533+
backup_dir, 'node', node, backup_type='page')
534+
535+
# Change FULL backup status to ERROR
536+
control_path = os.path.join(
537+
backup_dir, 'backups', 'node', backup_id_1, 'backup.control')
538+
539+
with open(control_path, 'r') as f:
540+
actual_control = f.read()
541+
542+
new_control_file = ''
543+
for line in actual_control.splitlines():
544+
new_control_file += line.replace(
545+
'status = OK', 'status = ERROR')
546+
new_control_file += '\n'
547+
548+
with open(control_path, 'wt') as f:
549+
f.write(new_control_file)
550+
f.flush()
551+
f.close()
552+
553+
# Validate instance
554+
try:
555+
self.validate_pb(backup_dir)
556+
self.assertEqual(
557+
1, 0,
558+
"Expecting Error because backup has status ERROR.\n "
559+
"Output: {0} \n CMD: {1}".format(
560+
repr(self.output), self.cmd))
561+
except ProbackupException as e:
562+
self.assertTrue(
563+
"WARNING: Backup {0} is orphaned because "
564+
"his parent {1} has status: ERROR".format(
565+
backup_id_2, backup_id_1) in e.message and
566+
'WARNING: Backup {0} has status ERROR. Skip validation'.format(
567+
backup_id_1) in e.message and
568+
"WARNING: Some backups are not valid" in e.message,
569+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
570+
repr(e.message), self.cmd))
571+
572+
self.assertEqual(
573+
'ERROR',
574+
self.show_pb(backup_dir, 'node', backup_id_1)['status'],
575+
'Backup STATUS should be "ERROR"')
576+
self.assertEqual(
577+
'ORPHAN',
578+
self.show_pb(backup_dir, 'node', backup_id_2)['status'],
579+
'Backup STATUS should be "ORPHAN"')
580+
self.assertEqual(
581+
'ORPHAN',
582+
self.show_pb(backup_dir, 'node', backup_id_3)['status'],
583+
'Backup STATUS should be "ORPHAN"')
584+
585+
# Clean after yourself
586+
self.del_test_dir(module_name, fname)
587+
508588
# @unittest.skip("skip")
509589
def test_validate_corrupted_intermediate_backups_1(self):
510590
"""

0 commit comments

Comments
 (0)