You've already forked pg_probackup
mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-09-16 09:26:30 +02:00
tests: added test_unlink_rotation_file
This commit is contained in:
@@ -579,7 +579,7 @@ class ProbackupTest(object):
|
||||
)
|
||||
)
|
||||
|
||||
def run_pb(self, command, asynchronous=False, gdb=False, old_binary=False):
|
||||
def run_pb(self, command, asynchronous=False, gdb=False, old_binary=False, return_id=True):
|
||||
if not self.probackup_old_path and old_binary:
|
||||
print('PGPROBACKUPBIN_OLD is not set')
|
||||
exit(1)
|
||||
@@ -608,7 +608,7 @@ class ProbackupTest(object):
|
||||
stderr=subprocess.STDOUT,
|
||||
env=self.test_env
|
||||
).decode('utf-8')
|
||||
if command[0] == 'backup':
|
||||
if command[0] == 'backup' and return_id:
|
||||
# return backup ID
|
||||
for line in self.output.splitlines():
|
||||
if 'INFO: Backup' and 'completed' in line:
|
||||
@@ -700,7 +700,7 @@ class ProbackupTest(object):
|
||||
def backup_node(
|
||||
self, backup_dir, instance, node, data_dir=False,
|
||||
backup_type='full', options=[], asynchronous=False, gdb=False,
|
||||
old_binary=False
|
||||
old_binary=False, return_id=True
|
||||
):
|
||||
if not node and not data_dir:
|
||||
print('You must provide ether node or data_dir for backup')
|
||||
@@ -730,7 +730,7 @@ class ProbackupTest(object):
|
||||
if backup_type:
|
||||
cmd_list += ['-b', backup_type]
|
||||
|
||||
return self.run_pb(cmd_list + options, asynchronous, gdb, old_binary)
|
||||
return self.run_pb(cmd_list + options, asynchronous, gdb, old_binary, return_id)
|
||||
|
||||
def checkdb_node(
|
||||
self, backup_dir=False, instance=False, data_dir=False,
|
||||
|
@@ -73,7 +73,7 @@ class LogTest(ProbackupTest, unittest.TestCase):
|
||||
# Clean after yourself
|
||||
self.del_test_dir(module_name, fname)
|
||||
|
||||
def test_truncated_rotation_file(self):
|
||||
def test_truncate_rotation_file(self):
|
||||
fname = self.id().split('.')[3]
|
||||
node = self.make_simple_node(
|
||||
base_dir=os.path.join(module_name, fname, 'node'),
|
||||
@@ -97,8 +97,7 @@ class LogTest(ProbackupTest, unittest.TestCase):
|
||||
backup_dir, 'node', node,
|
||||
options=[
|
||||
'--stream',
|
||||
'--log-level-file=VERBOSE',
|
||||
'--log-filename=pg_probackup.log'])
|
||||
'--log-level-file=VERBOSE'])
|
||||
|
||||
self.assertTrue(os.path.isfile(rotation_file_path))
|
||||
|
||||
@@ -108,14 +107,86 @@ class LogTest(ProbackupTest, unittest.TestCase):
|
||||
f.flush()
|
||||
f.close
|
||||
|
||||
self.backup_node(
|
||||
output = self.backup_node(
|
||||
backup_dir, 'node', node,
|
||||
options=[
|
||||
'--stream',
|
||||
'--log-level-file=VERBOSE',
|
||||
'--log-filename=pg_probackup.log'])
|
||||
'--log-level-file=VERBOSE'],
|
||||
return_id=False)
|
||||
|
||||
self.assertIn(
|
||||
'WARNING: cannot read creation timestamp from rotation file',
|
||||
output)
|
||||
|
||||
output = self.backup_node(
|
||||
backup_dir, 'node', node,
|
||||
options=[
|
||||
'--stream',
|
||||
'--log-level-file=VERBOSE'],
|
||||
return_id=False)
|
||||
|
||||
self.assertNotIn(
|
||||
'WARNING:',
|
||||
output)
|
||||
|
||||
self.assertTrue(os.path.isfile(rotation_file_path))
|
||||
|
||||
# Clean after yourself
|
||||
self.del_test_dir(module_name, fname)
|
||||
|
||||
def test_unlink_rotation_file(self):
|
||||
fname = self.id().split('.')[3]
|
||||
node = self.make_simple_node(
|
||||
base_dir=os.path.join(module_name, fname, 'node'),
|
||||
initdb_params=['--data-checksums'])
|
||||
|
||||
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
||||
self.init_pb(backup_dir)
|
||||
self.add_instance(backup_dir, 'node', node)
|
||||
node.slow_start()
|
||||
|
||||
self.set_config(
|
||||
backup_dir, 'node',
|
||||
options=['--log-rotation-age=1d'])
|
||||
|
||||
rotation_file_path = os.path.join(
|
||||
backup_dir, 'log', 'pg_probackup.log.rotation')
|
||||
|
||||
|
||||
self.backup_node(
|
||||
backup_dir, 'node', node,
|
||||
options=[
|
||||
'--stream',
|
||||
'--log-level-file=VERBOSE'])
|
||||
|
||||
self.assertTrue(os.path.isfile(rotation_file_path))
|
||||
|
||||
# unlink .rotation file
|
||||
os.unlink(rotation_file_path)
|
||||
|
||||
output = self.backup_node(
|
||||
backup_dir, 'node', node,
|
||||
options=[
|
||||
'--stream',
|
||||
'--log-level-file=VERBOSE'],
|
||||
return_id=False)
|
||||
|
||||
self.assertIn(
|
||||
'WARNING: missing rotation file:',
|
||||
output)
|
||||
|
||||
self.assertTrue(os.path.isfile(rotation_file_path))
|
||||
|
||||
output = self.backup_node(
|
||||
backup_dir, 'node', node,
|
||||
options=[
|
||||
'--stream',
|
||||
'--log-level-file=VERBOSE'],
|
||||
return_id=False)
|
||||
|
||||
self.assertNotIn(
|
||||
'WARNING:',
|
||||
output)
|
||||
|
||||
# Clean after yourself
|
||||
self.del_test_dir(module_name, fname)
|
||||
|
Reference in New Issue
Block a user