- Notifications
You must be signed in to change notification settings - Fork35
Add **kwargs to append_conf()#48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 3 additions & 2 deletionstestgres/backup.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletiontestgres/consts.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
107 changes: 63 additions & 44 deletionstestgres/node.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -7,7 +7,7 @@ | ||
import time | ||
from shutil import rmtree | ||
from six import raise_from, iteritems, text_type | ||
from tempfile import mkstemp, mkdtemp | ||
from .enums import \ | ||
@@ -38,8 +38,10 @@ | ||
PG_PID_FILE | ||
from .consts import \ | ||
MAX_LOGICAL_REPLICATION_WORKERS, \ | ||
MAX_REPLICATION_SLOTS, \ | ||
MAX_WORKER_PROCESSES, \ | ||
MAX_WAL_SENDERS, \ | ||
WAL_KEEP_SEGMENTS | ||
from .decorators import \ | ||
@@ -329,25 +331,27 @@ def _create_recovery_conf(self, username, slot=None): | ||
# Connect to master for some additional actions | ||
with master.connect(username=username) as con: | ||
# check if slot already exists | ||
res = con.execute( | ||
""" | ||
select exists ( | ||
select from pg_catalog.pg_replication_slots | ||
where slot_name = %s | ||
) | ||
""", slot) | ||
if res[0][0]: | ||
raise TestgresException( | ||
"Slot '{}' already exists".format(slot)) | ||
# TODO: we should drop this slot after replica's cleanup() | ||
con.execute( | ||
""" | ||
select pg_catalog.pg_create_physical_replication_slot(%s) | ||
""", slot) | ||
line += "primary_slot_name={}\n".format(slot) | ||
self.append_conf(filename=RECOVERY_CONF_FILE,line=line) | ||
def _maybe_start_logger(self): | ||
if testgres_config.use_python_logging: | ||
@@ -475,65 +479,80 @@ def get_auth_method(t): | ||
# overwrite config file | ||
with io.open(postgres_conf, "w") as conf: | ||
conf.truncate() | ||
self.append_conf(fsync=fsync, | ||
max_worker_processes=MAX_WORKER_PROCESSES, | ||
log_statement=log_statement, | ||
listen_addresses=self.host, | ||
port=self.port) # yapf:disable | ||
# common replication settings | ||
if allow_streaming or allow_logical: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Had to fix settings according tothis page. | ||
self.append_conf(max_replication_slots=MAX_REPLICATION_SLOTS, | ||
max_wal_senders=MAX_WAL_SENDERS) # yapf: disable | ||
# binary replication | ||
if allow_streaming: | ||
# select a proper wal_level for PostgreSQL | ||
wal_level = 'replica' if self._pg_version >= '9.6' else 'hot_standby' | ||
self.append_conf(hot_standby=True, | ||
wal_keep_segments=WAL_KEEP_SEGMENTS, | ||
wal_level=wal_level) # yapf: disable | ||
# logical replication | ||
if allow_logical: | ||
if self._pg_version < '10': | ||
raise InitNodeException("Logical replication is only " | ||
"available on PostgreSQL 10 and newer") | ||
self.append_conf( | ||
max_logical_replication_workers=MAX_LOGICAL_REPLICATION_WORKERS, | ||
wal_level='logical') | ||
# disable UNIX sockets if asked to | ||
if not unix_sockets: | ||
self.append_conf(unix_socket_directories='') | ||
return self | ||
@method_decorator(positional_args_hack(['filename', 'line'])) | ||
def append_conf(self, line='', filename=PG_CONF_FILE, **kwargs): | ||
""" | ||
Append line to a config file. | ||
Args: | ||
line: string to be appended to config. | ||
filename: config file (postgresql.conf by default). | ||
**kwargs: named config options. | ||
Returns: | ||
This instance of :class:`.PostgresNode`. | ||
Examples: | ||
append_conf(fsync=False) | ||
append_conf('log_connections = yes') | ||
append_conf(random_page_cost=1.5, fsync=True, ...) | ||
append_conf('postgresql.conf', 'synchronous_commit = off') | ||
""" | ||
lines = [line] | ||
for option, value in iteritems(kwargs): | ||
if isinstance(value, bool): | ||
value = 'on' if value else 'off' | ||
elif not str(value).replace('.', '', 1).isdigit(): | ||
value = "'{}'".format(value) | ||
# format a new config line | ||
lines.append('{} = {}'.format(option, value)) | ||
config_name = os.path.join(self.data_dir, filename) | ||
with io.open(config_name, 'a') as conf: | ||
for line in lines: | ||
conf.write(text_type(line)) | ||
conf.write(text_type('\n')) | ||
return self | ||
2 changes: 1 addition & 1 deletiontests/test_simple.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.