From e0d6c6bfc056c851385e51950d8cf5c114dba8a0 Mon Sep 17 00:00:00 2001 From: Grigory Smolkin Date: Fri, 19 Apr 2019 15:55:03 +0300 Subject: [PATCH] tests: added test_unlink_rotation_file --- tests/helpers/ptrack_helpers.py | 8 ++-- tests/logging.py | 83 ++++++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 10 deletions(-) diff --git a/tests/helpers/ptrack_helpers.py b/tests/helpers/ptrack_helpers.py index f2ae21e2..e7d89156 100644 --- a/tests/helpers/ptrack_helpers.py +++ b/tests/helpers/ptrack_helpers.py @@ -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, diff --git a/tests/logging.py b/tests/logging.py index 54462547..0333d951 100644 --- a/tests/logging.py +++ b/tests/logging.py @@ -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)