|
| 1 | +import pgautofailover_utils as pgautofailover |
| 2 | +from nose.tools import assert_raises, raises, eq_ |
| 3 | + |
| 4 | +import os |
| 5 | +import shutil |
| 6 | +import subprocess |
| 7 | +import time |
| 8 | + |
| 9 | +cluster = None |
| 10 | +monitor = None |
| 11 | +node1 = None |
| 12 | + |
| 13 | + |
| 14 | +def setup_module(): |
| 15 | + global cluster |
| 16 | + cluster = pgautofailover.Cluster() |
| 17 | + |
| 18 | + |
| 19 | +def teardown_module(): |
| 20 | + cluster.destroy() |
| 21 | + |
| 22 | + |
| 23 | +def test_000_create_monitor(): |
| 24 | + global monitor |
| 25 | + monitor = cluster.create_monitor("/tmp/config_test/monitor") |
| 26 | + monitor.run() |
| 27 | + |
| 28 | + |
| 29 | +def test_001_init_primary(): |
| 30 | + global node1 |
| 31 | + node1 = cluster.create_datanode("/tmp/config_test/node1") |
| 32 | + node1.create() |
| 33 | + |
| 34 | + # the name of the node should be "%s_%d" % ("node", node1.nodeid) |
| 35 | + eq_(node1.get_nodename(), "node_%d" % node1.get_nodeid()) |
| 36 | + |
| 37 | + # we can change the name on the monitor with pg_autoctl set node metadata |
| 38 | + node1.set_metadata(name="node a") |
| 39 | + eq_(node1.get_nodename(), "node a") |
| 40 | + |
| 41 | + node1.run() |
| 42 | + assert node1.wait_until_state(target_state="single") |
| 43 | + |
| 44 | + # we can also change the name directly in the configuration file |
| 45 | + node1.config_set("pg_autoctl.name", "a") |
| 46 | + |
| 47 | + # wait until the reload signal has been processed before checking |
| 48 | + time.sleep(2) |
| 49 | + eq_(node1.get_nodename(), "a") |
| 50 | + |
| 51 | + |
| 52 | +def test_002_config_set_monitor(): |
| 53 | + pg_ctl = monitor.config_get("postgresql.pg_ctl") |
| 54 | + |
| 55 | + # set something non-default to assert no side-effects later |
| 56 | + sslmode = "prefer" |
| 57 | + monitor.config_set("ssl.sslmode", sslmode) |
| 58 | + |
| 59 | + # set monitor config postgresql.pg_ctl to something invalid |
| 60 | + with assert_raises(subprocess.CalledProcessError): |
| 61 | + monitor.config_set("postgresql.pg_ctl", "invalid") |
| 62 | + |
| 63 | + # it should not get changed |
| 64 | + eq_(monitor.config_get("postgresql.pg_ctl"), pg_ctl) |
| 65 | + |
| 66 | + # try again with a keeper |
| 67 | + pg_ctl = node1.config_get("postgresql.pg_ctl") |
| 68 | + |
| 69 | + # set the keeper to something invalid |
| 70 | + with assert_raises(subprocess.CalledProcessError): |
| 71 | + node1.config_set("postgresql.pg_ctl", "invalid") |
| 72 | + |
| 73 | + # it should not get changed |
| 74 | + eq_(node1.config_get("postgresql.pg_ctl"), pg_ctl) |
| 75 | + |
| 76 | + # pg_ctl can be moved and `config set` will still operate. |
| 77 | + shutil.copy(pg_ctl, "/tmp/pg_ctl") |
| 78 | + monitor.config_set("postgresql.pg_ctl", "/tmp/pg_ctl") |
| 79 | + # "move" pg_ctl |
| 80 | + os.remove("/tmp/pg_ctl") |
| 81 | + monitor.config_set("postgresql.pg_ctl", pg_ctl) |
| 82 | + |
| 83 | + eq_(monitor.config_get("postgresql.pg_ctl"), pg_ctl) |
| 84 | + |
| 85 | + # no side effects |
| 86 | + eq_(monitor.config_get("ssl.sslmode"), sslmode) |
0 commit comments