|
3 | 3 | importos |
4 | 4 | from .helpers.ptrack_helpersimportProbackupTest,ProbackupException |
5 | 5 | fromsysimportexit |
| 6 | +fromshutilimportcopyfile |
6 | 7 |
|
7 | 8 | module_name='config' |
8 | 9 |
|
@@ -51,3 +52,61 @@ def test_remove_instance_config(self): |
51 | 52 | e.message, |
52 | 53 | "\n Unexpected Error Message: {0}\n CMD: {1}".format( |
53 | 54 | repr(e.message),self.cmd)) |
| 55 | + |
| 56 | +# @unittest.expectedFailure |
| 57 | +# @unittest.skip("skip") |
| 58 | +deftest_corrupt_backup_content(self): |
| 59 | +"""corrupt backup_content.control""" |
| 60 | +fname=self.id().split('.')[3] |
| 61 | +backup_dir=os.path.join(self.tmp_path,module_name,fname,'backup') |
| 62 | +node=self.make_simple_node( |
| 63 | +base_dir=os.path.join(module_name,fname,'node'), |
| 64 | +set_replication=True, |
| 65 | +initdb_params=['--data-checksums']) |
| 66 | + |
| 67 | +self.init_pb(backup_dir) |
| 68 | +self.add_instance(backup_dir,'node',node) |
| 69 | +self.set_archiving(backup_dir,'node',node) |
| 70 | +node.slow_start() |
| 71 | + |
| 72 | +full1_id=self.backup_node(backup_dir,'node',node) |
| 73 | + |
| 74 | +node.safe_psql( |
| 75 | +'postgres', |
| 76 | +'create table t1()') |
| 77 | + |
| 78 | +fulle2_id=self.backup_node(backup_dir,'node',node) |
| 79 | + |
| 80 | +fulle1_conf_file=os.path.join( |
| 81 | +backup_dir,'backups','node',full1_id,'backup_content.control') |
| 82 | + |
| 83 | +fulle2_conf_file=os.path.join( |
| 84 | +backup_dir,'backups','node',fulle2_id,'backup_content.control') |
| 85 | + |
| 86 | +copyfile(fulle2_conf_file,fulle1_conf_file) |
| 87 | + |
| 88 | +try: |
| 89 | +self.validate_pb(backup_dir,'node') |
| 90 | +self.assertEqual( |
| 91 | +1,0, |
| 92 | +"Expecting Error because pg_probackup.conf is missing. " |
| 93 | +".\n Output: {0}\n CMD: {1}".format( |
| 94 | +repr(self.output),self.cmd)) |
| 95 | +exceptProbackupExceptionase: |
| 96 | +self.assertIn( |
| 97 | +"WARNING: Invalid CRC of backup control file '{0}':".format(fulle1_conf_file), |
| 98 | +e.message, |
| 99 | +"\n Unexpected Error Message: {0}\n CMD: {1}".format( |
| 100 | +repr(e.message),self.cmd)) |
| 101 | + |
| 102 | +self.assertIn( |
| 103 | +"WARNING: Failed to get file list for backup {0}".format(full1_id), |
| 104 | +e.message, |
| 105 | +"\n Unexpected Error Message: {0}\n CMD: {1}".format( |
| 106 | +repr(e.message),self.cmd)) |
| 107 | + |
| 108 | +self.assertIn( |
| 109 | +"WARNING: Backup {0} file list is corrupted".format(full1_id), |
| 110 | +e.message, |
| 111 | +"\n Unexpected Error Message: {0}\n CMD: {1}".format( |
| 112 | +repr(e.message),self.cmd)) |