1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-01-20 11:34:51 +02:00

test_ptrack_disable added

This commit is contained in:
Grigory Smolkin 2017-10-05 12:06:01 +03:00
parent af99fe4daa
commit 3700576d99
2 changed files with 111 additions and 32 deletions

View File

@ -599,7 +599,7 @@ class ProbackupTest(object):
def pgdata_content(self, directory):
""" return dict with directory content. TAKE IT AFTER CHECKPOINT or BACKUP"""
dirs_to_ignore = ['pg_xlog', 'pg_wal', 'pg_log', 'pg_stat_tmp', 'pg_subtrans', 'pg_notify']
files_to_ignore = ['postmaster.pid', 'postmaster.opts', 'pg_internal.init']
files_to_ignore = ['postmaster.pid', 'postmaster.opts', 'pg_internal.init', 'postgresql.auto.conf']
suffixes_to_ignore = ('_ptrack', 'ptrack_control', 'pg_control', 'ptrack_init')
directory_dict = {}
directory_dict['pgdata'] = directory

View File

@ -12,7 +12,7 @@ module_name = 'ptrack'
class PtrackBackupTest(ProbackupTest, unittest.TestCase):
#@unittest.skip("skip")
# @unittest.skip("skip")
# @unittest.expectedFailure
def test_ptrack_enable(self):
"""make ptrack without full backup, should result in error"""
@ -42,7 +42,88 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
# Clean after yourself
self.del_test_dir(module_name, fname)
#@unittest.skip("skip")
# @unittest.skip("skip")
# @unittest.expectedFailure
def test_ptrack_disable(self):
"""Take full backup, disable ptrack restart postgresql, enable ptrack, restart postgresql, take ptrack backup which should fail"""
self.maxDiff = None
fname = self.id().split('.')[3]
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
set_replication=True,
initdb_params=['--data-checksums'],
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', 'checkpoint_timeout': '30s', 'ptrack_enable': 'on'}
)
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node)
node.start()
# FULL BACKUP
self.backup_node(backup_dir, 'node', node, options=['--stream'])
# DISABLE PTRACK
node.safe_psql('postgres', "alter system set ptrack_enable to off")
node.restart()
print('DISABLED')
print(node.safe_psql('postgres', "select pg_ptrack_control_lsn()"))
# ENABLE PTRACK
node.safe_psql('postgres', "alter system set ptrack_enable to on")
node.restart()
print('ENABLED')
print(node.safe_psql('postgres', "select pg_ptrack_control_lsn()"))
# PTRACK BACKUP
try:
self.backup_node(backup_dir, 'node', node, backup_type='ptrack', options=["--stream"])
# we should die here because exception is what we expect to happen
self.assertEqual(1, 0, "Expecting Error because ptrack_enable was set to OFF at some point after previous backup.\n Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertIn('ERROR: LSN from ptrack_control', e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
# @unittest.expectedFailure
def test_ptrack_control(self):
"""make ptrack without full backup, should result in error"""
self.maxDiff = None
fname = self.id().split('.')[3]
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
set_replication=True,
initdb_params=['--data-checksums'],
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', 'checkpoint_timeout': '30s', 'ptrack_enable': 'on'}
)
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
node.start()
# FULL BACKUP
self.backup_node(backup_dir, 'node', node, options=['--stream'])
# DISABLE PTRACK
node.safe_psql('postgres', "select ")
node.restart()
# ENABLE PTRACK
node.safe_psql('postgres', "alter system set ptrack_enable to on")
node.restart()
# PTRACK BACKUP
try:
self.backup_node(backup_dir, 'node', node, backup_type='ptrack', options=["--stream"])
# we should die here because exception is what we expect to happen
self.assertEqual(1, 0, "Expecting Error because ptrack_enable was set to OFF at some point after previous backup.\n Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertIn('ERROR: LSN from ptrack_control', e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
def test_ptrack_stream(self):
"""make node, make full and ptrack stream backups, restore them and check data correctness"""
self.maxDiff = None
@ -99,7 +180,7 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
# Clean after yourself
self.del_test_dir(module_name, fname)
#@unittest.skip("skip")
# @unittest.skip("skip")
def test_ptrack_archive(self):
"""make archive node, make full and ptrack backups, check data correctness in restored instance"""
self.maxDiff = None
@ -157,7 +238,7 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
# Clean after yourself
self.del_test_dir(module_name, fname)
#@unittest.skip("skip")
# @unittest.skip("skip")
def test_ptrack_pgpro417(self):
"""Make node, take full backup, take ptrack backup, delete ptrack backup. Try to take ptrack backup, which should fail"""
self.maxDiff = None
@ -202,14 +283,13 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
self.assertEqual(1, 0, "Expecting Error because of LSN mismatch from ptrack_control and previous backup start_lsn.\n Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertTrue('ERROR: LSN from ptrack_control' in e.message
and 'differs from LSN of previous backup' in e.message,
self.assertTrue('ERROR: LSN from ptrack_control' in e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
# Clean after yourself
self.del_test_dir(module_name, fname)
#@unittest.skip("skip")
# @unittest.skip("skip")
def test_page_pgpro417(self):
"""Make archive node, take full backup, take page backup, delete page backup. Try to take ptrack backup, which should fail"""
self.maxDiff = None
@ -241,6 +321,7 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
backup_id = self.backup_node(backup_dir, 'node', node, backup_type='page')
self.delete_pb(backup_dir, 'node', backup_id)
# sys.exit(1)
# PTRACK BACKUP
node.safe_psql(
@ -253,14 +334,13 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
self.assertEqual(1, 0, "Expecting Error because of LSN mismatch from ptrack_control and previous backup start_lsn.\n Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertTrue('ERROR: LSN from ptrack_control' in e.message
and 'differs from LSN of previous backup' in e.message,
self.assertTrue('ERROR: LSN from ptrack_control' in e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
# Clean after yourself
# self.del_test_dir(module_name, fname)
#@unittest.skip("skip")
# @unittest.skip("skip")
def test_full_pgpro417(self):
"""Make node, take two full backups, delete full second backup. Try to take ptrack backup, which should fail"""
self.maxDiff = None
@ -303,14 +383,13 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertTrue('ERROR: LSN from ptrack_control' in e.message
and 'differs from LSN of previous backup' in e.message
and 'Create new full backup before an incremental one' in e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
# Clean after yourself
self.del_test_dir(module_name, fname)
#@unittest.skip("skip")
# @unittest.skip("skip")
def test_create_db(self):
"""Make node, take full backup, create database db1, take ptrack backup, restore database and check it presense"""
self.maxDiff = None
@ -319,11 +398,12 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
set_replication=True,
initdb_params=['--data-checksums'],
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', 'checkpoint_timeout': '30s', 'ptrack_enable': 'on', 'autovacuum': 'off'}
pg_options={'wal_level': 'replica', 'max_wal_size': '10GB', 'max_wal_senders': '2', 'checkpoint_timeout': '5min', 'ptrack_enable': 'on', 'autovacuum': 'off'}
)
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node)
node.start()
# FULL BACKUP
@ -337,41 +417,40 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
node.safe_psql("db1", "create table t_heap as select i as id, md5(i::text) as text, md5(i::text)::tsvector as tsvector from generate_series(0,100) i")
# PTRACK BACKUP
node.safe_psql("postgres", "checkpoint")
pgdata = self.pgdata_content(node.data_dir)
backup_id = self.backup_node(backup_dir, 'node', node, backup_type='ptrack', options=["--stream"])
pgdata_content = self.pgdata_content(node.data_dir)
# RESTORE
node_restored = self.make_simple_node(base_dir="{0}/{1}/node_restored".format(module_name, fname))
node_restored.cleanup()
# COMPARE PHYSICAL CONTENT
self.restore_node(backup_dir, 'node', node_restored, backup_id=backup_id, options=["-j", "4"])
pgdata_content_new = self.pgdata_content(node_restored.data_dir)
self.compare_pgdata(pgdata_content, pgdata_content_new)
pgdata_new = self.pgdata_content(node_restored.data_dir)
self.compare_pgdata(pgdata, pgdata_new)
# START RESTORED NODE
node_restored.append_conf("postgresql.auto.conf", "port = {0}".format(node_restored.port))
node_restored.start()
result_new = node_restored.safe_psql("postgres", "select * from pg_class")
# result_new = node_restored.safe_psql("postgres", "select * from pg_class")
# DROP DATABASE DB1
node.safe_psql(
"postgres", "drop database db1")
# SECOND PTRACK BACKUP
backup_id = self.backup_node(backup_dir, 'node', node, backup_type='ptrack', options=["--stream"])
pgdata_content = self.pgdata_content(node.data_dir)
# RESTORE SECOND PTRACK BACKUP
node_restored.cleanup()
self.restore_node(backup_dir, 'node', node_restored, backup_id=backup_id, options=["-j", "4"])
# COMPARE PHYSICAL CONTENT
pgdata_content_new = self.pgdata_content(node_restored.data_dir)
self.compare_pgdata(pgdata_content, pgdata_content_new)
# START RESTORED NODE
node_restored.append_conf("postgresql.auto.conf", "port = {0}".format(node_restored.port))
node_restored.start()
# COMPARE PHYSICAL CONTENT
#pgdata = self.pgdata_content(node.data_dir)
#pgdata_new = self.pgdata_content(node_restored.data_dir)
#self.compare_pgdata(pgdata, pgdata_new)
try:
node_restored.safe_psql('db1', 'select 1')
@ -385,7 +464,7 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
# Clean after yourself
self.del_test_dir(module_name, fname)
#@unittest.skip("skip")
# @unittest.skip("skip")
def test_alter_table_set_tablespace_ptrack(self):
"""Make node, create tablespace with table, take full backup, alter tablespace location, take ptrack backup, restore database."""
self.maxDiff = None
@ -442,7 +521,7 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
# Clean after yourself
self.del_test_dir(module_name, fname)
#@unittest.skip("skip")
# @unittest.skip("skip")
def test_alter_database_set_tablespace_ptrack(self):
"""Make node, create tablespace with database, take full backup, alter tablespace location, take ptrack backup, restore database."""
self.maxDiff = None
@ -489,7 +568,7 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
# Clean after yourself
self.del_test_dir(module_name, fname)
#@unittest.skip("skip")
# @unittest.skip("skip")
def test_drop_tablespace(self):
"""Make node, create table, alter table tablespace, take ptrack backup, move table from tablespace, take ptrack backup"""
self.maxDiff = None
@ -549,7 +628,7 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
# Clean after yourself
self.del_test_dir(module_name, fname)
#@unittest.skip("skip")
# @unittest.skip("skip")
def test_alter_tablespace(self):
"""Make node, create table, alter table tablespace, take ptrack backup, move table from tablespace, take ptrack backup"""
self.maxDiff = None
@ -606,17 +685,17 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
node.safe_psql(
"postgres", "alter table t_heap set tablespace pg_default")
# SECOND PTRACK BACKUP
node.safe_psql("template1", "checkpoint")
self.backup_node(backup_dir, 'node', node, backup_type='ptrack', options=["--stream"])
pgdata_content = self.pgdata_content(node.data_dir)
# Restore second ptrack backup and check table consistency
self.restore_node(backup_dir, 'node', restored_node, options=[
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new)])
pgdata_content_new = self.pgdata_content(restored_node.data_dir)
self.compare_pgdata(pgdata_content, pgdata_content_new)
restored_node.append_conf("postgresql.auto.conf", "port = {0}".format(restored_node.port))
restored_node.start()
# COMPARE PHYSICAL CONTENT
#pgdata = self.pgdata_content(node.data_dir)
#pgdata_new = self.pgdata_content(restored_node.data_dir)
#self.compare_pgdata(pgdata, pgdata_new)
result_new = restored_node.safe_psql("postgres", "select * from t_heap")
self.assertEqual(result, result_new)