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.
5 PATH="${CTDB_SCRIPTS_BASE}:${PATH}"
7 hdir="$CTDB_SCRIPTS_HELPER_BINDIR"
8 export CTDB_EVENTD="${hdir}/ctdb-eventd"
9 export CTDB_EVENT_HELPER="${hdir}/ctdb-event"
10 export CTDB_LOCK_HELPER="${hdir}/ctdb_lock_helper"
11 export CTDB_RECOVERY_HELPER="${hdir}/ctdb_recovery_helper"
12 export CTDB_TAKEOVER_HELPER="${hdir}/ctdb_takeover_helper"
13 export CTDB_CLUSTER_MUTEX_HELPER="${hdir}/ctdb_mutex_fcntl_helper"
15 if [ -n "$TEST_SOCKET_WRAPPER_SO_PATH" ] ; then
16 export LD_PRELOAD="$TEST_SOCKET_WRAPPER_SO_PATH"
17 export SOCKET_WRAPPER_DIR="${SIMPLE_TESTS_VAR_DIR}/sw"
18 mkdir -p "$SOCKET_WRAPPER_DIR"
21 # onnode will execute this, which fakes ssh against local daemons
22 export ONNODE_SSH="${TEST_SUBDIR}/scripts/ssh_local_daemons.sh"
24 #######################################
26 # If the given IP is hosted then print 2 items: maskbits and iface
37 t=$(ip addr show to "${addr}/${bits}")
43 local have_all_ips=true
45 for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
46 if [ -n "$CTDB_USE_IPV6" ]; then
47 local j=$(printf "%02x" $i)
48 local node_ip="fd00::5357:5f${j}"
49 if have_ip "$node_ip" ; then
53 ERROR: ${node_ip} not on an interface, please add it
63 # Fail if we don't have all of the IPv6 addresses assigned
67 setup_public_addresses ()
72 for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
73 if [ $((i - 1)) -eq $pnn_no_ips ] ; then
77 # 2 public addresses on most nodes, just to make
79 local j=$((i + TEST_LOCAL_DAEMONS))
80 if [ -n "$CTDB_USE_IPV6" ]; then
81 printf "fc00:10::1:%x/64 lo\n" "$i"
82 printf "fc00:10::1:%x/64 lo\n" "$j"
84 printf "192.168.234.%x/24 lo\n" "$i"
85 printf "192.168.234.%x/24 lo\n" "$j"
92 local no_public_addresses=false
93 local no_event_scripts=false
94 local disable_failover=false
96 --no-public-addresses) no_public_addresses=true ;;
97 --no-event-scripts) no_event_scripts=true ;;
98 --disable-failover) disable_failover=true ;;
101 nodes_file="${SIMPLE_TESTS_VAR_DIR}/nodes"
102 setup_nodes >"$nodes_file" || return 1
104 # If there are (strictly) greater than 2 nodes then we'll
105 # randomly choose a node to have no public addresses
107 if [ $TEST_LOCAL_DAEMONS -gt 2 ] ; then
108 pnn_no_ips=$((RANDOM % TEST_LOCAL_DAEMONS))
111 local public_addresses_all="${SIMPLE_TESTS_VAR_DIR}/public_addresses"
112 setup_public_addresses $pnn_no_ips >"$public_addresses_all"
115 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
116 setup_ctdb_base "$SIMPLE_TESTS_VAR_DIR" "node.${pnn}" \
117 functions notify.sh debug-hung-script.sh
119 cp "$nodes_file" "${CTDB_BASE}/nodes"
121 local public_addresses="${CTDB_BASE}/public_addresses"
123 if $no_public_addresses || [ $pnn_no_ips -eq $pnn ] ; then
124 echo "Node ${pnn} will have no public IPs."
125 : >"$public_addresses"
127 cp "$public_addresses_all" "$public_addresses"
130 local node_ip=$(sed -n -e "$(($pnn + 1))p" "$nodes_file")
132 local db_dir="${CTDB_BASE}/db"
134 for d in "volatile" "persistent" "state" ; do
135 mkdir -p "${db_dir}/${d}"
138 if $no_event_scripts ; then
139 rm -vf "${CTDB_BASE}/events/legacy/"*
142 cat >"${CTDB_BASE}/ctdb.conf" <<EOF
144 location = file:${CTDB_BASE}/log.ctdb
148 recovery lock = ${SIMPLE_TESTS_VAR_DIR}/rec.lock
149 node address = ${node_ip}
152 volatile database directory = ${db_dir}/volatile
153 persistent database directory = ${db_dir}/persistent
154 state database directory = ${db_dir}/state
157 disabled = ${disable_failover}
160 debug script = debug-hung-script.sh
169 CTDBD="${VALGRIND} ctdbd" \
170 onnode "$pnn" ctdbd_wrapper start
175 echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
178 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
187 onnode "$pnn" ctdbd_wrapper stop
192 echo "Stopping $TEST_LOCAL_DAEMONS ctdb daemons..."
195 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
206 # onnode will use CTDB_BASES to help the ctdb tool connection to each
209 for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
210 b="${SIMPLE_TESTS_VAR_DIR}/node.${i}"
211 CTDB_BASES="${CTDB_BASES}${CTDB_BASES:+ }${b}"
214 # Need a default CTDB_BASE for onnode (to find the functions file).
215 # Any node will do, so pick the 1st...
216 export CTDB_BASE="${CTDB_BASES%% *}"