1 # If we're not running on a real cluster then we need a local copy of
2 # ctdb (and other stuff) in $PATH and we will use local daemons.
4 # Use in-tree binaries if running against local daemons.
5 # Otherwise CTDB need to be installed on all nodes.
6 if [ -n "$ctdb_dir" -a -d "${ctdb_dir}/bin" ] ; then
7 # ctdbd_wrapper is in config/ directory
8 PATH="${ctdb_dir}/bin:${ctdb_dir}/config:${PATH}"
10 export CTDB_EVENTD="${hdir}/ctdb_eventd"
11 export CTDB_EVENT_HELPER="${hdir}/ctdb_event"
12 export CTDB_LOCK_HELPER="${hdir}/ctdb_lock_helper"
13 export CTDB_RECOVERY_HELPER="${hdir}/ctdb_recovery_helper"
14 export CTDB_TAKEOVER_HELPER="${hdir}/ctdb_takeover_helper"
15 export CTDB_CLUSTER_MUTEX_HELPER="${hdir}/ctdb_mutex_fcntl_helper"
18 export CTDB_NODES="${SIMPLE_TESTS_VAR_DIR}/nodes.txt"
20 if [ -n "$TEST_SOCKET_WRAPPER_SO_PATH" ] ; then
21 export LD_PRELOAD="$TEST_SOCKET_WRAPPER_SO_PATH"
22 export SOCKET_WRAPPER_DIR="${SIMPLE_TESTS_VAR_DIR}/sw"
23 mkdir -p "$SOCKET_WRAPPER_DIR"
26 # onnode will execute this, which fakes ssh against local daemons
27 export ONNODE_SSH="${TEST_SUBDIR}/scripts/ssh_local_daemons.sh"
29 #######################################
31 config_from_environment ()
33 # Override from the environment. This would be easier if env was
34 # guaranteed to quote its output so it could be reused.
37 sed -e 's@=\([^"]\)@="\1@' -e 's@[^"]$@&"@' -e 's@="$@&"@'
40 # If the given IP is hosted then print 2 items: maskbits and iface
51 t=$(ip addr show to "${addr}/${bits}")
59 echo "${SIMPLE_TESTS_VAR_DIR}/node.${pnn}"
66 local node_dir=$(node_dir "$pnn")
67 echo "${node_dir}/ctdbd.conf"
74 local node_dir=$(node_dir "$pnn")
75 echo "${node_dir}/ctdbd.pid"
82 local node_dir=$(node_dir "$pnn")
83 echo "${node_dir}/ctdbd.socket"
88 local have_all_ips=true
90 for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
91 if [ -n "$CTDB_USE_IPV6" ]; then
92 local j=$(printf "%02x" $i)
93 local node_ip="fd00::5357:5f${j}"
94 if have_ip "$node_ip" ; then
98 ERROR: ${node_ip} not on an interface, please add it
108 # Fail if we don't have all of the IPv6 addresses assigned
112 setup_public_addresses ()
114 local pnn_no_ips="$1"
117 for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
118 if [ $((i - 1)) -eq $pnn_no_ips ] ; then
122 # 2 public addresses on most nodes, just to make
124 local j=$((i + TEST_LOCAL_DAEMONS))
125 if [ -n "$CTDB_USE_IPV6" ]; then
126 printf "fc00:10::1:%x/64 lo\n" "$i"
127 printf "fc00:10::1:%x/64 lo\n" "$j"
129 printf "192.168.234.%x/24 lo\n" "$i"
130 printf "192.168.234.%x/24 lo\n" "$j"
137 # When running certain tests we add and remove eventscripts, so we
138 # need to be able to modify the events.d/ directory. Therefore,
139 # we use a temporary events.d/ directory under $TEST_VAR_DIR. We
140 # copy the actual test eventscript(s) in there from the original
141 # events.d/ directory that sits alongside $TEST_SCRIPT_DIR.
142 local top=$(dirname "$TEST_SCRIPTS_DIR")
143 local events_d="${top}/events.d"
144 mkdir -p "${TEST_VAR_DIR}/events.d"
145 cp -p "${events_d}/"* "${TEST_VAR_DIR}/events.d/"
147 setup_nodes >"$CTDB_NODES" || return 1
149 # If there are (strictly) greater than 2 nodes then we'll
150 # randomly choose a node to have no public addresses
152 if [ $TEST_LOCAL_DAEMONS -gt 2 ] ; then
153 pnn_no_ips=$((RANDOM % TEST_LOCAL_DAEMONS))
156 local public_addresses_all="${SIMPLE_TESTS_VAR_DIR}/public_addresses"
157 setup_public_addresses $pnn_no_ips >"$public_addresses_all"
160 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
161 local node_dir=$(node_dir "$pnn")
163 setup_ctdb_base "$SIMPLE_TESTS_VAR_DIR" "node.${pnn}" \
166 if [ "$node_dir" != "$CTDB_BASE" ] ; then
167 die "Inconsistent CTDB_BASE"
170 local public_addresses="${node_dir}/public_addresses"
172 if [ $pnn_no_ips -eq $pnn ] ; then
173 echo "Node ${pnn} will have no public IPs."
174 : >"$public_addresses"
176 cp "$public_addresses_all" "$public_addresses"
179 local node_ip=$(sed -n -e "$(($pnn + 1))p" "$CTDB_NODES")
181 local conf=$(node_conf "$pnn")
182 local socket=$(node_socket "$pnn")
184 local db_dir="${node_dir}/db"
185 mkdir -p "${db_dir}/persistent"
188 CTDB_RECOVERY_LOCK="${SIMPLE_TESTS_VAR_DIR}/rec.lock"
189 CTDB_NODES="$CTDB_NODES"
190 CTDB_NODE_ADDRESS="${node_ip}"
191 CTDB_EVENT_SCRIPT_DIR="${TEST_VAR_DIR}/events.d"
192 CTDB_LOGGING="file:${node_dir}/log.ctdb"
194 CTDB_DBDIR="${db_dir}"
195 CTDB_DBDIR_PERSISTENT="${db_dir}/persistent"
196 CTDB_DBDIR_STATE="${db_dir}/state"
197 CTDB_PUBLIC_ADDRESSES="${public_addresses}"
198 CTDB_SOCKET="${socket}"
202 # Append any configuration variables set in environment to
203 # configuration file so they affect CTDB after each restart.
204 config_from_environment >>"$conf"
211 local node_dir=$(node_dir "$pnn")
212 local pidfile=$(node_pidfile "$pnn")
213 local conf=$(node_conf "$pnn")
215 # If there is any CTDB configuration in the environment then
216 # append it to the regular configuration in a temporary
217 # configuration file and use it just this once.
219 local env_conf=$(config_from_environment)
220 if [ -n "$env_conf" ] ; then
221 tmp_conf=$(mktemp --tmpdir="$SIMPLE_TESTS_VAR_DIR")
222 cat "$conf" >"$tmp_conf"
223 echo "$env_conf" >>"$tmp_conf"
227 CTDBD="${VALGRIND} ctdbd --sloppy-start --nopublicipcheck" \
228 CTDB_BASE="$node_dir" \
230 CTDB_PIDFILE="$pidfile" \
233 if [ -n "$tmp_conf" ] ; then
240 echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
243 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
251 local node_dir=$(node_dir "$pnn")
252 local pidfile=$(node_pidfile "$pnn")
253 local conf=$(node_conf "$pnn")
255 CTDB_BASE="$node_dir" \
257 CTDB_PIDFILE="$pidfile" \
263 echo "Stopping $TEST_LOCAL_DAEMONS ctdb daemons..."
266 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
270 rm -rf "${SIMPLE_TESTS_VAR_DIR}/test.db"
296 # If this fails to find processes then the tests fails, so
297 # look at full command-line so this will work with valgrind.
298 # Note that the output could be generated with pgrep's -a
299 # option but it doesn't exist in older versions.
300 ps -p $(pgrep -f '\<ctdbd\>' | xargs | sed -e 's| |,|g') -o args ww
304 # onnode will use CTDB_NODES_SOCKETS to help the ctdb tool connection
306 export CTDB_NODES_SOCKETS=""
307 for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
308 socket=$(node_socket "$i")
309 CTDB_NODES_SOCKETS="${CTDB_NODES_SOCKETS}${CTDB_NODES_SOCKETS:+ }${socket}"
312 # Need a default CTDB_BASE for onnode (to find the functions file).
313 # Any node will do, so pick the 1st...
314 export CTDB_BASE=$(node_dir 0)