File: test_config_get_set.py

package info (click to toggle)
pg-auto-failover 2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,368 kB
  • sloc: ansic: 58,369; python: 5,515; sql: 3,177; makefile: 629; sh: 35
file content (86 lines) | stat: -rw-r--r-- 2,410 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import tests.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)