1
1
import unittest
2
2
import os
3
- import six
4
3
from 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
7
7
8
8
9
9
class BackupTest (ProbackupTest ,unittest .TestCase ):
@@ -12,10 +12,6 @@ def __init__(self, *args, **kwargs):
12
12
super (BackupTest ,self ).__init__ (* args ,** kwargs )
13
13
self .module_name = 'backup'
14
14
15
- @classmethod
16
- def tearDownClass (cls ):
17
- stop_all ()
18
-
19
15
# @unittest.skip("skip")
20
16
# @unittest.expectedFailure
21
17
# PGPRO-707
@@ -39,8 +35,8 @@ def test_backup_modes_archive(self):
39
35
backup_id = self .backup_node (backup_dir ,'node' ,node )
40
36
show_backup = self .show_pb (backup_dir ,'node' )[0 ]
41
37
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" )
44
40
45
41
# postmaster.pid and postmaster.opts shouldn't be copied
46
42
excluded = True
@@ -56,8 +52,8 @@ def test_backup_modes_archive(self):
56
52
57
53
# print self.show_pb(node)
58
54
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" )
61
57
62
58
# Check parent backup
63
59
self .assertEqual (
@@ -68,15 +64,16 @@ def test_backup_modes_archive(self):
68
64
self .backup_node (backup_dir ,'node' ,node ,backup_type = "ptrack" )
69
65
70
66
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" )
73
69
74
70
# Check parent backup
75
71
self .assertEqual (
76
72
page_backup_id ,
77
73
self .show_pb (backup_dir ,'node' ,backup_id = show_backup ['ID' ])["parent-backup-id" ])
78
74
79
- node .stop ()
75
+ # Clean after yourself
76
+ self .del_test_dir (self .module_name ,fname )
80
77
81
78
# @unittest.skip("skip")
82
79
def test_smooth_checkpoint (self ):
@@ -93,9 +90,12 @@ def test_smooth_checkpoint(self):
93
90
node .start ()
94
91
95
92
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" )
97
94
node .stop ()
98
95
96
+ # Clean after yourself
97
+ self .del_test_dir (self .module_name ,fname )
98
+
99
99
#@unittest.skip("skip")
100
100
def test_incremental_backup_without_full (self ):
101
101
"""page-level backup without validated full backup"""
@@ -115,7 +115,7 @@ def test_incremental_backup_without_full(self):
115
115
# we should die here because exception is what we expect to happen
116
116
self .assertEqual (1 ,0 ,"Expecting Error because page backup should not be possible without valid full backup.\n Output: {0}\n CMD: {1}" .format (
117
117
repr (self .output ),self .cmd ))
118
- except ProbackupException , e :
118
+ except ProbackupException as e :
119
119
self .assertEqual (e .message ,
120
120
'ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n ' ,
121
121
'\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):
127
127
# we should die here because exception is what we expect to happen
128
128
self .assertEqual (1 ,0 ,"Expecting Error because page backup should not be possible without valid full backup.\n Output: {0}\n CMD: {1}" .format (
129
129
repr (self .output ),self .cmd ))
130
- except ProbackupException , e :
130
+ except ProbackupException as e :
131
131
self .assertEqual (e .message ,
132
132
'ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n ' ,
133
133
'\n Unexpected Error Message: {0}\n CMD: {1}' .format (repr (e .message ),self .cmd ))
134
134
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 )
137
139
138
- @unittest .expectedFailure
139
- # Need to forcibly validate parent
140
+ # @unittest.expectedFailure
140
141
def test_incremental_backup_corrupt_full (self ):
141
142
"""page-level backup with corrupted full backup"""
142
143
fname = self .id ().split ('.' )[3 ]
@@ -151,29 +152,37 @@ def test_incremental_backup_corrupt_full(self):
151
152
node .start ()
152
153
153
154
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" )
155
156
os .remove (file )
156
157
157
158
try :
158
- self .backup_node (backup_dir ,'node' , node , backup_type = "page" )
159
+ self .validate_pb (backup_dir ,'node' )
159
160
# we should die here because exception is what we expect to happen
160
- self .assertEqual (1 ,0 ,"Expecting Error becausepage backup should not be possible without valid full backup.\n Output: {0}\n CMD: {1}" .format (
161
+ self .assertEqual (1 ,0 ,"Expecting Error becauseof validation of corrupted backup.\n Output: {0}\n CMD: {1}" .format (
161
162
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 ))
166
169
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
168
173
self .assertEqual (1 ,0 ,"Expecting Error because page backup should not be possible without valid full backup.\n Output: {0}\n CMD: {1}" .format (
169
174
repr (self .output ),self .cmd ))
170
- except ProbackupException , e :
175
+ except ProbackupException as e :
171
176
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 ))
174
179
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 )
177
186
178
187
# @unittest.skip("skip")
179
188
def test_ptrack_threads (self ):
@@ -190,12 +199,13 @@ def test_ptrack_threads(self):
190
199
node .start ()
191
200
192
201
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" )
194
203
195
204
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" )
197
206
198
- node .stop ()
207
+ # Clean after yourself
208
+ self .del_test_dir (self .module_name ,fname )
199
209
200
210
# @unittest.skip("skip")
201
211
def test_ptrack_threads_stream (self ):
@@ -213,7 +223,9 @@ def test_ptrack_threads_stream(self):
213
223
214
224
self .backup_node (backup_dir ,'node' ,node ,backup_type = "full" ,options = ["-j" ,"4" ,"--stream" ])
215
225
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" )
217
227
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 )