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

Commit8b6b813

Browse files
demonolockvshepard
and
vshepard
authored
Remove polling (#137)
* Change print on logging* Normalize error---------Co-authored-by: vshepard <v.shepard@postgrespro.ru>
1 parent1d68e91 commit8b6b813

File tree

9 files changed

+40
-24
lines changed

9 files changed

+40
-24
lines changed

‎testgres/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
importatexit
44
importcopy
5+
importlogging
6+
importos
57
importtempfile
68

79
fromcontextlibimportcontextmanager
@@ -10,6 +12,10 @@
1012
from .operations.os_opsimportOsOperations
1113
from .operations.local_opsimportLocalOperations
1214

15+
log_level=os.getenv('LOGGING_LEVEL','WARNING').upper()
16+
log_format=os.getenv('LOGGING_FORMAT','%(asctime)s - %(levelname)s - %(message)s').upper()
17+
logging.basicConfig(level=log_level,format=log_format)
18+
1319

1420
classGlobalConfig(object):
1521
"""

‎testgres/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# coding: utf-8
2+
importlogging
23

34
# we support both pg8000 and psycopg2
45
try:
@@ -110,7 +111,7 @@ def execute(self, query, *args):
110111
exceptProgrammingError:
111112
returnNone
112113
exceptExceptionase:
113-
print("Error executing query: {}\n {}".format(repr(e),query))
114+
logging.error("Error executing query: {}\n {}".format(repr(e),query))
114115
returnNone
115116

116117
defclose(self):

‎testgres/node.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding: utf-8
2-
2+
importlogging
33
importos
44
importrandom
55
importsignal
@@ -736,11 +736,10 @@ def start(self, params=[], wait=True):
736736
ifany(len(file)>1and'Is another postmaster already '
737737
'running on port'infile[1].decode()for
738738
fileinfiles):
739-
print("Detected an issue with connecting to port {0}. "
740-
"Trying another port after a 5-second sleep...".format(self.port))
739+
logging.warning("Detected an issue with connecting to port {0}. "
740+
"Trying another port after a 5-second sleep...".format(self.port))
741741
self.port=reserve_port()
742-
options= {}
743-
options['port']=str(self.port)
742+
options= {'port':str(self.port)}
744743
self.set_auto_conf(options)
745744
startup_retries-=1
746745
time.sleep(5)
@@ -1166,7 +1165,6 @@ def poll_query_until(self,
11661165
assertsleep_time>0
11671166
attempts=0
11681167
whilemax_attempts==0orattempts<max_attempts:
1169-
print(f"Pooling{attempts}")
11701168
try:
11711169
res=self.execute(dbname=dbname,
11721170
query=query,
@@ -1190,6 +1188,7 @@ def poll_query_until(self,
11901188
return# done
11911189

11921190
excepttuple(suppressor []):
1191+
logging.info(f"Trying execute, attempt{attempts+1}.\nQuery:{query}")
11931192
pass# we're suppressing them
11941193

11951194
time.sleep(sleep_time)

‎testgres/operations/local_ops.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importgetpass
2+
importlogging
23
importos
34
importshutil
45
importstat
@@ -165,9 +166,9 @@ def rmdirs(self, path, ignore_errors=True, retries=3, delay=1):
165166
exceptFileNotFoundError:
166167
returnTrue
167168
exceptExceptionase:
168-
print(f"Error: Failed to remove directory{path} on attempt{attempt+1}:{e}")
169+
logging.error(f"Error: Failed to remove directory{path} on attempt{attempt+1}:{e}")
169170
time.sleep(delay)
170-
print(f"Error: Failed to remove directory{path} after{retries} attempts.")
171+
logging.error(f"Error: Failed to remove directory{path} after{retries} attempts.")
171172
returnFalse
172173

173174
deflistdir(self,path):

‎testgres/operations/remote_ops.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
9393
ifnoterror:
9494
error_found=0
9595
else:
96+
error=normalize_error(error)
9697
error_found=exit_status!=0orany(
97-
markerinerrorformarkerin [b'error',b'Permission denied',b'fatal',b'No such file or directory'])
98+
markerinerrorformarkerin ['error','Permission denied','fatal','No such file or directory']
99+
)
98100

99101
iferror_found:
100102
ifisinstance(error,bytes):
@@ -369,3 +371,9 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
369371
password=password,
370372
)
371373
returnconn
374+
375+
376+
defnormalize_error(error):
377+
ifisinstance(error,bytes):
378+
returnerror.decode()
379+
returnerror

‎testgres/plugins/pg_probackup2/pg_probackup2/app.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
importcontextlib
22
importimportlib
33
importjson
4+
importlogging
45
importos
56
importre
67
importsubprocess
@@ -74,7 +75,7 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
7475
command= [command[0],*self.backup_dir.pb_args,*command[1:]]
7576

7677
ifnotself.probackup_old_pathandold_binary:
77-
print('PGPROBACKUPBIN_OLD is not set')
78+
logging.error('PGPROBACKUPBIN_OLD is not set')
7879
exit(1)
7980

8081
ifold_binary:
@@ -107,12 +108,11 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
107108
returnGDBobj(cmdline,self.test_class)
108109

109110
try:
110-
result=None
111111
iftype(gdb)istupleandgdb[0]=='suspend':
112112
# special test flow for manually debug probackup
113113
gdb_port=gdb[1]
114114
cmdline= ['gdbserver']+ ['localhost:'+str(gdb_port)]+cmdline
115-
print("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}".format(gdb_port))
115+
logging.warning("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}".format(gdb_port))
116116

117117
start_time=time.time()
118118
self.test_class.output=subprocess.check_output(
@@ -233,7 +233,7 @@ def backup_node(
233233
ifoptionsisNone:
234234
options= []
235235
ifnotnodeandnotdata_dir:
236-
print('You must provide ether node or data_dir for backup')
236+
logging.error('You must provide ether node or data_dir for backup')
237237
exit(1)
238238

239239
ifnotdatname:
@@ -502,7 +502,7 @@ def show(
502502
ifi=='':
503503
backup_record_split.remove(i)
504504
iflen(header_split)!=len(backup_record_split):
505-
print(warning.format(
505+
logging.error(warning.format(
506506
header=header,body=body,
507507
header_split=header_split,
508508
body_split=backup_record_split)
@@ -581,7 +581,7 @@ def show_archive(
581581
else:
582582
show_splitted=self.run(cmd_list+options,old_binary=old_binary,
583583
expect_error=expect_error).splitlines()
584-
print(show_splitted)
584+
logging.error(show_splitted)
585585
exit(1)
586586

587587
defvalidate(
@@ -769,7 +769,7 @@ def load_backup_class(fs_type):
769769
iffs_type:
770770
implementation=fs_type
771771

772-
print("Using ",implementation)
772+
logging.info("Using ",implementation)
773773
module_name,class_name=implementation.rsplit(sep='.',maxsplit=1)
774774

775775
module=importlib.import_module(module_name)

‎testgres/plugins/pg_probackup2/pg_probackup2/init_helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
importlogging
12
fromfunctoolsimportreduce
23
importgetpass
34
importos
@@ -31,7 +32,7 @@
3132
cached_initdb_dir=False,
3233
node_cleanup_full=delete_logs)
3334
exceptExceptionase:
34-
print("Can't configure testgres: {0}".format(e))
35+
logging.warning("Can't configure testgres: {0}".format(e))
3536

3637

3738
classInit(object):
@@ -104,7 +105,7 @@ def __init__(self):
104105

105106
ifos.path.isfile(probackup_path_tmp):
106107
ifnotos.access(probackup_path_tmp,os.X_OK):
107-
print('{0} is not an executable file'.format(
108+
logging.warning('{0} is not an executable file'.format(
108109
probackup_path_tmp))
109110
else:
110111
self.probackup_path=probackup_path_tmp
@@ -114,13 +115,13 @@ def __init__(self):
114115

115116
ifos.path.isfile(probackup_path_tmp):
116117
ifnotos.access(probackup_path_tmp,os.X_OK):
117-
print('{0} is not an executable file'.format(
118+
logging.warning('{0} is not an executable file'.format(
118119
probackup_path_tmp))
119120
else:
120121
self.probackup_path=probackup_path_tmp
121122

122123
ifnotself.probackup_path:
123-
print('pg_probackup binary is not found')
124+
logging.error('pg_probackup binary is not found')
124125
exit(1)
125126

126127
ifos.name=='posix':
@@ -207,7 +208,7 @@ def __init__(self):
207208
ifself.probackup_version.split('.')[0].isdigit():
208209
self.major_version=int(self.probackup_version.split('.')[0])
209210
else:
210-
print('Can\'t process pg_probackup version\"{}\": the major version is expected to be a number'.format(self.probackup_version))
211+
logging.error('Can\'t process pg_probackup version\"{}\": the major version is expected to be a number'.format(self.probackup_version))
211212
sys.exit(1)
212213

213214
deftest_env(self):

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
importlogging
12
importos
23
importshutil
34
importunittest
@@ -14,7 +15,7 @@ def get_module_and_function_name(test_id):
1415
module_name=test_id.split('.')[-2]
1516
fname=test_id.split('.')[-1]
1617
exceptIndexError:
17-
print(f"Couldn't get module name and function name from test_id: `{test_id}`")
18+
logging.warning(f"Couldn't get module name and function name from test_id: `{test_id}`")
1819
module_name,fname=test_id.split('(')[1].split('.')[1],test_id.split('(')[0]
1920
returnmodule_name,fname
2021

‎testgres/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ def eprint(*args, **kwargs):
228228
"""
229229
Print stuff to stderr.
230230
"""
231-
232231
print(*args,file=sys.stderr,**kwargs)
233232

234233

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp