Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commited7b187

Browse files
Probackup plugin is updated
Probackup plugin tests - They are skipped if PGPROBACKUPBIN is not definedGlobal variable init_params is None when PGPROBACKUPBIN is not defined or version is not processed
1 parentf7f163d commited7b187

File tree

2 files changed

+91
-68
lines changed

2 files changed

+91
-68
lines changed
Lines changed: 78 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__importannotations
2+
13
importlogging
24
fromfunctoolsimportreduce
35
importgetpass
@@ -37,21 +39,27 @@
3739

3840
classInit(object):
3941
def__init__(self):
42+
pass
43+
44+
@staticmethod
45+
defcreate()->Init:
46+
SELF=__class__()
47+
4048
if'-v'insys.argvor'--verbose'insys.argv:
41-
self.verbose=True
49+
SELF.verbose=True
4250
else:
43-
self.verbose=False
44-
45-
self._pg_config=testgres.get_pg_config()
46-
self.is_enterprise=self._pg_config.get('PGPRO_EDITION',None)=='enterprise'
47-
self.is_shardman=self._pg_config.get('PGPRO_EDITION',None)=='shardman'
48-
self.is_pgpro='PGPRO_EDITION'inself._pg_config
49-
self.is_nls_enabled='enable-nls'inself._pg_config['CONFIGURE']
50-
self.is_lz4_enabled='-llz4'inself._pg_config['LIBS']
51-
version=self._pg_config['VERSION'].rstrip('develalphabetapre')
51+
SELF.verbose=False
52+
53+
SELF._pg_config=testgres.get_pg_config()
54+
SELF.is_enterprise=SELF._pg_config.get('PGPRO_EDITION',None)=='enterprise'
55+
SELF.is_shardman=SELF._pg_config.get('PGPRO_EDITION',None)=='shardman'
56+
SELF.is_pgpro='PGPRO_EDITION'inSELF._pg_config
57+
SELF.is_nls_enabled='enable-nls'inSELF._pg_config['CONFIGURE']
58+
SELF.is_lz4_enabled='-llz4'inSELF._pg_config['LIBS']
59+
version=SELF._pg_config['VERSION'].rstrip('develalphabetapre')
5260
parts= [*version.split(' ')[1].split('.'),'0','0'][:3]
5361
parts[0]=re.match(r'\d+',parts[0]).group()
54-
self.pg_config_version=reduce(lambdav,x:v*100+int(x),parts,0)
62+
SELF.pg_config_version=reduce(lambdav,x:v*100+int(x),parts,0)
5563

5664
os.environ['LANGUAGE']='en'# set default locale language to en. All messages will use this locale
5765
test_env=os.environ.copy()
@@ -75,31 +83,31 @@ def __init__(self):
7583

7684
test_env['LC_MESSAGES']='C'
7785
test_env['LC_TIME']='C'
78-
self._test_env=test_env
86+
SELF._test_env=test_env
7987

8088
# Get the directory from which the script was executed
81-
self.source_path=os.getcwd()
89+
SELF.source_path=os.getcwd()
8290
tmp_path=test_env.get('PGPROBACKUP_TMP_DIR')
8391
iftmp_pathandos.path.isabs(tmp_path):
84-
self.tmp_path=tmp_path
92+
SELF.tmp_path=tmp_path
8593
else:
86-
self.tmp_path=os.path.abspath(
87-
os.path.join(self.source_path,tmp_pathoros.path.join('tests','tmp_dirs'))
94+
SELF.tmp_path=os.path.abspath(
95+
os.path.join(SELF.source_path,tmp_pathoros.path.join('tests','tmp_dirs'))
8896
)
8997

90-
os.makedirs(self.tmp_path,exist_ok=True)
98+
os.makedirs(SELF.tmp_path,exist_ok=True)
9199

92-
self.username=getpass.getuser()
100+
SELF.username=getpass.getuser()
93101

94-
self.probackup_path=None
102+
SELF.probackup_path=None
95103
if'PGPROBACKUPBIN'intest_env:
96104
ifshutil.which(test_env["PGPROBACKUPBIN"]):
97-
self.probackup_path=test_env["PGPROBACKUPBIN"]
105+
SELF.probackup_path=test_env["PGPROBACKUPBIN"]
98106
else:
99-
ifself.verbose:
107+
ifSELF.verbose:
100108
print('PGPROBACKUPBIN is not an executable file')
101109

102-
ifnotself.probackup_path:
110+
ifnotSELF.probackup_path:
103111
probackup_path_tmp=os.path.join(
104112
testgres.get_pg_config()['BINDIR'],'pg_probackup')
105113

@@ -108,116 +116,118 @@ def __init__(self):
108116
logging.warning('{0} is not an executable file'.format(
109117
probackup_path_tmp))
110118
else:
111-
self.probackup_path=probackup_path_tmp
119+
SELF.probackup_path=probackup_path_tmp
112120

113-
ifnotself.probackup_path:
114-
probackup_path_tmp=self.source_path
121+
ifnotSELF.probackup_path:
122+
probackup_path_tmp=SELF.source_path
115123

116124
ifos.path.isfile(probackup_path_tmp):
117125
ifnotos.access(probackup_path_tmp,os.X_OK):
118126
logging.warning('{0} is not an executable file'.format(
119127
probackup_path_tmp))
120128
else:
121-
self.probackup_path=probackup_path_tmp
129+
SELF.probackup_path=probackup_path_tmp
122130

123-
ifnotself.probackup_path:
131+
ifnotSELF.probackup_path:
124132
logging.error('pg_probackup binary is not found')
125-
exit(1)
133+
returnNone
126134

127135
ifos.name=='posix':
128-
self.EXTERNAL_DIRECTORY_DELIMITER=':'
136+
SELF.EXTERNAL_DIRECTORY_DELIMITER=':'
129137
os.environ['PATH']=os.path.dirname(
130-
self.probackup_path)+':'+os.environ['PATH']
138+
SELF.probackup_path)+':'+os.environ['PATH']
131139

132140
elifos.name=='nt':
133-
self.EXTERNAL_DIRECTORY_DELIMITER=';'
141+
SELF.EXTERNAL_DIRECTORY_DELIMITER=';'
134142
os.environ['PATH']=os.path.dirname(
135-
self.probackup_path)+';'+os.environ['PATH']
143+
SELF.probackup_path)+';'+os.environ['PATH']
136144

137-
self.probackup_old_path=None
145+
SELF.probackup_old_path=None
138146
if'PGPROBACKUPBIN_OLD'intest_env:
139147
if (os.path.isfile(test_env['PGPROBACKUPBIN_OLD'])andos.access(test_env['PGPROBACKUPBIN_OLD'],os.X_OK)):
140-
self.probackup_old_path=test_env['PGPROBACKUPBIN_OLD']
148+
SELF.probackup_old_path=test_env['PGPROBACKUPBIN_OLD']
141149
else:
142-
ifself.verbose:
150+
ifSELF.verbose:
143151
print('PGPROBACKUPBIN_OLD is not an executable file')
144152

145-
self.probackup_version=None
146-
self.old_probackup_version=None
153+
SELF.probackup_version=None
154+
SELF.old_probackup_version=None
147155

148156
probackup_version_output=subprocess.check_output(
149-
[self.probackup_path,"--version"],
157+
[SELF.probackup_path,"--version"],
150158
stderr=subprocess.STDOUT,
151159
).decode('utf-8')
152160
match=re.search(r"\d+\.\d+\.\d+",
153161
probackup_version_output)
154-
self.probackup_version=match.group(0)ifmatchelseNone
162+
SELF.probackup_version=match.group(0)ifmatchelseNone
155163
match=re.search(r"\(compressions: ([^)]*)\)",probackup_version_output)
156164
compressions=match.group(1)ifmatchelseNone
157165
ifcompressions:
158-
self.probackup_compressions= {s.strip()forsincompressions.split(',')}
166+
SELF.probackup_compressions= {s.strip()forsincompressions.split(',')}
159167
else:
160-
self.probackup_compressions= []
168+
SELF.probackup_compressions= []
161169

162-
ifself.probackup_old_path:
170+
ifSELF.probackup_old_path:
163171
old_probackup_version_output=subprocess.check_output(
164-
[self.probackup_old_path,"--version"],
172+
[SELF.probackup_old_path,"--version"],
165173
stderr=subprocess.STDOUT,
166174
).decode('utf-8')
167175
match=re.search(r"\d+\.\d+\.\d+",
168176
old_probackup_version_output)
169-
self.old_probackup_version=match.group(0)ifmatchelseNone
177+
SELF.old_probackup_version=match.group(0)ifmatchelseNone
170178

171-
self.remote=test_env.get('PGPROBACKUP_SSH_REMOTE',None)=='ON'
172-
self.ptrack=test_env.get('PG_PROBACKUP_PTRACK',None)=='ON'andself.pg_config_version>=110000
173-
self.wal_tree_enabled=test_env.get('PG_PROBACKUP_WAL_TREE_ENABLED',None)=='ON'
179+
SELF.remote=test_env.get('PGPROBACKUP_SSH_REMOTE',None)=='ON'
180+
SELF.ptrack=test_env.get('PG_PROBACKUP_PTRACK',None)=='ON'andSELF.pg_config_version>=110000
181+
SELF.wal_tree_enabled=test_env.get('PG_PROBACKUP_WAL_TREE_ENABLED',None)=='ON'
174182

175-
self.bckp_source=test_env.get('PG_PROBACKUP_SOURCE','pro').lower()
176-
ifself.bckp_sourcenotin ('base','direct','pro'):
183+
SELF.bckp_source=test_env.get('PG_PROBACKUP_SOURCE','pro').lower()
184+
ifSELF.bckp_sourcenotin ('base','direct','pro'):
177185
raiseException("Wrong PG_PROBACKUP_SOURCE value. Available options: base|direct|pro")
178186

179-
self.paranoia=test_env.get('PG_PROBACKUP_PARANOIA',None)=='ON'
187+
SELF.paranoia=test_env.get('PG_PROBACKUP_PARANOIA',None)=='ON'
180188
env_compress=test_env.get('ARCHIVE_COMPRESSION',None)
181189
ifenv_compress:
182190
env_compress=env_compress.lower()
183191
ifenv_compressin ('on','zlib'):
184-
self.compress_suffix='.gz'
185-
self.archive_compress='zlib'
192+
SELF.compress_suffix='.gz'
193+
SELF.archive_compress='zlib'
186194
elifenv_compress=='lz4':
187195
ifnotHAVE_LZ4:
188196
raiseLZ4_error
189-
if'lz4'notinself.probackup_compressions:
197+
if'lz4'notinSELF.probackup_compressions:
190198
raiseException("pg_probackup is not compiled with lz4 support")
191-
self.compress_suffix='.lz4'
192-
self.archive_compress='lz4'
199+
SELF.compress_suffix='.lz4'
200+
SELF.archive_compress='lz4'
193201
elifenv_compress=='zstd':
194202
ifnotHAVE_ZSTD:
195203
raiseZSTD_error
196-
if'zstd'notinself.probackup_compressions:
204+
if'zstd'notinSELF.probackup_compressions:
197205
raiseException("pg_probackup is not compiled with zstd support")
198-
self.compress_suffix='.zst'
199-
self.archive_compress='zstd'
206+
SELF.compress_suffix='.zst'
207+
SELF.archive_compress='zstd'
200208
else:
201-
self.compress_suffix=''
202-
self.archive_compress=False
209+
SELF.compress_suffix=''
210+
SELF.archive_compress=False
203211

204212
cfs_compress=test_env.get('PG_PROBACKUP_CFS_COMPRESS',None)
205213
ifcfs_compress:
206-
self.cfs_compress=cfs_compress.lower()
214+
SELF.cfs_compress=cfs_compress.lower()
207215
else:
208-
self.cfs_compress=self.archive_compress
216+
SELF.cfs_compress=SELF.archive_compress
209217

210218
os.environ["PGAPPNAME"]="pg_probackup"
211-
self.delete_logs=delete_logs
219+
SELF.delete_logs=delete_logs
212220

213-
ifself.probackup_version.split('.')[0].isdigit():
214-
self.major_version=int(self.probackup_version.split('.')[0])
221+
ifSELF.probackup_version.split('.')[0].isdigit():
222+
SELF.major_version=int(SELF.probackup_version.split('.')[0])
215223
else:
216-
logging.error('Can\'t process pg_probackup version\"{}\": the major version is expected to be a number'.format(self.probackup_version))
217-
sys.exit(1)
224+
logging.error('Can\'t process pg_probackup version\"{}\": the major version is expected to be a number'.format(SELF.probackup_version))
225+
returnNone
226+
227+
returnSELF
218228

219229
deftest_env(self):
220230
returnself._test_env.copy()
221231

222232

223-
init_params=Init()
233+
init_params=Init.create()

‎testgres/plugins/pg_probackup2/pg_probackup2/tests/test_basic.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
classProbackupTest:
1414
pg_node:testgres.PostgresNode
1515

16+
@staticmethod
17+
defprobackup_is_available()->bool:
18+
p=os.environ.get("PGPROBACKUPBIN")
19+
20+
ifpisNone:
21+
returnFalse
22+
23+
ifnotos.path.exists(p):
24+
returnFalse
25+
26+
returnTrue
27+
1628
@pytest.fixture(autouse=True,scope="function")
1729
defimplicit_fixture(self,request:pytest.FixtureRequest):
1830
assertisinstance(request,pytest.FixtureRequest)
@@ -60,6 +72,7 @@ def helper__build_backup_dir(self, backup='backup'):
6072
returnFSTestBackupDir(rel_path=self.rel_path,backup=backup)
6173

6274

75+
@pytest.mark.skipif(notProbackupTest.probackup_is_available(),reason="Check that PGPROBACKUPBIN is defined and is valid.")
6376
classTestBasic(ProbackupTest):
6477
deftest_full_backup(self):
6578
# Setting up a simple test node

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp