File: database-migration-config

package info (click to toggle)
puppetdb 8.8.1-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 19,692 kB
  • sloc: javascript: 23,285; ruby: 5,620; sh: 3,457; python: 389; xml: 114; makefile: 38
file content (98 lines) | stat: -rwxr-xr-x 3,315 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
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash

# Ensures PuppetDB jar fails to start and logs error message when the PuppetDB
# PostgreSQL database is not fully migrated.
# You can specify PuppetDB jar location with env var PDB_JAR.
# PuppetDB configuration is sourced from PDBBOX sandbox or an ephemeral sandbox
# Flags --pgbin and --pgbin are necessary unless set with ext/bin/test-config

set -euo pipefail

test_name=test-database-migration-config

usage() { echo 'Usage: [PDB_JAR=JAR] $(basename "$0") --pgbin PGBIN --pgport PGPORT'; }
misuse() { usage 1>&2; exit 2; }

argv=("$(cd "$(dirname "$0")" && pwd)/$(basename "$0")" "$@")
declare -A opt

# Validate arguments
while test $# -gt 0; do
    case "$1" in
        --pgbin|--pgport)
            test $# -gt 1 || misuse
            opt["${1:2}"]="$2"
            shift 2
            ;;
        *)
            misuse
    esac
done

# If pgbin directory is not provided with --pgbin, read ext/test-conf/pgbin
# If pgbin directory cannot be found, exit with error status
if test -z "${opt[pgbin]:-}"; then
    opt[pgbin]="$(ext/bin/test-config --get pgbin)"
    if test  -z "${opt[pgbin]:-}"; then
        echo 'Please specify --pgbin or set pgbin with ext/bin/test-config' 1>&2
        exit 2
    fi
fi

# If pgport number is not provided with --pgport, read ext/test-conf/pgport
# If pgport number cannot be found, exit with error status
if test -z "${opt[pgport]:-}"; then
    opt[pgport]="$(ext/bin/test-config --get pgport)"
     if test  -z "${opt[pgport]:-}"; then
        echo 'Please specify --pgport or set pgport with ext/bin/test-config' 1>&2
        exit 2
    fi
fi

set -x

# Create an ephemeral PuppetDB sandbox if one isn't set by PDBBOX
if test -z "${PDBBOX:-}"; then
    # No PDBBOX, set one up and run ourselves again
    tmpdir="$(mktemp -d "$test_name-pdbbox-XXXXXX")"
    tmpdir="$(cd "$tmpdir" && pwd)"
    trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT
    # Don't exec (or we'll never run the trap)
    ext/bin/with-pdbbox --box "$tmpdir/box" \
                        --pgbin "${opt[pgbin]}" --pgport "${opt[pgport]}" \
                        -- "${argv[@]}"
    exit 0
fi

# Create temporary directory
tmpdir="$(mktemp -d "$test_name-XXXXXX")"
tmpdir="$(cd "$tmpdir" && pwd)"
trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT


# Since we have an empty database, we need all the migrations, so we
# can just set the option to false to test whether it blocks them.

# Append "migrate = false" just after the [database] section header
# in PuppetDB config file to prevent upgrade subcommand from working.

# MacOS sed appears to require the embedded newline
sed '/\[database\]/a\
  migrate = false
' \
    "$PDBBOX/conf.d/pdb.ini" > "$tmpdir/pdb.ini"
mv "$tmpdir/pdb.ini" "$PDBBOX/conf.d/pdb.ini"

# Test on both services and upgrade subcommands
for cmd in services upgrade; do
    rc=0
    # Start PuppetDB jar with config from PuppetDB sandbox
    ./pdb "$cmd" -c "$PDBBOX/conf.d" 1>"$tmpdir/out" 2>"$tmpdir/err" || rc=$?
    cat "$tmpdir/out" "$tmpdir/err"
    echo  # in case the output doesn't end with a newline
    # This will become 109 once trapperkeeper supports custom exit statuses/
    test "$rc" -eq 109
    # Ensure error message has the right output
    grep -F 'Database is not fully migrated and migration is disallowed' \
         "$tmpdir/err"
done