11import unittest
22import os
3- import six
43from time import sleep
5- from helpers .ptrack_helpers import ProbackupTest , ProbackupException
6- from testgres import stop_all
4+ from .helpers .ptrack_helpers import ProbackupTest , ProbackupException
5+ from testgres import stop_all , clean_all
6+ import shutil
77
88
99class BackupTest (ProbackupTest , unittest .TestCase ):
@@ -12,10 +12,6 @@ def __init__(self, *args, **kwargs):
1212 super (BackupTest , self ).__init__ (* args , ** kwargs )
1313 self .module_name = 'backup'
1414
15- @classmethod
16- def tearDownClass (cls ):
17- stop_all ()
18-
1915 # @unittest.skip("skip")
2016 # @unittest.expectedFailure
2117 # PGPRO-707
@@ -39,8 +35,8 @@ def test_backup_modes_archive(self):
3935 backup_id = self .backup_node (backup_dir , 'node' , node )
4036 show_backup = self .show_pb (backup_dir , 'node' )[0 ]
4137
42- self .assertEqual (show_backup ['Status' ], six . b ( "OK" ) )
43- self .assertEqual (show_backup ['Mode' ], six . b ( "FULL" ) )
38+ self .assertEqual (show_backup ['Status' ], "OK" )
39+ self .assertEqual (show_backup ['Mode' ], "FULL" )
4440
4541 # postmaster.pid and postmaster.opts shouldn't be copied
4642 excluded = True
@@ -56,8 +52,8 @@ def test_backup_modes_archive(self):
5652
5753 # print self.show_pb(node)
5854 show_backup = self .show_pb (backup_dir , 'node' )[1 ]
59- self .assertEqual (show_backup ['Status' ], six . b ( "OK" ) )
60- self .assertEqual (show_backup ['Mode' ], six . b ( "PAGE" ) )
55+ self .assertEqual (show_backup ['Status' ], "OK" )
56+ self .assertEqual (show_backup ['Mode' ], "PAGE" )
6157
6258 # Check parent backup
6359 self .assertEqual (
@@ -68,15 +64,16 @@ def test_backup_modes_archive(self):
6864 self .backup_node (backup_dir , 'node' , node , backup_type = "ptrack" )
6965
7066 show_backup = self .show_pb (backup_dir , 'node' )[2 ]
71- self .assertEqual (show_backup ['Status' ], six . b ( "OK" ) )
72- self .assertEqual (show_backup ['Mode' ], six . b ( "PTRACK" ) )
67+ self .assertEqual (show_backup ['Status' ], "OK" )
68+ self .assertEqual (show_backup ['Mode' ], "PTRACK" )
7369
7470 # Check parent backup
7571 self .assertEqual (
7672 page_backup_id ,
7773 self .show_pb (backup_dir , 'node' , backup_id = show_backup ['ID' ])["parent-backup-id" ])
7874
79- node .stop ()
75+ # Clean after yourself
76+ self .del_test_dir (self .module_name , fname )
8077
8178 # @unittest.skip("skip")
8279 def test_smooth_checkpoint (self ):
@@ -93,9 +90,12 @@ def test_smooth_checkpoint(self):
9390 node .start ()
9491
9592 self .backup_node (backup_dir , 'node' ,node , options = ["-C" ])
96- self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], six . b ( "OK" ) )
93+ self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], "OK" )
9794 node .stop ()
9895
96+ # Clean after yourself
97+ self .del_test_dir (self .module_name , fname )
98+
9999 #@unittest.skip("skip")
100100 def test_incremental_backup_without_full (self ):
101101 """page-level backup without validated full backup"""
@@ -115,7 +115,7 @@ def test_incremental_backup_without_full(self):
115115 # we should die here because exception is what we expect to happen
116116 self .assertEqual (1 , 0 , "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}" .format (
117117 repr (self .output ), self .cmd ))
118- except ProbackupException , e :
118+ except ProbackupException as e :
119119 self .assertEqual (e .message ,
120120 'ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n ' ,
121121 '\n Unexpected Error Message: {0}\n CMD: {1}' .format (repr (e .message ), self .cmd ))
@@ -127,16 +127,17 @@ def test_incremental_backup_without_full(self):
127127 # we should die here because exception is what we expect to happen
128128 self .assertEqual (1 , 0 , "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}" .format (
129129 repr (self .output ), self .cmd ))
130- except ProbackupException , e :
130+ except ProbackupException as e :
131131 self .assertEqual (e .message ,
132132 'ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n ' ,
133133 '\n Unexpected Error Message: {0}\n CMD: {1}' .format (repr (e .message ), self .cmd ))
134134
135- self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], six .b ("ERROR" ))
136- node .stop ()
135+ self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], "ERROR" )
136+
137+ # Clean after yourself
138+ self .del_test_dir (self .module_name , fname )
137139
138- @unittest .expectedFailure
139- # Need to forcibly validate parent
140+ # @unittest.expectedFailure
140141 def test_incremental_backup_corrupt_full (self ):
141142 """page-level backup with corrupted full backup"""
142143 fname = self .id ().split ('.' )[3 ]
@@ -151,29 +152,37 @@ def test_incremental_backup_corrupt_full(self):
151152 node .start ()
152153
153154 backup_id = self .backup_node (backup_dir , 'node' , node )
154- file = os .path .join (backup_dir , "backups" , "node" , backup_id . decode ( "utf-8" ) , "database" , "postgresql.conf" )
155+ file = os .path .join (backup_dir , "backups" , "node" , backup_id , "database" , "postgresql.conf" )
155156 os .remove (file )
156157
157158 try :
158- self .backup_node (backup_dir , 'node' , node , backup_type = "page" )
159+ self .validate_pb (backup_dir , 'node' )
159160 # we should die here because exception is what we expect to happen
160- self .assertEqual (1 , 0 , "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}" .format (
161+ self .assertEqual (1 , 0 , "Expecting Error because of validation of corrupted backup.\n Output: {0} \n CMD: {1}" .format (
161162 repr (self .output ), self .cmd ))
162- except ProbackupException , e :
163- self .assertEqual (e .message ,
164- 'ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n ' ,
165- '\n Unexpected Error Message: {0}\n CMD: {1}' .format (repr (e .message ), self .cmd ))
163+ except ProbackupException as e :
164+ self .assertTrue ("INFO: Validate backups of the instance 'node'\n " in e .message
165+ and 'WARNING: Backup file "{0}" is not found\n ' .format (file ) in e .message
166+ and "WARNING: Backup {0} is corrupted\n " .format (backup_id ) in e .message
167+ and "INFO: Some backups are not valid\n " in e .message ,
168+ "\n Unexpected Error Message: {0}\n CMD: {1}" .format (repr (e .message ), self .cmd ))
166169
167- sleep (1 )
170+ try :
171+ self .backup_node (backup_dir , 'node' , node , backup_type = "page" )
172+ # we should die here because exception is what we expect to happen
168173 self .assertEqual (1 , 0 , "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}" .format (
169174 repr (self .output ), self .cmd ))
170- except ProbackupException , e :
175+ except ProbackupException as e :
171176 self .assertEqual (e .message ,
172- ' ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n ' ,
173- ' \n Unexpected Error Message: {0}\n CMD: {1}' .format (repr (e .message ), self .cmd ))
177+ " ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n " ,
178+ " \n Unexpected Error Message: {0}\n CMD: {1}" .format (repr (e .message ), self .cmd ))
174179
175- self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], six .b ("ERROR" ))
176- node .stop ()
180+ # sleep(1)
181+ self .assertEqual (self .show_pb (backup_dir , 'node' , backup_id )['status' ], "CORRUPT" )
182+ self .assertEqual (self .show_pb (backup_dir , 'node' )[1 ]['Status' ], "ERROR" )
183+
184+ # Clean after yourself
185+ self .del_test_dir (self .module_name , fname )
177186
178187 # @unittest.skip("skip")
179188 def test_ptrack_threads (self ):
@@ -190,12 +199,13 @@ def test_ptrack_threads(self):
190199 node .start ()
191200
192201 self .backup_node (backup_dir , 'node' , node , backup_type = "full" , options = ["-j" , "4" ])
193- self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], six . b ( "OK" ) )
202+ self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], "OK" )
194203
195204 self .backup_node (backup_dir , 'node' , node , backup_type = "ptrack" , options = ["-j" , "4" ])
196- self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], six . b ( "OK" ) )
205+ self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], "OK" )
197206
198- node .stop ()
207+ # Clean after yourself
208+ self .del_test_dir (self .module_name , fname )
199209
200210 # @unittest.skip("skip")
201211 def test_ptrack_threads_stream (self ):
@@ -213,7 +223,9 @@ def test_ptrack_threads_stream(self):
213223
214224 self .backup_node (backup_dir , 'node' , node , backup_type = "full" , options = ["-j" , "4" , "--stream" ])
215225
216- self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], six . b ( "OK" ) )
226+ self .assertEqual (self .show_pb (backup_dir , 'node' )[0 ]['Status' ], "OK" )
217227 self .backup_node (backup_dir , 'node' , node , backup_type = "ptrack" , options = ["-j" , "4" , "--stream" ])
218- self .assertEqual (self .show_pb (backup_dir , 'node' )[1 ]['Status' ], six .b ("OK" ))
219- node .stop ()
228+ self .assertEqual (self .show_pb (backup_dir , 'node' )[1 ]['Status' ], "OK" )
229+
230+ # Clean after yourself
231+ self .del_test_dir (self .module_name , fname )
0 commit comments