1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

ctdb-tests: Use local_daemons.sh in local_daemons.bash

The etc-ctdb/ subdirectory containing the event script moves into the
top-level tests/ directory because the subdirectory is really now
owned by local_daemons.sh instead of simple/.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2018-10-11 21:55:10 +11:00 committed by Amitay Isaacs
parent 46fd4f144e
commit 19de5f463d
4 changed files with 26 additions and 205 deletions

View File

@ -1,164 +1,45 @@
# If we're not running on a real cluster then we need a local copy of # Hey Emacs, this is a -*- shell-script -*- !!! :-)
# ctdb (and other stuff) in $PATH and we will use local daemons.
hdir="$CTDB_SCRIPTS_HELPER_BINDIR" hdir="$CTDB_SCRIPTS_HELPER_BINDIR"
export CTDB_EVENTD="${hdir}/ctdb-eventd"
export CTDB_EVENT_HELPER="${hdir}/ctdb-event" export CTDB_EVENT_HELPER="${hdir}/ctdb-event"
export CTDB_LOCK_HELPER="${hdir}/ctdb_lock_helper"
export CTDB_RECOVERY_HELPER="${hdir}/ctdb_recovery_helper"
export CTDB_TAKEOVER_HELPER="${hdir}/ctdb_takeover_helper"
export CTDB_CLUSTER_MUTEX_HELPER="${hdir}/ctdb_mutex_fcntl_helper"
if [ -n "$TEST_SOCKET_WRAPPER_SO_PATH" ] ; then if $CTDB_TESTS_ARE_INSTALLED ; then
export LD_PRELOAD="$TEST_SOCKET_WRAPPER_SO_PATH" # Find it in $PATH
export SOCKET_WRAPPER_DIR="${SIMPLE_TESTS_VAR_DIR}/sw" helper="ctdb_local_daemons"
mkdir -p "$SOCKET_WRAPPER_DIR" else
helper="${CTDB_TEST_DIR}/local_daemons.sh"
fi fi
ctdb_local_daemons="${helper} ${SIMPLE_TESTS_VAR_DIR}"
# onnode will execute this, which fakes ssh against local daemons # onnode will execute this, which fakes ssh against local daemons
export ONNODE_SSH="${TEST_SUBDIR}/scripts/ssh_local_daemons.sh" export ONNODE_SSH="${ctdb_local_daemons} ssh"
####################################### #######################################
# If the given IP is hosted then print 2 items: maskbits and iface
have_ip ()
{
local addr="$1"
local bits t
case "$addr" in
*:*) bits=128 ;;
*) bits=32 ;;
esac
t=$(ip addr show to "${addr}/${bits}")
[ -n "$t" ]
}
setup_nodes ()
{
local have_all_ips=true
local i
for i in $(seq 0 $((TEST_LOCAL_DAEMONS - 1)) ) ; do
if [ -n "$CTDB_USE_IPV6" ]; then
local j=$(printf "%04x" $((0x5f00 + 1 + i)) )
local node_ip="fd00::5357:${j}"
if have_ip "$node_ip" ; then
echo "$node_ip"
else
cat >&2 <<EOF
ERROR: ${node_ip} not on an interface, please add it
EOF
have_all_ips=false
fi
else
local c=$(( i / 100 ))
local d=$(( 1 + (i % 100) ))
echo "127.0.${c}.${d}"
fi
done
# Fail if we don't have all of the IPv6 addresses assigned
$have_all_ips
}
setup_public_addresses ()
{
local pnn_no_ips="$1"
local i
for i in $(seq 0 $((TEST_LOCAL_DAEMONS - 1)) ) ; do
if [ $i -eq $pnn_no_ips ] ; then
continue
fi
# 2 public addresses on most nodes, just to make
# things interesting
if [ -n "$CTDB_USE_IPV6" ]; then
printf "fc00:10::1:%x/64 lo\n" $((1 + i))
printf "fc00:10::2:%x/64 lo\n" $((1 + i))
else
local c1=$(( 100 + (i / 100) ))
local c2=$(( 200 + (i / 100) ))
local d=$(( 1 + (i % 100) ))
printf "192.168.${c1}.${d}/24 lo\n"
printf "192.168.${c2}.${d}/24 lo\n"
fi
done
}
setup_ctdb () setup_ctdb ()
{ {
local no_public_addresses=false local public_addresses=""
local no_event_scripts=false local no_event_scripts=false
local disable_failover=false local disable_failover=""
case "$1" in case "$1" in
--no-public-addresses) no_public_addresses=true ;; --no-public-addresses) public_addresses="/dev/null" ;;
--no-event-scripts) no_event_scripts=true ;; --no-event-scripts) no_event_scripts=true ;;
--disable-failover) disable_failover=true ;; --disable-failover) disable_failover="yes" ;;
esac esac
nodes_file="${SIMPLE_TESTS_VAR_DIR}/nodes" $ctdb_local_daemons setup \
setup_nodes >"$nodes_file" || return 1 -n "$TEST_LOCAL_DAEMONS" \
${disable_failover:+-F} \
# If there are (strictly) greater than 2 nodes then we'll ${public_addresses:+-P} ${public_addresses} \
# randomly choose a node to have no public addresses ${CTDB_USE_IPV6:+-6} \
local pnn_no_ips=-1 ${TEST_SOCKET_WRAPPER_SO_PATH:+-S} ${TEST_SOCKET_WRAPPER_SO_PATH}
if [ $TEST_LOCAL_DAEMONS -gt 2 ] ; then
pnn_no_ips=$((RANDOM % TEST_LOCAL_DAEMONS))
fi
local public_addresses_all="${SIMPLE_TESTS_VAR_DIR}/public_addresses"
setup_public_addresses $pnn_no_ips >"$public_addresses_all"
local pnn local pnn
for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
setup_ctdb_base "$SIMPLE_TESTS_VAR_DIR" "node.${pnn}" \
functions notify.sh debug-hung-script.sh
cp "$nodes_file" "${CTDB_BASE}/nodes"
local public_addresses="${CTDB_BASE}/public_addresses"
if $no_public_addresses || [ $pnn_no_ips -eq $pnn ] ; then
echo "Node ${pnn} will have no public IPs."
: >"$public_addresses"
else
cp "$public_addresses_all" "$public_addresses"
fi
local node_ip=$(sed -n -e "$(($pnn + 1))p" "$nodes_file")
local db_dir="${CTDB_BASE}/db"
local d
for d in "volatile" "persistent" "state" ; do
mkdir -p "${db_dir}/${d}"
done
if $no_event_scripts ; then if $no_event_scripts ; then
rm -vf "${CTDB_BASE}/events/legacy/"* rm -vf "${CTDB_BASE}/events/legacy/"*
fi fi
cat >"${CTDB_BASE}/ctdb.conf" <<EOF
[logging]
location = file:${CTDB_BASE}/log.ctdb
log level = INFO
[cluster]
recovery lock = ${SIMPLE_TESTS_VAR_DIR}/rec.lock
node address = ${node_ip}
[database]
volatile database directory = ${db_dir}/volatile
persistent database directory = ${db_dir}/persistent
state database directory = ${db_dir}/state
[failover]
disabled = ${disable_failover}
[event]
debug script = debug-hung-script.sh
EOF
done done
} }
@ -166,28 +47,24 @@ start_ctdb_1 ()
{ {
local pnn="$1" local pnn="$1"
onnode "$pnn" $VALGRIND ctdbd $ctdb_local_daemons start "$pnn"
} }
ctdb_start_all () ctdb_start_all ()
{ {
echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..." $ctdb_local_daemons start "all"
onnode all $VALGRIND ctdbd
} }
stop_ctdb_1 () stop_ctdb_1 ()
{ {
local pnn="$1" local pnn="$1"
onnode "$pnn" $CTDB shutdown $ctdb_local_daemons stop "$pnn"
} }
ctdb_stop_all () ctdb_stop_all ()
{ {
echo "Stopping $TEST_LOCAL_DAEMONS ctdb daemons..." $ctdb_local_daemons stop "all"
onnode -p all $CTDB shutdown
} }
restart_ctdb_1 () restart_ctdb_1 ()
@ -196,14 +73,5 @@ restart_ctdb_1 ()
start_ctdb_1 "$1" start_ctdb_1 "$1"
} }
# onnode will use CTDB_BASES to help the ctdb tool connection to each # onnode just needs the nodes file, so use the common one
# daemon export CTDB_BASE="$SIMPLE_TESTS_VAR_DIR"
export CTDB_BASES=""
for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
b="${SIMPLE_TESTS_VAR_DIR}/node.${i}"
CTDB_BASES="${CTDB_BASES}${CTDB_BASES:+ }${b}"
done
# Need a default CTDB_BASE for onnode (to find the functions file).
# Any node will do, so pick the 1st...
export CTDB_BASE="${CTDB_BASES%% *}"

View File

@ -1,48 +0,0 @@
#!/bin/sh
nodes="${CTDB_BASE}/nodes"
# Only try to respect ssh -n option, others can't be used so discard them
close_stdin=false
while : ; do
case "$1" in
-n) close_stdin=true ; shift ;;
-*) shift ;;
*) break ;;
esac
done
if [ $# -ne 2 ] ; then
echo "usage: $0 <ip> <command>" >&2
exit 1
fi
# IP adress of node. onnode can pass hostnames but not in these tests
ip="$1"
# Complete command is provide by onnode as a single argument
command="$2"
num=$(awk -v ip="$ip" '$1 == ip { print NR }' "$nodes")
pnn=$((num - 1))
# Determine the correct CTDB base directory
export CTDB_BASE=""
n=0
for b in $CTDB_BASES ; do
if [ $n -eq $pnn ] ; then
CTDB_BASE="$b"
break
fi
n=$((n + 1))
done
if [ -z "$CTDB_BASE" ] ; then
echo "$0: Unable to find base for node ${ip}" >&2
exit 1
fi
if $close_stdin ; then
exec sh -c "$command" <&-
else
exec sh -c "$command"
fi

View File

@ -1051,6 +1051,7 @@ def build(bld):
'complex', 'complex',
'ctdb_eventd', 'ctdb_eventd',
'cunit', 'cunit',
'etc-ctdb',
'eventd', 'eventd',
'eventscripts', 'eventscripts',
'onnode', 'onnode',