Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fb1eb3c

Browse files
committed
tests: minor fixes, backup_test PEP8
1 parent d6a2d36 commit fb1eb3c

File tree

1 file changed

+107
-47
lines changed

1 file changed

+107
-47
lines changed

tests/backup_test.py

Lines changed: 107 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ class BackupTest(ProbackupTest, unittest.TestCase):
1515
def test_backup_modes_archive(self):
1616
"""standart backup modes with ARCHIVE WAL method"""
1717
fname = self.id().split('.')[3]
18-
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
18+
node = self.make_simple_node(
19+
base_dir="{0}/{1}/node".format(module_name, fname),
1920
initdb_params=['--data-checksums'],
20-
pg_options={'wal_level': 'replica', 'ptrack_enable': 'on'}
21+
pg_options={
22+
'wal_level': 'replica',
23+
'ptrack_enable': 'on'}
2124
)
2225
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
2326
self.init_pb(backup_dir)
@@ -26,7 +29,7 @@ def test_backup_modes_archive(self):
2629
node.start()
2730

2831
# full backup mode
29-
#with open(path.join(node.logs_dir, "backup_full.log"), "wb") as backup_log:
32+
# with open(path.join(node.logs_dir, "backup_full.log"), "wb") as backup_log:
3033
# backup_log.write(self.backup_node(node, options=["--verbose"]))
3134

3235
backup_id = self.backup_node(backup_dir, 'node', node)
@@ -37,15 +40,23 @@ def test_backup_modes_archive(self):
3740

3841
# postmaster.pid and postmaster.opts shouldn't be copied
3942
excluded = True
40-
db_dir = os.path.join(backup_dir, "backups", 'node', backup_id, "database")
43+
db_dir = os.path.join(
44+
backup_dir, "backups", 'node', backup_id, "database")
45+
4146
for f in os.listdir(db_dir):
42-
if os.path.isfile(os.path.join(db_dir, f)) \
43-
and (f == "postmaster.pid" or f == "postmaster.opts"):
44-
excluded = False
45-
self.assertEqual(excluded, True)
47+
if (
48+
os.path.isfile(os.path.join(db_dir, f)) and
49+
(
50+
f == "postmaster.pid" or
51+
f == "postmaster.opts"
52+
)
53+
):
54+
excluded = False
55+
self.assertEqual(excluded, True)
4656

4757
# page backup mode
48-
page_backup_id = self.backup_node(backup_dir, 'node', node, backup_type="page")
58+
page_backup_id = self.backup_node(
59+
backup_dir, 'node', node, backup_type="page")
4960

5061
# print self.show_pb(node)
5162
show_backup = self.show_pb(backup_dir, 'node')[1]
@@ -55,7 +66,9 @@ def test_backup_modes_archive(self):
5566
# Check parent backup
5667
self.assertEqual(
5768
backup_id,
58-
self.show_pb(backup_dir, 'node', backup_id=show_backup['ID'])["parent-backup-id"])
69+
self.show_pb(
70+
backup_dir, 'node',
71+
backup_id=show_backup['ID'])["parent-backup-id"])
5972

6073
# ptrack backup mode
6174
self.backup_node(backup_dir, 'node', node, backup_type="ptrack")
@@ -67,7 +80,9 @@ def test_backup_modes_archive(self):
6780
# Check parent backup
6881
self.assertEqual(
6982
page_backup_id,
70-
self.show_pb(backup_dir, 'node', backup_id=show_backup['ID'])["parent-backup-id"])
83+
self.show_pb(
84+
backup_dir, 'node',
85+
backup_id=show_backup['ID'])["parent-backup-id"])
7186

7287
# Clean after yourself
7388
self.del_test_dir(module_name, fname)
@@ -76,17 +91,20 @@ def test_backup_modes_archive(self):
7691
def test_smooth_checkpoint(self):
7792
"""full backup with smooth checkpoint"""
7893
fname = self.id().split('.')[3]
79-
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
94+
node = self.make_simple_node(
95+
base_dir="{0}/{1}/node".format(module_name, fname),
8096
initdb_params=['--data-checksums'],
8197
pg_options={'wal_level': 'replica'}
82-
)
98+
)
8399
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
84100
self.init_pb(backup_dir)
85101
self.add_instance(backup_dir, 'node', node)
86102
self.set_archiving(backup_dir, 'node', node)
87103
node.start()
88104

89-
self.backup_node(backup_dir, 'node' ,node, options=["-C"])
105+
self.backup_node(
106+
backup_dir, 'node', node,
107+
options=["-C"])
90108
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
91109
node.stop()
92110

@@ -97,7 +115,8 @@ def test_smooth_checkpoint(self):
97115
def test_incremental_backup_without_full(self):
98116
"""page-level backup without validated full backup"""
99117
fname = self.id().split('.')[3]
100-
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
118+
node = self.make_simple_node(
119+
base_dir="{0}/{1}/node".format(module_name, fname),
101120
initdb_params=['--data-checksums'],
102121
pg_options={'wal_level': 'replica', 'ptrack_enable': 'on'}
103122
)
@@ -110,28 +129,40 @@ def test_incremental_backup_without_full(self):
110129
try:
111130
self.backup_node(backup_dir, 'node', node, backup_type="page")
112131
# we should die here because exception is what we expect to happen
113-
self.assertEqual(1, 0, "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}".format(
114-
repr(self.output), self.cmd))
132+
self.assertEqual(
133+
1, 0,
134+
"Expecting Error because page backup should not be possible "
135+
"without valid full backup.\n Output: {0} \n CMD: {1}".format(
136+
repr(self.output), self.cmd))
115137
except ProbackupException as e:
116138
self.assertIn(
117-
"ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.",
139+
"ERROR: Valid backup on current timeline is not found. "
140+
"Create new FULL backup before an incremental one.",
118141
e.message,
119-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(repr(e.message), self.cmd))
142+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
143+
repr(e.message), self.cmd))
120144

121145
sleep(1)
122146

123147
try:
124148
self.backup_node(backup_dir, 'node', node, backup_type="ptrack")
125149
# we should die here because exception is what we expect to happen
126-
self.assertEqual(1, 0, "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}".format(
127-
repr(self.output), self.cmd))
150+
self.assertEqual(
151+
1, 0,
152+
"Expecting Error because page backup should not be possible "
153+
"without valid full backup.\n Output: {0} \n CMD: {1}".format(
154+
repr(self.output), self.cmd))
128155
except ProbackupException as e:
129156
self.assertIn(
130-
"ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.",
157+
"ERROR: Valid backup on current timeline is not found. "
158+
"Create new FULL backup before an incremental one.",
131159
e.message,
132-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(repr(e.message), self.cmd))
160+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
161+
repr(e.message), self.cmd))
133162

134-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "ERROR")
163+
self.assertEqual(
164+
self.show_pb(backup_dir, 'node')[0]['Status'],
165+
"ERROR")
135166

136167
# Clean after yourself
137168
self.del_test_dir(module_name, fname)
@@ -140,7 +171,8 @@ def test_incremental_backup_without_full(self):
140171
def test_incremental_backup_corrupt_full(self):
141172
"""page-level backup with corrupted full backup"""
142173
fname = self.id().split('.')[3]
143-
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
174+
node = self.make_simple_node(
175+
base_dir="{0}/{1}/node".format(module_name, fname),
144176
initdb_params=['--data-checksums'],
145177
pg_options={'wal_level': 'replica', 'ptrack_enable': 'on'}
146178
)
@@ -151,35 +183,50 @@ def test_incremental_backup_corrupt_full(self):
151183
node.start()
152184

153185
backup_id = self.backup_node(backup_dir, 'node', node)
154-
file = os.path.join(backup_dir, "backups", "node", backup_id, "database", "postgresql.conf")
186+
file = os.path.join(
187+
backup_dir, "backups", "node", backup_id,
188+
"database", "postgresql.conf")
155189
os.remove(file)
156190

157191
try:
158192
self.validate_pb(backup_dir, 'node')
159193
# we should die here because exception is what we expect to happen
160-
self.assertEqual(1, 0, "Expecting Error because of validation of corrupted backup.\n Output: {0} \n CMD: {1}".format(
161-
repr(self.output), self.cmd))
194+
self.assertEqual(
195+
1, 0,
196+
"Expecting Error because of validation of corrupted backup.\n"
197+
" Output: {0} \n CMD: {1}".format(
198+
repr(self.output), self.cmd))
162199
except ProbackupException as e:
163-
self.assertTrue("INFO: Validate backups of the instance 'node'\n" in e.message
164-
and 'WARNING: Backup file "{0}" is not found\n'.format(file) in e.message
165-
and "WARNING: Backup {0} data files are corrupted\n".format(backup_id) in e.message
166-
and "INFO: Some backups are not valid\n" in e.message,
167-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(repr(e.message), self.cmd))
200+
self.assertTrue(
201+
"INFO: Validate backups of the instance 'node'\n" in e.message and
202+
"WARNING: Backup file \"{0}\" is not found\n".format(
203+
file) in e.message and
204+
"WARNING: Backup {0} data files are corrupted\n".format(
205+
backup_id) in e.message and
206+
"INFO: Some backups are not valid\n" in e.message,
207+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
208+
repr(e.message), self.cmd))
168209

169210
try:
170211
self.backup_node(backup_dir, 'node', node, backup_type="page")
171212
# we should die here because exception is what we expect to happen
172-
self.assertEqual(1, 0, "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}".format(
173-
repr(self.output), self.cmd))
213+
self.assertEqual(
214+
1, 0,
215+
"Expecting Error because page backup should not be possible "
216+
"without valid full backup.\n Output: {0} \n CMD: {1}".format(
217+
repr(self.output), self.cmd))
174218
except ProbackupException as e:
175219
self.assertIn(
176-
"ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.",
220+
"ERROR: Valid backup on current timeline is not found. "
221+
"Create new FULL backup before an incremental one.",
177222
e.message,
178-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(repr(e.message), self.cmd))
223+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
224+
repr(e.message), self.cmd))
179225

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")
226+
self.assertEqual(
227+
self.show_pb(backup_dir, 'node', backup_id)['status'], "CORRUPT")
228+
self.assertEqual(
229+
self.show_pb(backup_dir, 'node')[1]['Status'], "ERROR")
183230

184231
# Clean after yourself
185232
self.del_test_dir(module_name, fname)
@@ -188,7 +235,8 @@ def test_incremental_backup_corrupt_full(self):
188235
def test_ptrack_threads(self):
189236
"""ptrack multi thread backup mode"""
190237
fname = self.id().split('.')[3]
191-
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
238+
node = self.make_simple_node(
239+
base_dir="{0}/{1}/node".format(module_name, fname),
192240
initdb_params=['--data-checksums'],
193241
pg_options={'wal_level': 'replica', 'ptrack_enable': 'on'}
194242
)
@@ -198,10 +246,14 @@ def test_ptrack_threads(self):
198246
self.set_archiving(backup_dir, 'node', node)
199247
node.start()
200248

201-
self.backup_node(backup_dir, 'node', node, backup_type="full", options=["-j", "4"])
249+
self.backup_node(
250+
backup_dir, 'node', node,
251+
backup_type="full", options=["-j", "4"])
202252
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
203253

204-
self.backup_node(backup_dir, 'node', node, backup_type="ptrack", options=["-j", "4"])
254+
self.backup_node(
255+
backup_dir, 'node', node,
256+
backup_type="ptrack", options=["-j", "4"])
205257
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
206258

207259
# Clean after yourself
@@ -211,20 +263,28 @@ def test_ptrack_threads(self):
211263
def test_ptrack_threads_stream(self):
212264
"""ptrack multi thread backup mode and stream"""
213265
fname = self.id().split('.')[3]
214-
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
266+
node = self.make_simple_node(
267+
base_dir="{0}/{1}/node".format(module_name, fname),
215268
set_replication=True,
216269
initdb_params=['--data-checksums'],
217-
pg_options={'wal_level': 'replica', 'ptrack_enable': 'on', 'max_wal_senders': '2'}
270+
pg_options={
271+
'wal_level': 'replica',
272+
'ptrack_enable': 'on',
273+
'max_wal_senders': '2'}
218274
)
219275
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
220276
self.init_pb(backup_dir)
221277
self.add_instance(backup_dir, 'node', node)
222278
node.start()
223279

224-
self.backup_node(backup_dir, 'node', node, backup_type="full", options=["-j", "4", "--stream"])
280+
self.backup_node(
281+
backup_dir, 'node', node, backup_type="full",
282+
options=["-j", "4", "--stream"])
225283

226284
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
227-
self.backup_node(backup_dir, 'node', node, backup_type="ptrack", options=["-j", "4", "--stream"])
285+
self.backup_node(
286+
backup_dir, 'node', node,
287+
backup_type="ptrack", options=["-j", "4", "--stream"])
228288
self.assertEqual(self.show_pb(backup_dir, 'node')[1]['Status'], "OK")
229289

230290
# Clean after yourself

0 commit comments

Comments
 (0)