File: test_installcheck.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 (81 lines) | stat: -rw-r--r-- 1,937 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
import tests.pgautofailover_utils as pgautofailover
from nose.tools import *

import subprocess
import shutil
import os
import os.path

cluster = None
node1 = None
node2 = None


def setup_module():
    global cluster
    cluster = pgautofailover.Cluster()


def teardown_module():
    cluster.destroy()


def test_000_create_monitor():
    monitor = cluster.create_monitor("/tmp/check/monitor")
    monitor.run()
    monitor.wait_until_pg_is_running()


def test_001_add_hba_entry():
    with open(os.path.join("/tmp/check/monitor", "pg_hba.conf"), "a") as hba:
        hba.write("host all all %s trust\n" % cluster.networkSubnet)

    # print()
    # with open(os.path.join("/tmp/check/monitor", "pg_hba.conf"), "r") as hba:
    #     lines = hba.readlines()
    #     for line in lines[-10:]:
    #         print("%s" % line[:-1])

    cluster.monitor.reload_postgres()


def test_002_make_installcheck():
    # support both the local Dockerfile and also Travis build environments
    if "TRAVIS_BUILD_DIR" in os.environ:
        topdir = os.environ["TRAVIS_BUILD_DIR"]
    else:
        topdir = "/usr/src/pg_auto_failover"

    p = subprocess.Popen(
        [
            "sudo",
            shutil.which("chmod"),
            "-R",
            "go+w",
            os.path.join(topdir, "src/monitor"),
        ]
    )
    assert p.wait() == 0

    p = subprocess.Popen(
        [
            "sudo",
            "-E",
            "-u",
            os.getenv("USER"),
            "env",
            "PATH=" + os.getenv("PATH"),
            "PGHOST=" + str(cluster.monitor.vnode.address),
            "make",
            "-C",
            os.path.join(topdir, "src/monitor"),
            "installcheck",
        ]
    )

    if p.wait() != 0:
        diff = os.path.join(topdir, "src/monitor/regression.diffs")
        with open(diff, "r") as d:
            print("%s" % d.read())

        raise Exception("make installcheck failed")