12
12
import re
13
13
import json
14
14
15
+ import errno
16
+ import unittest
17
+ from termcolor import colored
18
+
19
+
15
20
from time import sleep
16
21
from sys import exit , argv , version_info
17
22
18
23
#from testgres.utils import get_pg_edition
19
24
from testgres .utils import is_enterprise , is_nls_enabled
20
25
21
- class ProbackupException (Exception ):
26
+
27
+ # move to the settings.py with other global configurations
28
+ TEST_DIR = 'tmp_dirs'
29
+
30
+
31
+ class PGProbackupException (Exception ):
22
32
def __init__ (self , message , cmd ):
23
33
self .message = message
24
34
self .cmd = cmd
@@ -27,21 +37,60 @@ def __str__(self):
27
37
return '\n ERROR: {0}\n CMD: {1}' .format (repr (self .message ), self .cmd )
28
38
29
39
40
+ class PGProbackupApp (object ):
41
+ IS_ENTERPRISE = False
42
+
43
+ settings = dict ()
44
+ host = 'localhost'
45
+ tests_full_path = TEST_DIR # tmp_test_dirs
46
+
47
+
48
+ #def __new__(self, *args, **kwargs):
49
+ # pass
50
+
51
+ def __init__ (
52
+ self , tests_path = '.' , test_dir = TEST_DIR ,
53
+ * args , ** kwargs ):
54
+ pass
30
55
31
56
32
- class ProbackupTest (object ):
57
+ class PGProbackupTestCaseMixin (unittest .TestCase ):
58
+ def setUp (self ):
59
+ pass
60
+
61
+ def tearDown (self ):
62
+ pass
63
+
64
+
65
+
66
+ class PGProbackupPackageCompTestCaseMixin (PGProbackupTestCaseMixin ):
67
+ current_version = None
68
+ previous_version = None
69
+
70
+ def setUp (self ):
71
+ pass
72
+
73
+ def tearDown (self ):
74
+ pass
75
+
76
+
77
+
78
+
79
+ class ProbackupTest (object ):
33
80
# Class attributes
34
81
enterprise = is_enterprise ()
35
82
enable_nls = is_nls_enabled ()
36
83
37
84
def __init__ (self , * args , ** kwargs ):
38
85
super (ProbackupTest , self ).__init__ (* args , ** kwargs )
86
+
87
+ self .verbose = False
39
88
if '-v' in argv or '--verbose' in argv :
40
89
self .verbose = True
41
- else :
42
- self .verbose = False
90
+
43
91
44
92
self .test_env = os .environ .copy ()
93
+
45
94
envs_list = [
46
95
'LANGUAGE' ,
47
96
'LC_ALL' ,
@@ -75,28 +124,32 @@ def __init__(self, *args, **kwargs):
75
124
self .archive_compress = 'ARCHIVE_COMPRESSION' in self .test_env and \
76
125
self .test_env ['ARCHIVE_COMPRESSION' ] == 'ON'
77
126
78
- try :
79
- testgres .configure_testgres (
80
- cache_initdb = False ,
81
- cached_initdb_dir = False ,
82
- cache_pg_config = False ,
83
- node_cleanup_full = False )
84
- except :
85
- pass
86
-
87
- self .helpers_path = os .path .dirname (os .path .realpath (__file__ ))
88
- self .dir_path = os .path .abspath (
89
- os .path .join (self .helpers_path , os .pardir )
90
- )
91
- self .tmp_path = os .path .abspath (
92
- os .path .join (self .dir_path , 'tmp_dirs' )
93
- )
94
- try :
95
- os .makedirs (os .path .join (self .dir_path , 'tmp_dirs' ))
96
- except :
97
- pass
98
127
128
+ testgres .configure_testgres (
129
+ cache_initdb = False ,
130
+ cached_initdb_dir = False ,
131
+ cache_pg_config = False ,
132
+ node_cleanup_full = False )
133
+
134
+
135
+ # Choose path for the tests artifacts
136
+ self .tests_path = os .path .join (os .path .abspath ('.' ), TEST_DIR )
137
+ try :
138
+ os .makedirs (os .path .join (self .tests_path ))
139
+ log .info ('Artefacts from the tests are stored in the direcotry: %s' % self .tests_path )
140
+ except OSError as e :
141
+ if e .errno == errno .EEXIST :
142
+ pass
143
+ else :
144
+ # print(
145
+ # colored('Please choose directory for the tests artefacts with 777 chmod. [%s]'%self.tests_path, 'red'))
146
+ raise
147
+
148
+
149
+ # XXX dont work with
99
150
self .user = self .get_username ()
151
+
152
+
100
153
self .probackup_path = None
101
154
if 'PGPROBACKUPBIN' in self .test_env :
102
155
if (
@@ -108,6 +161,7 @@ def __init__(self, *args, **kwargs):
108
161
if self .verbose :
109
162
print ('PGPROBACKUPBIN is not an executable file' )
110
163
164
+ # XXX
111
165
print ('@@@' , self .probackup_path )
112
166
113
167
if not self .probackup_path :
@@ -162,18 +216,22 @@ def __init__(self, *args, **kwargs):
162
216
self .old_probackup_version = None
163
217
164
218
try :
219
+
165
220
self .probackup_version_output = subprocess .check_output (
166
221
[self .probackup_path , "--version" ],
167
222
stderr = subprocess .STDOUT ,
168
223
).decode ('utf-8' )
224
+
169
225
except subprocess .CalledProcessError as e :
170
- raise ProbackupException (e .output .decode ('utf-8' ))
226
+ raise PGProbackupException (e .output .decode ('utf-8' ))
171
227
172
228
if self .probackup_old_path :
229
+
173
230
old_probackup_version_output = subprocess .check_output (
174
231
[self .probackup_old_path , "--version" ],
175
232
stderr = subprocess .STDOUT ,
176
233
).decode ('utf-8' )
234
+
177
235
self .old_probackup_version = re .search (
178
236
r"\d+\.\d+\.\d+" ,
179
237
subprocess .check_output (
@@ -224,19 +282,26 @@ def pg_config_version(self):
224
282
# print('PGPROBACKUP_SSH_USER is not set')
225
283
# exit(1)
226
284
285
+
286
+ # XXX move to the node.PostgresNode
227
287
def make_empty_node (
228
288
self ,
229
289
base_dir = None ):
230
- real_base_dir = os .path .join (self .tmp_path , base_dir )
290
+
291
+ real_base_dir = os .path .join (self .tests_path , base_dir )
231
292
shutil .rmtree (real_base_dir , ignore_errors = True )
232
293
os .makedirs (real_base_dir )
233
294
234
295
node = testgres .get_new_node ('test' , base_dir = real_base_dir )
296
+
235
297
# bound method slow_start() to 'node' class instance
236
- node .slow_start = slow_start .__get__ (node )
298
+ #node.slow_start = slow_start.__get__(node)
299
+
237
300
node .should_rm_dirs = True
238
301
return node
239
302
303
+
304
+ # XXX preconfigured Node for the pg_probackup app
240
305
def make_simple_node (
241
306
self ,
242
307
base_dir = None ,
@@ -254,6 +319,8 @@ def make_simple_node(
254
319
node .major_version_str = str (f .read ().rstrip ())
255
320
node .major_version = float (node .major_version_str )
256
321
322
+ # XXX move it to the ProbackupTestCaseMixin class setUp
323
+
257
324
# Sane default parameters
258
325
options = {}
259
326
options ['max_connections' ] = 100
@@ -405,7 +472,7 @@ def get_md5_per_page_for_fork(self, file, size_in_pages):
405
472
406
473
size = size_in_pages
407
474
for segment_number in range (nsegments ):
408
- if size - 131072 > 0 :
475
+ if size - 131072 > 0 : # XXX make global static config PARAM
409
476
pages_per_segment [segment_number ] = 131072
410
477
else :
411
478
pages_per_segment [segment_number ] = size
@@ -427,7 +494,7 @@ def get_md5_per_page_for_fork(self, file, size_in_pages):
427
494
for page in range (start_page , end_page ):
428
495
md5_per_page [page ] = hashlib .md5 (
429
496
os .read (file_desc , 8192 )).hexdigest ()
430
- offset += 8192
497
+ offset += 8192 # XXX make global static config PARAM
431
498
os .lseek (file_desc , offset , 0 )
432
499
os .close (file_desc )
433
500
@@ -683,7 +750,7 @@ def run_pb(self, command, asynchronous=False, gdb=False, old_binary=False, retur
683
750
else :
684
751
return self .output
685
752
except subprocess .CalledProcessError as e :
686
- raise ProbackupException (e .output .decode ('utf-8' ), self .cmd )
753
+ raise PGProbackupException (e .output .decode ('utf-8' ), self .cmd )
687
754
688
755
def run_binary (self , command , asynchronous = False , env = None ):
689
756
@@ -709,7 +776,7 @@ def run_binary(self, command, asynchronous=False, env=None):
709
776
).decode ('utf-8' )
710
777
return self .output
711
778
except subprocess .CalledProcessError as e :
712
- raise ProbackupException (e .output .decode ('utf-8' ), command )
779
+ raise PGProbackupException (e .output .decode ('utf-8' ), command )
713
780
714
781
def init_pb (self , backup_dir , options = [], old_binary = False ):
715
782
@@ -1455,7 +1522,7 @@ def del_test_dir(self, module_name, fname):
1455
1522
1456
1523
shutil .rmtree (
1457
1524
os .path .join (
1458
- self .tmp_path ,
1525
+ self .tests_path ,
1459
1526
module_name ,
1460
1527
fname
1461
1528
),
0 commit comments