3232RECOVERY_CONF_FILE , \
3333PG_LOG_FILE , \
3434UTILS_LOG_FILE , \
35- PG_PID_FILE , \
36- REPLICATION_SLOTS
35+ PG_PID_FILE
36+
37+ from .consts import \
38+ MAX_WAL_SENDERS , \
39+ MAX_REPLICATION_SLOTS , \
40+ WAL_KEEP_SEGMENTS
3741
3842from .decorators import \
3943method_decorator , \
@@ -292,12 +296,11 @@ def _create_recovery_conf(self, username, slot=None):
292296master = self .master
293297assert master is not None
294298
295- # yapf: disable
296299conninfo = (
297300u"application_name={} "
298301u"port={} "
299302u"user={} "
300- ).format (self .name ,master .port ,username )
303+ ).format (self .name ,master .port ,username )# yapf: disable
301304
302305# host is tricky
303306try :
@@ -307,11 +310,10 @@ def _create_recovery_conf(self, username, slot=None):
307310except ValueError :
308311conninfo += u"host={}" .format (master .host )
309312
310- # yapf: disable
311313line = (
312314"primary_conninfo='{}'\n "
313315"standby_mode=on\n "
314- ).format (conninfo )
316+ ).format (conninfo )# yapf: disable
315317
316318if slot :
317319# Connect to master for some additional actions
@@ -325,7 +327,8 @@ def _create_recovery_conf(self, username, slot=None):
325327 """ ,slot )
326328
327329if res [0 ][0 ]:
328- raise TestgresException ("Slot '{}' already exists" .format (slot ))
330+ raise TestgresException (
331+ "Slot '{}' already exists" .format (slot ))
329332
330333# TODO: we should drop this slot after replica's cleanup()
331334con .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
362365for f ,num_lines in files :
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
400404self .default_conf (** kwargs )
@@ -446,12 +450,11 @@ def get_auth_method(t):
446450auth_local = get_auth_method ('local' )
447451auth_host = get_auth_method ('host' )
448452
449- # yapf: disable
450453new_lines = [
451454u"local\t replication\t all\t \t \t {}\n " .format (auth_local ),
452455u"host\t replication\t all\t 127.0.0.1/32\t {}\n " .format (auth_host ),
453456u"host\t replication\t all\t ::1/128\t \t {}\n " .format (auth_host )
454- ]
457+ ]# yapf: disable
455458
456459# write missing lines
457460for line in new_lines :
@@ -466,12 +469,11 @@ def get_auth_method(t):
466469if not fsync :
467470conf .write (u"fsync = off\n " )
468471
469- # yapf: disable
470472conf .write (u"log_statement = {}\n "
471473u"listen_addresses = '{}'\n "
472474u"port = {}\n " .format (log_statement ,
473475self .host ,
474- self .port ))
476+ self .port ))# yapf: disable
475477
476478# replication-related settings
477479if allow_streaming :
@@ -482,17 +484,14 @@ def get_auth_method(t):
482484else :
483485wal_level = "hot_standby"
484486
485- # yapf: disable
486- max_wal_senders = 10 # default in PG 10
487- wal_keep_segments = 20 # for convenience
488487conf .write (u"hot_standby = on\n "
489488u"max_wal_senders = {}\n "
490489u"max_replication_slots = {}\n "
491490u"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
498497if not unix_sockets :
@@ -528,12 +527,11 @@ def status(self):
528527 """
529528
530529try :
531- # yapf: disable
532530_params = [
533531get_bin_path ("pg_ctl" ),
534532"-D" ,self .data_dir ,
535533"status"
536- ]
534+ ]# yapf: disable
537535execute_utility (_params ,self .utils_log_file )
538536return NodeStatus .Running
539537
@@ -577,14 +575,13 @@ def start(self, params=[]):
577575 This instance of PostgresNode.
578576 """
579577
580- # yapf: disable
581578_params = [
582579get_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
589586try :
590587execute_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 = [
613609get_bin_path ("pg_ctl" ),
614610"-D" ,self .data_dir ,
615611"-w" ,# wait
616612"stop"
617- ]+ params
613+ ]+ params # yapf: disable
618614
619615execute_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 = [
638633get_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
645640try :
646641execute_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 = [
669663get_bin_path ("pg_ctl" ),
670664"-D" ,self .data_dir ,
671665"-w" ,# wait
672666"reload"
673- ]+ params
667+ ]+ params # yapf: disable
674668
675669execute_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 = [
690683get_bin_path ("pg_ctl" ),
691684"-D" ,self .data_dir ,
692685"-w" # wait
693- ]+ params
686+ ]+ params # yapf: disable
694687
695688return execute_utility (_params ,self .utils_log_file )
696689
@@ -753,7 +746,6 @@ def psql(self,
753746dbname = dbname or default_dbname ()
754747username = username or default_username ()
755748
756- # yapf: disable
757749psql_params = [
758750get_bin_path ("psql" ),
759751"-p" ,str (self .port ),
@@ -764,7 +756,7 @@ def psql(self,
764756"-t" ,# print rows only
765757"-q" ,# run quietly
766758dbname
767- ]
759+ ]# yapf: disable
768760
769761# select query source
770762if query :
@@ -831,15 +823,14 @@ def tmpfile():
831823username = username or default_username ()
832824filename = filename or tmpfile ()
833825
834- # yapf: disable
835826_params = [
836827get_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
844835execute_utility (_params ,self .utils_log_file )
845836
@@ -948,7 +939,7 @@ def execute(self,
948939
949940with self .connect (dbname = dbname ,
950941username = username ,
951- password = password )as node_con :
942+ password = password )as node_con :# yapf: disable
952943
953944res = node_con .execute (query )
954945
@@ -1007,7 +998,7 @@ def catchup(self, dbname=None, username=None):
1007998# fetch latest LSN
1008999lsn = self .master .execute (query = poll_lsn ,
10091000dbname = dbname ,
1010- username = username )[0 ][0 ]
1001+ username = username )[0 ][0 ]# yapf: disable
10111002
10121003# wait until this LSN reaches replica
10131004self .poll_query_until (
@@ -1042,13 +1033,12 @@ def pgbench(self,
10421033dbname = dbname or default_dbname ()
10431034username = username or default_username ()
10441035
1045- # yapf: disable
10461036_params = [
10471037get_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
10711061return self
10721062
1073- def pgbench_run (self ,
1074- dbname = None ,
1075- username = None ,
1076- options = [],
1077- ** kwargs ):
1063+ def pgbench_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,
10981084dbname = dbname or default_dbname ()
10991085username = username or default_username ()
11001086
1101- # yapf: disable
11021087_params = [
11031088get_bin_path ("pgbench" ),
11041089"-p" ,str (self .port ),
11051090"-h" ,self .host ,
11061091"-U" ,username ,
1107- ]+ options
1092+ ]+ options # yapf: disable
11081093
11091094for key ,value in iteritems (kwargs ):
11101095# rename keys for pgbench
@@ -1114,7 +1099,7 @@ def pgbench_run(self,
11141099if not isinstance (value ,bool ):
11151100_params .append ('--{}={}' .format (key ,value ))
11161101else :
1117- assert value is True # just in case
1102+ assert value is True # 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):
11381123return NodeConnection (node = self ,
11391124dbname = dbname ,
11401125username = username ,
1141- password = password )
1126+ password = password )# yapf: disable