-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monitor config set postgresql.pg_ctl bug fix (#818)
- removes double-reload of config file during `config set` - errors out when attempting to update to an invalid pg_ctl - allows update to an invalid pg_ctl, in case the binary moved - add new config test (to be backfilled as more changes come up) - fix code comment in related code Co-authored-by: Jacob Champion <pchampion@vmware.com>
- Loading branch information
Showing
4 changed files
with
99 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import pgautofailover_utils as pgautofailover | ||
from nose.tools import assert_raises, raises, eq_ | ||
|
||
import os | ||
import shutil | ||
import subprocess | ||
import time | ||
|
||
cluster = None | ||
monitor = None | ||
node1 = None | ||
|
||
|
||
def setup_module(): | ||
global cluster | ||
cluster = pgautofailover.Cluster() | ||
|
||
|
||
def teardown_module(): | ||
cluster.destroy() | ||
|
||
|
||
def test_000_create_monitor(): | ||
global monitor | ||
monitor = cluster.create_monitor("/tmp/config_test/monitor") | ||
monitor.run() | ||
|
||
|
||
def test_001_init_primary(): | ||
global node1 | ||
node1 = cluster.create_datanode("/tmp/config_test/node1") | ||
node1.create() | ||
|
||
# the name of the node should be "%s_%d" % ("node", node1.nodeid) | ||
eq_(node1.get_nodename(), "node_%d" % node1.get_nodeid()) | ||
|
||
# we can change the name on the monitor with pg_autoctl set node metadata | ||
node1.set_metadata(name="node a") | ||
eq_(node1.get_nodename(), "node a") | ||
|
||
node1.run() | ||
assert node1.wait_until_state(target_state="single") | ||
|
||
# we can also change the name directly in the configuration file | ||
node1.config_set("pg_autoctl.name", "a") | ||
|
||
# wait until the reload signal has been processed before checking | ||
time.sleep(2) | ||
eq_(node1.get_nodename(), "a") | ||
|
||
|
||
def test_002_config_set_monitor(): | ||
pg_ctl = monitor.config_get("postgresql.pg_ctl") | ||
|
||
# set something non-default to assert no side-effects later | ||
sslmode = "prefer" | ||
monitor.config_set("ssl.sslmode", sslmode) | ||
|
||
# set monitor config postgresql.pg_ctl to something invalid | ||
with assert_raises(subprocess.CalledProcessError): | ||
monitor.config_set("postgresql.pg_ctl", "invalid") | ||
|
||
# it should not get changed | ||
eq_(monitor.config_get("postgresql.pg_ctl"), pg_ctl) | ||
|
||
# try again with a keeper | ||
pg_ctl = node1.config_get("postgresql.pg_ctl") | ||
|
||
# set the keeper to something invalid | ||
with assert_raises(subprocess.CalledProcessError): | ||
node1.config_set("postgresql.pg_ctl", "invalid") | ||
|
||
# it should not get changed | ||
eq_(node1.config_get("postgresql.pg_ctl"), pg_ctl) | ||
|
||
# pg_ctl can be moved and `config set` will still operate. | ||
shutil.copy(pg_ctl, "/tmp/pg_ctl") | ||
monitor.config_set("postgresql.pg_ctl", "/tmp/pg_ctl") | ||
# "move" pg_ctl | ||
os.remove("/tmp/pg_ctl") | ||
monitor.config_set("postgresql.pg_ctl", pg_ctl) | ||
|
||
eq_(monitor.config_get("postgresql.pg_ctl"), pg_ctl) | ||
|
||
# no side effects | ||
eq_(monitor.config_get("ssl.sslmode"), sslmode) |