blob: b3ffe7f642291ee247e18cf1d06f19dc26f18fcf (
plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# Hey Emacs, this is a -*- shell-script -*- !!! :-)
setup_ctdb_base "$CTDB_TEST_TMP_DIR" "ctdb-etc" \
functions
if "$CTDB_TEST_VERBOSE"; then
debug()
{
echo "$@"
}
else
debug()
{
:
}
fi
ctdbd_socket=$(ctdb-path socket "ctdbd")
ctdbd_pidfile=$(ctdb-path pidfile "ctdbd")
ctdbd_dbdir=$(ctdb-path vardir append "db")
define_test()
{
_f=$(basename "$0" ".sh")
case "$_f" in
ctdb.*)
_cmd="${_f#ctdb.}"
_cmd="${_cmd%.*}" # Strip test number
export CTDB="ctdb"
export CTDB_DEBUGLEVEL=NOTICE
if [ -z "$FAKE_CTDBD_DEBUGLEVEL" ]; then
FAKE_CTDBD_DEBUGLEVEL="ERR"
fi
export FAKE_CTDBD_DEBUGLEVEL
test_args="$_cmd"
;;
*)
die "Unknown pattern for testcase \"$_f\""
;;
esac
printf "%-28s - %s\n" "$_f" "$1"
}
cleanup_ctdbd()
{
debug "Cleaning up fake ctdbd"
pid=$(cat "$ctdbd_pidfile" 2>/dev/null || echo)
if [ -n "$pid" ]; then
kill "$pid" || true
rm -f "$ctdbd_pidfile"
fi
rm -f "$ctdbd_socket"
rm -rf "$ctdbd_dbdir"
}
setup_ctdbd()
{
echo "Setting up fake ctdbd"
mkdir -p "$ctdbd_dbdir"
$VALGRIND fake_ctdbd -d "$FAKE_CTDBD_DEBUGLEVEL" \
-s "$ctdbd_socket" -p "$ctdbd_pidfile" \
-D "$ctdbd_dbdir"
# Wait till fake_ctdbd is running
wait_until 10 test -S "$ctdbd_socket" ||
die "fake_ctdbd failed to start"
test_cleanup cleanup_ctdbd
}
ctdbd_getpid()
{
cat "$ctdbd_pidfile"
}
setup_natgw()
{
debug "Setting up NAT gateway"
export CTDB_NATGW_NODES="${CTDB_BASE}/natgw_nodes"
cat >"$CTDB_NATGW_NODES"
}
setup_lvs()
{
debug "Setting up LVS"
export CTDB_LVS_NODES="${CTDB_BASE}/lvs_nodes"
cat >"$CTDB_LVS_NODES"
}
setup_nodes()
{
_pnn="$1"
_f="${CTDB_BASE}/nodes${_pnn:+.}${_pnn}"
cat >"$_f"
}
simple_test_other()
{
# Want word splitting in $CTDB
# shellcheck disable=SC2086
unit_test $CTDB -d "$CTDB_DEBUGLEVEL" "$@"
}
simple_test()
{
# Want word splitting in $test_args
# shellcheck disable=SC2086
simple_test_other $test_args "$@"
}
simple_json_test ()
{
if ! "$CTDB" version --json > /dev/null 2>&1; then
return 0
fi
simple_test "$@" --json
}
|