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

Commit0051f44

Browse files
committed
fix yapf pattern usage in node.py
1 parente00a16d commit0051f44

File tree

2 files changed

+40
-53
lines changed

2 files changed

+40
-53
lines changed

‎testgres/consts.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@
2525
UTILS_LOG_FILE="utils.log"
2626
BACKUP_LOG_FILE="backup.log"
2727

28-
# default replication slots number
29-
REPLICATION_SLOTS=10
28+
# defaults for node settings
29+
MAX_REPLICATION_SLOTS=10
30+
MAX_WAL_SENDERS=10
31+
WAL_KEEP_SEGMENTS=20

‎testgres/node.py‎

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@
3232
RECOVERY_CONF_FILE, \
3333
PG_LOG_FILE, \
3434
UTILS_LOG_FILE, \
35-
PG_PID_FILE, \
36-
REPLICATION_SLOTS
35+
PG_PID_FILE
36+
37+
from .constsimport \
38+
MAX_WAL_SENDERS, \
39+
MAX_REPLICATION_SLOTS, \
40+
WAL_KEEP_SEGMENTS
3741

3842
from .decoratorsimport \
3943
method_decorator, \
@@ -292,12 +296,11 @@ def _create_recovery_conf(self, username, slot=None):
292296
master=self.master
293297
assertmasterisnotNone
294298

295-
# yapf: disable
296299
conninfo= (
297300
u"application_name={} "
298301
u"port={} "
299302
u"user={} "
300-
).format(self.name,master.port,username)
303+
).format(self.name,master.port,username)# yapf: disable
301304

302305
# host is tricky
303306
try:
@@ -307,11 +310,10 @@ def _create_recovery_conf(self, username, slot=None):
307310
exceptValueError:
308311
conninfo+=u"host={}".format(master.host)
309312

310-
# yapf: disable
311313
line= (
312314
"primary_conninfo='{}'\n"
313315
"standby_mode=on\n"
314-
).format(conninfo)
316+
).format(conninfo)# yapf: disable
315317

316318
ifslot:
317319
# Connect to master for some additional actions
@@ -325,7 +327,8 @@ def _create_recovery_conf(self, username, slot=None):
325327
""",slot)
326328

327329
ifres[0][0]:
328-
raiseTestgresException("Slot '{}' already exists".format(slot))
330+
raiseTestgresException(
331+
"Slot '{}' already exists".format(slot))
329332

330333
# TODO: we should drop this slot after replica's cleanup()
331334
con.execute("""
@@ -357,7 +360,7 @@ def _collect_special_files(self):
357360
(os.path.join(self.data_dir,RECOVERY_CONF_FILE),0),
358361
(os.path.join(self.data_dir,HBA_CONF_FILE),0),
359362
(self.pg_log_file,testgres_config.error_log_lines)
360-
]
363+
]# yapf: disable
361364

362365
forf,num_linesinfiles:
363366
# skip missing files
@@ -392,9 +395,10 @@ def init(self, initdb_params=None, **kwargs):
392395
"""
393396

394397
# initialize this PostgreSQL node
395-
cached_initdb(data_dir=self.data_dir,
396-
logfile=self.utils_log_file,
397-
params=initdb_params)
398+
cached_initdb(
399+
data_dir=self.data_dir,
400+
logfile=self.utils_log_file,
401+
params=initdb_params)
398402

399403
# initialize default config files
400404
self.default_conf(**kwargs)
@@ -446,12 +450,11 @@ def get_auth_method(t):
446450
auth_local=get_auth_method('local')
447451
auth_host=get_auth_method('host')
448452

449-
# yapf: disable
450453
new_lines= [
451454
u"local\treplication\tall\t\t\t{}\n".format(auth_local),
452455
u"host\treplication\tall\t127.0.0.1/32\t{}\n".format(auth_host),
453456
u"host\treplication\tall\t::1/128\t\t{}\n".format(auth_host)
454-
]
457+
]# yapf: disable
455458

456459
# write missing lines
457460
forlineinnew_lines:
@@ -466,12 +469,11 @@ def get_auth_method(t):
466469
ifnotfsync:
467470
conf.write(u"fsync = off\n")
468471

469-
# yapf: disable
470472
conf.write(u"log_statement = {}\n"
471473
u"listen_addresses = '{}'\n"
472474
u"port = {}\n".format(log_statement,
473475
self.host,
474-
self.port))
476+
self.port))# yapf: disable
475477

476478
# replication-related settings
477479
ifallow_streaming:
@@ -482,17 +484,14 @@ def get_auth_method(t):
482484
else:
483485
wal_level="hot_standby"
484486

485-
# yapf: disable
486-
max_wal_senders=10# default in PG 10
487-
wal_keep_segments=20# for convenience
488487
conf.write(u"hot_standby = on\n"
489488
u"max_wal_senders = {}\n"
490489
u"max_replication_slots = {}\n"
491490
u"wal_keep_segments = {}\n"
492-
u"wal_level = {}\n".format(max_wal_senders,
493-
REPLICATION_SLOTS,
494-
wal_keep_segments,
495-
wal_level))
491+
u"wal_level = {}\n".format(MAX_WAL_SENDERS,
492+
MAX_REPLICATION_SLOTS,
493+
WAL_KEEP_SEGMENTS,
494+
wal_level))# yapf: disable
496495

497496
# disable UNIX sockets if asked to
498497
ifnotunix_sockets:
@@ -528,12 +527,11 @@ def status(self):
528527
"""
529528

530529
try:
531-
# yapf: disable
532530
_params= [
533531
get_bin_path("pg_ctl"),
534532
"-D",self.data_dir,
535533
"status"
536-
]
534+
]# yapf: disable
537535
execute_utility(_params,self.utils_log_file)
538536
returnNodeStatus.Running
539537

@@ -577,14 +575,13 @@ def start(self, params=[]):
577575
This instance of PostgresNode.
578576
"""
579577

580-
# yapf: disable
581578
_params= [
582579
get_bin_path("pg_ctl"),
583580
"-D",self.data_dir,
584581
"-l",self.pg_log_file,
585582
"-w",# wait
586583
"start"
587-
]+params
584+
]+params# yapf: disable
588585

589586
try:
590587
execute_utility(_params,self.utils_log_file)
@@ -608,13 +605,12 @@ def stop(self, params=[]):
608605
This instance of PostgresNode.
609606
"""
610607

611-
# yapf: disable
612608
_params= [
613609
get_bin_path("pg_ctl"),
614610
"-D",self.data_dir,
615611
"-w",# wait
616612
"stop"
617-
]+params
613+
]+params# yapf: disable
618614

619615
execute_utility(_params,self.utils_log_file)
620616

@@ -633,14 +629,13 @@ def restart(self, params=[]):
633629
This instance of PostgresNode.
634630
"""
635631

636-
# yapf: disable
637632
_params= [
638633
get_bin_path("pg_ctl"),
639634
"-D",self.data_dir,
640635
"-l",self.pg_log_file,
641636
"-w",# wait
642637
"restart"
643-
]+params
638+
]+params# yapf: disable
644639

645640
try:
646641
execute_utility(_params,self.utils_log_file)
@@ -664,13 +659,12 @@ def reload(self, params=[]):
664659
This instance of PostgresNode.
665660
"""
666661

667-
# yapf: disable
668662
_params= [
669663
get_bin_path("pg_ctl"),
670664
"-D",self.data_dir,
671665
"-w",# wait
672666
"reload"
673-
]+params
667+
]+params# yapf: disable
674668

675669
execute_utility(_params,self.utils_log_file)
676670

@@ -685,12 +679,11 @@ def pg_ctl(self, params):
685679
Stdout + stderr of pg_ctl.
686680
"""
687681

688-
# yapf: disable
689682
_params= [
690683
get_bin_path("pg_ctl"),
691684
"-D",self.data_dir,
692685
"-w"# wait
693-
]+params
686+
]+params# yapf: disable
694687

695688
returnexecute_utility(_params,self.utils_log_file)
696689

@@ -753,7 +746,6 @@ def psql(self,
753746
dbname=dbnameordefault_dbname()
754747
username=usernameordefault_username()
755748

756-
# yapf: disable
757749
psql_params= [
758750
get_bin_path("psql"),
759751
"-p",str(self.port),
@@ -764,7 +756,7 @@ def psql(self,
764756
"-t",# print rows only
765757
"-q",# run quietly
766758
dbname
767-
]
759+
]# yapf: disable
768760

769761
# select query source
770762
ifquery:
@@ -831,15 +823,14 @@ def tmpfile():
831823
username=usernameordefault_username()
832824
filename=filenameortmpfile()
833825

834-
# yapf: disable
835826
_params= [
836827
get_bin_path("pg_dump"),
837828
"-p",str(self.port),
838829
"-h",self.host,
839830
"-f",filename,
840831
"-U",username,
841832
"-d",dbname
842-
]
833+
]# yapf: disable
843834

844835
execute_utility(_params,self.utils_log_file)
845836

@@ -948,7 +939,7 @@ def execute(self,
948939

949940
withself.connect(dbname=dbname,
950941
username=username,
951-
password=password)asnode_con:
942+
password=password)asnode_con:# yapf: disable
952943

953944
res=node_con.execute(query)
954945

@@ -1007,7 +998,7 @@ def catchup(self, dbname=None, username=None):
1007998
# fetch latest LSN
1008999
lsn=self.master.execute(query=poll_lsn,
10091000
dbname=dbname,
1010-
username=username)[0][0]
1001+
username=username)[0][0]# yapf: disable
10111002

10121003
# wait until this LSN reaches replica
10131004
self.poll_query_until(
@@ -1042,13 +1033,12 @@ def pgbench(self,
10421033
dbname=dbnameordefault_dbname()
10431034
username=usernameordefault_username()
10441035

1045-
# yapf: disable
10461036
_params= [
10471037
get_bin_path("pgbench"),
10481038
"-p",str(self.port),
10491039
"-h",self.host,
10501040
"-U",username,
1051-
]+options
1041+
]+options# yapf: disable
10521042

10531043
# should be the last one
10541044
_params.append(dbname)
@@ -1070,11 +1060,7 @@ def pgbench_init(self, **kwargs):
10701060

10711061
returnself
10721062

1073-
defpgbench_run(self,
1074-
dbname=None,
1075-
username=None,
1076-
options=[],
1077-
**kwargs):
1063+
defpgbench_run(self,dbname=None,username=None,options=[],**kwargs):
10781064
"""
10791065
Run pgbench with some options.
10801066
This event is logged (see self.utils_log_file).
@@ -1098,13 +1084,12 @@ def pgbench_run(self,
10981084
dbname=dbnameordefault_dbname()
10991085
username=usernameordefault_username()
11001086

1101-
# yapf: disable
11021087
_params= [
11031088
get_bin_path("pgbench"),
11041089
"-p",str(self.port),
11051090
"-h",self.host,
11061091
"-U",username,
1107-
]+options
1092+
]+options# yapf: disable
11081093

11091094
forkey,valueiniteritems(kwargs):
11101095
# rename keys for pgbench
@@ -1114,7 +1099,7 @@ def pgbench_run(self,
11141099
ifnotisinstance(value,bool):
11151100
_params.append('--{}={}'.format(key,value))
11161101
else:
1117-
assertvalueisTrue# just in case
1102+
assertvalueisTrue# just in case
11181103
_params.append('--{}'.format(key))
11191104

11201105
# should be the last one
@@ -1138,4 +1123,4 @@ def connect(self, dbname=None, username=None, password=None):
11381123
returnNodeConnection(node=self,
11391124
dbname=dbname,
11401125
username=username,
1141-
password=password)
1126+
password=password)# yapf: disable

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp