Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12fa7f2

Browse files
node_base.py is updated
Names from 'consts' module are used explicitly.
1 parent 3e9cad1 commit 12fa7f2

File tree

1 file changed

+21
-37
lines changed

1 file changed

+21
-37
lines changed

testgres/node_base.py

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,7 @@
3636

3737
from .connection import NodeConnection
3838

39-
from .consts import \
40-
TMP_DUMP, \
41-
PG_CONF_FILE, \
42-
PG_AUTO_CONF_FILE, \
43-
HBA_CONF_FILE, \
44-
RECOVERY_CONF_FILE, \
45-
PG_CTL__STATUS__OK, \
46-
PG_CTL__STATUS__NODE_IS_STOPPED, \
47-
PG_CTL__STATUS__BAD_DATADIR \
48-
49-
from .consts import \
50-
MAX_LOGICAL_REPLICATION_WORKERS, \
51-
MAX_REPLICATION_SLOTS, \
52-
MAX_WORKER_PROCESSES, \
53-
MAX_WAL_SENDERS, \
54-
WAL_KEEP_SEGMENTS, \
55-
WAL_KEEP_SIZE
39+
from . import consts
5640

5741
from .decorators import \
5842
method_decorator, \
@@ -205,15 +189,15 @@ def pid(self):
205189
assert type(error) == str # noqa: E721
206190

207191
# -----------------
208-
if status_code == PG_CTL__STATUS__NODE_IS_STOPPED:
192+
if status_code == consts.PG_CTL__STATUS__NODE_IS_STOPPED:
209193
return 0
210194

211195
# -----------------
212-
if status_code == PG_CTL__STATUS__BAD_DATADIR:
196+
if status_code == consts.PG_CTL__STATUS__BAD_DATADIR:
213197
return 0
214198

215199
# -----------------
216-
if status_code != PG_CTL__STATUS__OK:
200+
if status_code != consts.PG_CTL__STATUS__OK:
217201
errMsg = "Getting of a node status [data_dir is {0}] failed.".format(self__data_dir)
218202

219203
raise ExecUtilException(
@@ -225,7 +209,7 @@ def pid(self):
225209
)
226210

227211
# -----------------
228-
assert status_code == PG_CTL__STATUS__OK
212+
assert status_code == consts.PG_CTL__STATUS__OK
229213

230214
if out == "":
231215
__class__._throw_error__pg_ctl_returns_an_empty_string(
@@ -568,7 +552,7 @@ def _create_recovery_conf(self, username, slot=None):
568552
if self.version >= utils.PgVer('12'):
569553
self.append_conf(line=line)
570554
else:
571-
self.append_conf(filename=RECOVERY_CONF_FILE, line=line)
555+
self.append_conf(filename=consts.RECOVERY_CONF_FILE, line=line)
572556

573557
def _maybe_start_logger(self):
574558
if testgres_config.use_python_logging:
@@ -586,10 +570,10 @@ def _collect_special_files(self):
586570

587571
# list of important files + last N lines
588572
files = [
589-
(os.path.join(self.data_dir, PG_CONF_FILE), 0),
590-
(os.path.join(self.data_dir, PG_AUTO_CONF_FILE), 0),
591-
(os.path.join(self.data_dir, RECOVERY_CONF_FILE), 0),
592-
(os.path.join(self.data_dir, HBA_CONF_FILE), 0),
573+
(os.path.join(self.data_dir, consts.PG_CONF_FILE), 0),
574+
(os.path.join(self.data_dir, consts.PG_AUTO_CONF_FILE), 0),
575+
(os.path.join(self.data_dir, consts.RECOVERY_CONF_FILE), 0),
576+
(os.path.join(self.data_dir, consts.HBA_CONF_FILE), 0),
593577
(self.pg_log_file, testgres_config.error_log_lines)
594578
] # yapf: disable
595579

@@ -676,8 +660,8 @@ def default_conf(self,
676660
This instance of :class:`.PostgresNode_Base`.
677661
"""
678662

679-
postgres_conf = os.path.join(self.data_dir, PG_CONF_FILE)
680-
hba_conf = os.path.join(self.data_dir, HBA_CONF_FILE)
663+
postgres_conf = os.path.join(self.data_dir, consts.PG_CONF_FILE)
664+
hba_conf = os.path.join(self.data_dir, consts.HBA_CONF_FILE)
681665

682666
# filter lines in hba file
683667
# get rid of comments and blank lines
@@ -719,15 +703,15 @@ def get_auth_method(t):
719703
self._os_ops.write(postgres_conf, '', truncate=True)
720704

721705
self.append_conf(fsync=fsync,
722-
max_worker_processes=MAX_WORKER_PROCESSES,
706+
max_worker_processes=consts.MAX_WORKER_PROCESSES,
723707
log_statement=log_statement,
724708
listen_addresses=self.host,
725709
port=self.port) # yapf:disable
726710

727711
# common replication settings
728712
if allow_streaming or allow_logical:
729-
self.append_conf(max_replication_slots=MAX_REPLICATION_SLOTS,
730-
max_wal_senders=MAX_WAL_SENDERS) # yapf: disable
713+
self.append_conf(max_replication_slots=consts.MAX_REPLICATION_SLOTS,
714+
max_wal_senders=consts.MAX_WAL_SENDERS) # yapf: disable
731715

732716
# binary replication
733717
if allow_streaming:
@@ -736,11 +720,11 @@ def get_auth_method(t):
736720

737721
if self._pg_version < utils.PgVer('13'):
738722
self.append_conf(hot_standby=True,
739-
wal_keep_segments=WAL_KEEP_SEGMENTS,
723+
wal_keep_segments=consts.WAL_KEEP_SEGMENTS,
740724
wal_level=wal_level) # yapf: disable
741725
else:
742726
self.append_conf(hot_standby=True,
743-
wal_keep_size=WAL_KEEP_SIZE,
727+
wal_keep_size=consts.WAL_KEEP_SIZE,
744728
wal_level=wal_level) # yapf: disable
745729

746730
# logical replication
@@ -750,7 +734,7 @@ def get_auth_method(t):
750734
"available on PostgreSQL 10 and newer")
751735

752736
self.append_conf(
753-
max_logical_replication_workers=MAX_LOGICAL_REPLICATION_WORKERS,
737+
max_logical_replication_workers=consts.MAX_LOGICAL_REPLICATION_WORKERS,
754738
wal_level='logical')
755739

756740
# disable UNIX sockets if asked to
@@ -760,7 +744,7 @@ def get_auth_method(t):
760744
return self
761745

762746
@method_decorator(positional_args_hack(['filename', 'line']))
763-
def append_conf(self, line='', filename=PG_CONF_FILE, **kwargs):
747+
def append_conf(self, line='', filename=consts.PG_CONF_FILE, **kwargs):
764748
"""
765749
Append line to a config file.
766750
@@ -1339,9 +1323,9 @@ def dump(self,
13391323
# Generate tmpfile or tmpdir
13401324
def tmpfile():
13411325
if format == DumpFormat.Directory:
1342-
fname = self._os_ops.mkdtemp(prefix=TMP_DUMP)
1326+
fname = self._os_ops.mkdtemp(prefix=consts.TMP_DUMP)
13431327
else:
1344-
fname = self._os_ops.mkstemp(prefix=TMP_DUMP)
1328+
fname = self._os_ops.mkstemp(prefix=consts.TMP_DUMP)
13451329
return fname
13461330

13471331
filename = filename or tmpfile()

0 commit comments

Comments
 (0)