Best reviewed with "git show -w" or similar.
Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Anoop C S <anoopcs@samba.org>
# $out set by ctdb_onnode() above
reclock_setting="$out"
-if [ -z "$reclock_setting" ] ; then
+if [ -z "$reclock_setting" ]; then
ctdb_test_skip "Cluster lock is not set"
fi
t="${reclock_setting% 5}"
reclock="${t##* }"
-if [ ! -f "$reclock" ] ; then
+if [ ! -f "$reclock" ]; then
ctdb_test_error "Cluster lock file \"${reclock}\" is missing"
fi
echo "Node ${test_node} has version ${major}.${minor}"
# Unchanged version - this should work
-export CTDB_TEST_SAMBA_VERSION=$(( (major << 16) | minor ))
+export CTDB_TEST_SAMBA_VERSION=$(((major << 16) | minor))
printf '\nRestarting node %d with CTDB_TEST_SAMBA_VERSION=0x%08x\n' \
- "$test_node" \
- "$CTDB_TEST_SAMBA_VERSION"
+ "$test_node" \
+ "$CTDB_TEST_SAMBA_VERSION"
ctdb_nodes_restart "$test_node"
wait_until_ready
echo "GOOD: ctdbd restarted successfully on node ${test_node}"
pidfile="$out"
# Changed major version - this should fail
-export CTDB_TEST_SAMBA_VERSION=$(( ((major + 1) << 16) | minor ))
+export CTDB_TEST_SAMBA_VERSION=$((((major + 1) << 16) | minor))
printf '\nRestarting node %d with CTDB_TEST_SAMBA_VERSION=0x%08x\n' \
- "$test_node" \
- "$CTDB_TEST_SAMBA_VERSION"
+ "$test_node" \
+ "$CTDB_TEST_SAMBA_VERSION"
ctdb_nodes_restart "$test_node"
echo "Will use PID file ${pidfile} to check for ctdbd exit"
wait_until 30 ! test -f "$pidfile"
echo "GOOD: ctdbd exited early on node ${test_node}"
# Changed minor version - this should fail
-export CTDB_TEST_SAMBA_VERSION=$(( (major << 16) | (minor + 1) ))
+export CTDB_TEST_SAMBA_VERSION=$(((major << 16) | (minor + 1)))
printf '\nRestarting node %d with CTDB_TEST_SAMBA_VERSION=0x%08x\n' \
- "$test_node" \
- "$CTDB_TEST_SAMBA_VERSION"
+ "$test_node" \
+ "$CTDB_TEST_SAMBA_VERSION"
ctdb_nodes_start "$test_node"
echo "Will use PID file ${pidfile} to check for ctdbd exit"
wait_until 30 ! test -f "$pidfile"
UNLOCK
EOF
unit_test cluster_mutex_test lock-file-removed-no-recheck \
- "$helper 0" "$lockfile"
+ "$helper 0" "$lockfile"
test_case "Recheck on, lock file not removed"
ok <<EOF
UNLOCK
EOF
unit_test cluster_mutex_test lock-file-wait-recheck-unlock \
- "$helper 5" 10
+ "$helper 5" 10
test_case "Recheck on, lock file removed"
ok <<EOF
EOF
unit_test cluster_mutex_test lock-io-timeout "$helper 5 7" "$lockfile" 1 2
-
test_case "Recheck on, ping on, child waits, child blocks causing ping timeout"
ok <<EOF
LOCK
lockfile="${CTDB_TEST_TMP_DIR}/cluster_mutex.lockfile"
trap 'rm ${lockfile}' 0
-if [ -n "$CTDB_TEST_MUTEX_HELPER" ] ; then
+if [ -n "$CTDB_TEST_MUTEX_HELPER" ]; then
helper="$CTDB_TEST_MUTEX_HELPER"
else
t="${CTDB_SCRIPTS_HELPER_BINDIR}/ctdb_mutex_fcntl_helper"
conffile="${CTDB_BASE}/ctdb.conf"
-remove_files ()
+remove_files()
{
rm -f "$conffile"
}
# Get the default values that are dependent on install prefix
logging_location=$(ctdb-config get "logging" "location")
database_volatile_dbdir=$(ctdb-config get \
- "database" \
- "volatile database directory")
+ "database" \
+ "volatile database directory")
database_persistent_dbdir=$(ctdb-config get \
- "database" \
- "persistent database directory")
+ "database" \
+ "persistent database directory")
database_state_dbdir=$(ctdb-config get \
- "database" \
- "state database directory")
+ "database" \
+ "state database directory")
ok <<EOF
[logging]
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
EOF
ok_null
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[foobar]
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
foobar = cat
EOF
# Confirm that an unknown key doesn't stop the rest of the file from
# loading
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[database]
unknown key = 123
conffile="${CTDB_BASE}/ctdb.conf"
-remove_files ()
+remove_files()
{
rm -f "$conffile"
}
test_cleanup remove_files
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
EOF
ok <<EOF
EOF
unit_test ctdb-config get "logging" "log level"
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[logging]
location = syslog:magic
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[logging]
log level = high
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[logging]
location = syslog
log level = notice
conffile="${CTDB_BASE}/ctdb.conf"
scriptfile="${CTDB_BASE}/debug-hung-script.sh"
-remove_files ()
+remove_files()
{
rm -f "$conffile"
}
test_cleanup remove_files
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
EOF
ok <<EOF
EOF
unit_test ctdb-config get "event" "debug script"
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[event]
debug script = debug-hung-script.sh
EOF
conffile="$CTDB_BASE/ctdb.conf"
-remove_files ()
+remove_files()
{
rm -f "$conffile"
}
test_cleanup remove_files
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
EOF
ok <<EOF
EOF
unit_test ctdb-config get "cluster" "leader capability"
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[cluster]
transport = invalid
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[cluster]
node address = 10.1.2.3
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[cluster]
node address = fc00:10:1:2::123
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[cluster]
node address = 10.1.2.3:123
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[cluster]
cluster lock = /foo/bar
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[cluster]
recovery lock = /foo/bar
EOF
EOF
unit_test ctdb-config -d WARNING validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[cluster]
leader timeout = 10
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[cluster]
leader timeout = 0
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[cluster]
leader timeout = -5
EOF
EOF
unit_test ctdb-config validate
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[cluster]
leader capability = false
EOF
dbdir_persistent="${dbdir}/persistent"
dbdir_state="${dbdir}/state"
-remove_files ()
+remove_files()
{
rm -f "$conffile" "$scriptfile"
}
test_cleanup remove_files
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[database]
volatile database directory = ${dbdir_volatile}
persistent database directory = ${dbdir_persistent}
EOF
unit_test ctdb-config get "database" "lock debug script"
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[database]
lock debug script = $scriptfile
EOF
conffile="${CTDB_BASE}/ctdb.conf"
-remove_files ()
+remove_files()
{
rm -f "$conffile"
}
test_cleanup remove_files
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
EOF
ok <<EOF
EOF
unit_test ctdb-config get "legacy" "script log level"
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
[legacy]
script log level = INVALID
EOF
conffile="${CTDB_BASE}/ctdb.conf"
-remove_files ()
+remove_files()
{
rm -f "$conffile"
}
test_cleanup remove_files
-cat > "$conffile" <<EOF
+cat >"$conffile" <<EOF
EOF
ok <<EOF
PATH="$PATH:$CTDB_SCRIPTS_TOOLS_HELPER_DIR"
-if "$CTDB_TEST_VERBOSE" ; then
- debug () { echo "$@" ; }
+if "$CTDB_TEST_VERBOSE"; then
+ debug()
+ {
+ echo "$@"
+ }
else
- debug () { : ; }
+ debug()
+ {
+ :
+ }
fi
setup_ctdb_base "$CTDB_TEST_TMP_DIR" "ctdb-etc"
eventd_scriptdir=$(ctdb-path etcdir append events)
eventd_logfile="${CTDB_BASE}/eventd.log"
-define_test ()
+define_test()
{
- _f=$(basename "$0" ".sh")
+ _f=$(basename "$0" ".sh")
- printf "%-28s - %s\n" "$_f" "$1"
+ printf "%-28s - %s\n" "$_f" "$1"
}
-cleanup_eventd ()
+cleanup_eventd()
{
debug "Cleaning up eventd"
pid=$(cat "$eventd_pidfile" 2>/dev/null || echo)
- if [ -n "$pid" ] ; then
+ if [ -n "$pid" ]; then
kill $pid || true
fi
}
-setup_eventd ()
+setup_eventd()
{
echo "Setting up eventd"
$VALGRIND ctdb-eventd 2>&1 | tee "$eventd_logfile" &
# Wait till eventd is running
- wait_until 10 test -S "$eventd_socket" || \
+ wait_until 10 test -S "$eventd_socket" ||
die "ctdb_eventd failed to start"
test_cleanup cleanup_eventd
}
-simple_test_background ()
+simple_test_background()
{
background_log="${CTDB_BASE}/background.log"
background_status="${CTDB_BASE}/background.status"
background_running=1
(
- (unit_test ctdb-event "$@") > "$background_log" 2>&1
- echo $? > "$background_status"
+ (unit_test ctdb-event "$@") >"$background_log" 2>&1
+ echo $? >"$background_status"
) &
background_pid=$!
}
-background_wait ()
+background_wait()
{
[ -n "$background_running" ] || return
count=0
- while [ ! -s "$background_status" -a $count -lt 30 ] ; do
- count=$(( $count + 1 ))
+ while [ ! -s "$background_status" -a $count -lt 30 ]; do
+ count=$(($count + 1))
sleep 1
done
- if [ ! -s "$background_status" ] ; then
+ if [ ! -s "$background_status" ]; then
kill -9 "$background_pid"
- echo TIMEOUT > "$background_status"
+ echo TIMEOUT >"$background_status"
fi
}
-background_output ()
+background_output()
{
[ -n "$background_running" ] || return
bg_status=$(cat "$background_status")
rm -f "$background_status"
echo "--- Background ---"
- if [ "$bg_status" = "TIMEOUT" ] ; then
+ if [ "$bg_status" = "TIMEOUT" ]; then
echo "Background process did not complete"
bg_status=1
else
[ $bg_status -eq 0 ] || exit $bg_status
}
-simple_test ()
+simple_test()
{
(unit_test ctdb-event "$@")
status=$?
[ $status -eq 0 ] || exit $status
}
-result_filter ()
+result_filter()
{
_duration="\<[0-9][0-9]*\.[0-9][0-9][0-9]\>"
_day="[FMSTW][aehoru][deintu]"
_datetime="${_day} ${_month} ${_date} ${_time} ${_year}"
_pid="[0-9][0-9]*"
sed -e "s#${_duration}#DURATION#" \
- -e "s#${_datetime}#DATETIME#" \
- -e "s#,${_pid}#,PID#"
+ -e "s#${_datetime}#DATETIME#" \
+ -e "s#,${_pid}#,PID#"
}
define_test "tests"
-if "$CTDB_TESTS_ARE_INSTALLED" ; then
+if "$CTDB_TESTS_ARE_INSTALLED"; then
run_tests="${CTDB_SCRIPTS_TESTS_BIN_DIR}/ctdb_run_tests"
local_daemons="${CTDB_SCRIPTS_TESTS_BIN_DIR}/ctdb_local_daemons"
else
# Scripts
shellcheck_test \
- "$run_tests" \
- "$local_daemons" \
- "${TEST_SCRIPTS_DIR}/test_wrap"
+ "$run_tests" \
+ "$local_daemons" \
+ "${TEST_SCRIPTS_DIR}/test_wrap"
# Includes
shellcheck_test -s sh \
# Hey Emacs, this is a -*- shell-script -*- !!! :-)
-if "$CTDB_TEST_VERBOSE" ; then
- debug () { echo "$@" ; }
+if "$CTDB_TEST_VERBOSE"; then
+ debug()
+ {
+ echo "$@"
+ }
else
- debug () { : ; }
+ debug()
+ {
+ :
+ }
fi
. "${TEST_SCRIPTS_DIR}/script_install_paths.sh"
ctdbd_pidfile=$(ctdb-path pidfile "ctdbd")
ctdbd_dbdir=$(ctdb-path vardir append "db")
-define_test ()
+define_test()
{
_f=$(basename "$0" ".sh")
printf "%-28s - %s\n" "$_f" "$1"
- if [ -z "$FAKE_CTDBD_DEBUGLEVEL" ] ; then
+ if [ -z "$FAKE_CTDBD_DEBUGLEVEL" ]; then
FAKE_CTDBD_DEBUGLEVEL="ERR"
fi
- if [ -z "$HELPER_DEBUGLEVEL" ] ; then
+ if [ -z "$HELPER_DEBUGLEVEL" ]; then
HELPER_DEBUGLEVEL="NOTICE"
fi
- if [ -z "$CTDB_DEBUGLEVEL" ] ; then
+ if [ -z "$CTDB_DEBUGLEVEL" ]; then
CTDB_DEBUGLEVEL="ERR"
fi
}
-cleanup_ctdbd ()
+cleanup_ctdbd()
{
debug "Cleaning up fake ctdbd"
pid=$(cat "$ctdbd_pidfile" 2>/dev/null || echo)
- if [ -n "$pid" ] ; then
+ if [ -n "$pid" ]; then
kill $pid || true
rm -f "$ctdbd_pidfile"
fi
rm -rf "$ctdbd_dbdir"
}
-setup_ctdbd ()
+setup_ctdbd()
{
debug "Setting up fake ctdbd"
mkdir -p "$ctdbd_dbdir"
$VALGRIND fake_ctdbd -d "$FAKE_CTDBD_DEBUGLEVEL" \
- -s "$ctdbd_socket" -p "$ctdbd_pidfile" \
- -D "$ctdbd_dbdir"
+ -s "$ctdbd_socket" -p "$ctdbd_pidfile" \
+ -D "$ctdbd_dbdir"
# This current translates to a 6 second timeout for the
# important controls
ctdb setvar TakeoverTimeout 2
# Render non-printable characters. The helper prints the status as
# binary, so render it for easy comparison.
-result_filter ()
+result_filter()
{
sed -e 's|ctdb-takeover\[[0-9]*\]: ||'
}
-ctdb_cmd ()
+ctdb_cmd()
{
echo Running: ctdb -d "$CTDB_DEBUGLEVEL" "$@"
ctdb -d "$CTDB_DEBUGLEVEL" "$@"
}
-test_ctdb_ip_all ()
+test_ctdb_ip_all()
{
unit_test ctdb -d "$CTDB_DEBUGLEVEL" ip all || exit $?
}
takeover_helper_out="${CTDB_TEST_TMP_DIR}/takover_helper.out"
-takeover_helper_format_outfd ()
+takeover_helper_format_outfd()
{
od -A n -t d4 "$takeover_helper_out" | sed -e 's|[[:space:]]*||g'
}
-test_takeover_helper ()
+test_takeover_helper()
{
(
export CTDB_DEBUGLEVEL="$HELPER_DEBUGLEVEL"
export CTDB_LOGGING="file:"
unit_test ctdb_takeover_helper 3 "$ctdbd_socket" "$@" \
- 3>"$takeover_helper_out"
+ 3>"$takeover_helper_out"
) || exit $?
case "$required_rc" in
PATH="${PATH}:${CTDB_SCRIPTS_HELPER_BINDIR}"
setup_ctdb_base "$CTDB_TEST_TMP_DIR" "ctdb-etc" \
- functions
+ functions
-if "$CTDB_TEST_VERBOSE" ; then
- debug () { echo "$@" ; }
+if "$CTDB_TEST_VERBOSE"; then
+ debug()
+ {
+ echo "$@"
+ }
else
- debug () { : ; }
+ debug()
+ {
+ :
+ }
fi
ctdbd_socket=$(ctdb-path socket "ctdbd")
ctdbd_pidfile=$(ctdb-path pidfile "ctdbd")
ctdbd_dbdir=$(ctdb-path vardir append "db")
-define_test ()
+define_test()
{
- _f=$(basename "$0" ".sh")
+ _f=$(basename "$0" ".sh")
- case "$_f" in
+ 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"
- ;;
+ _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
+ die "Unknown pattern for testcase \"$_f\""
+ ;;
+ esac
- printf "%-28s - %s\n" "$_f" "$1"
+ printf "%-28s - %s\n" "$_f" "$1"
}
-cleanup_ctdbd ()
+cleanup_ctdbd()
{
debug "Cleaning up fake ctdbd"
pid=$(cat "$ctdbd_pidfile" 2>/dev/null || echo)
- if [ -n "$pid" ] ; then
+ if [ -n "$pid" ]; then
kill $pid || true
rm -f "$ctdbd_pidfile"
fi
rm -rf "$ctdbd_dbdir"
}
-setup_ctdbd ()
+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"
+ -s "$ctdbd_socket" -p "$ctdbd_pidfile" \
+ -D "$ctdbd_dbdir"
# Wait till fake_ctdbd is running
- wait_until 10 test -S "$ctdbd_socket" || \
+ wait_until 10 test -S "$ctdbd_socket" ||
die "fake_ctdbd failed to start"
test_cleanup cleanup_ctdbd
}
-ctdbd_getpid ()
+ctdbd_getpid()
{
cat "$ctdbd_pidfile"
}
-setup_natgw ()
+setup_natgw()
{
debug "Setting up NAT gateway"
cat >"$CTDB_NATGW_NODES"
}
-setup_lvs ()
+setup_lvs()
{
debug "Setting up LVS"
cat >"$CTDB_LVS_NODES"
}
-setup_nodes ()
+setup_nodes()
{
- _pnn="$1"
+ _pnn="$1"
- _f="${CTDB_BASE}/nodes${_pnn:+.}${_pnn}"
+ _f="${CTDB_BASE}/nodes${_pnn:+.}${_pnn}"
- cat >"$_f"
+ cat >"$_f"
}
-simple_test_other ()
+simple_test_other()
{
unit_test $CTDB -d $CTDB_DEBUGLEVEL "$@"
}
-simple_test ()
+simple_test()
{
simple_test_other $test_args "$@"
}
. "${TEST_SCRIPTS_DIR}/common.sh"
-if ! $CTDB_TESTS_ARE_INSTALLED ; then
+if ! $CTDB_TESTS_ARE_INSTALLED; then
hdir="$CTDB_SCRIPTS_HELPER_BINDIR"
export CTDB_EVENTD="${hdir}/ctdb-eventd"
export CTDB_EVENT_HELPER="${hdir}/ctdb-event"
########################################
# If the given IP is hosted then print 2 items: maskbits and iface
-have_ip ()
+have_ip()
{
_addr="$1"
case "$_addr" in
*:*) _bits=128 ;;
- *) _bits=32 ;;
+ *) _bits=32 ;;
esac
_t=$(ip addr show to "${_addr}/${_bits}")
[ -n "$_t" ]
}
-setup_nodes ()
+setup_nodes()
{
_num_nodes="$1"
_use_ipv6="$2"
_have_all_ips=true
- for _i in $(seq 0 $((_num_nodes - 1)) ) ; do
- if $_use_ipv6 ; then
- _j=$(printf "%04x" $((0x5f00 + 1 + _i)) )
+ for _i in $(seq 0 $((_num_nodes - 1))); do
+ if $_use_ipv6; then
+ _j=$(printf "%04x" $((0x5f00 + 1 + _i)))
_node_ip="fd00::5357:${_j}"
- if have_ip "$_node_ip" ; then
+ if have_ip "$_node_ip"; then
echo "$_node_ip"
else
cat >&2 <<EOF
_have_all_ips=false
fi
else
- _c=$(( _i / 100 ))
- _d=$(( 1 + (_i % 100) ))
+ _c=$((_i / 100))
+ _d=$((1 + (_i % 100)))
echo "127.0.${_c}.${_d}"
fi
done
$_have_all_ips
}
-setup_public_addresses ()
+setup_public_addresses()
{
_num_nodes="$1"
_node_no_ips="$2"
_use_ipv6="$3"
- for _i in $(seq 0 $((_num_nodes - 1)) ) ; do
- if [ "$_i" -eq "$_node_no_ips" ] ; then
+ for _i in $(seq 0 $((_num_nodes - 1))); do
+ if [ "$_i" -eq "$_node_no_ips" ]; then
continue
fi
# 2 public addresses on most nodes, just to make
# things interesting
- if $_use_ipv6 ; then
+ if $_use_ipv6; then
printf 'fc00:10::1:%x/64 lo\n' $((1 + _i))
printf 'fc00:10::2:%x/64 lo\n' $((1 + _i))
else
- _c1=$(( 100 + (_i / 100) ))
- _c2=$(( 200 + (_i / 100) ))
- _d=$(( 1 + (_i % 100) ))
+ _c1=$((100 + (_i / 100)))
+ _c2=$((200 + (_i / 100)))
+ _d=$((1 + (_i % 100)))
printf '192.168.%d.%d/24 lo\n' "$_c1" "$_d"
printf '192.168.%d.%d/24 lo\n' "$_c2" "$_d"
fi
done
}
-setup_socket_wrapper ()
+setup_socket_wrapper()
{
_socket_wrapper_so="$1"
_so="${directory}/libsocket-wrapper.so"
- if [ ! -f "$_socket_wrapper_so" ] ; then
+ if [ ! -f "$_socket_wrapper_so" ]; then
die "$0 setup: Unable to find ${_socket_wrapper_so}"
fi
mkdir -p "$_d"
}
-local_daemons_setup_usage ()
+local_daemons_setup_usage()
{
cat >&2 <<EOF
$0 <directory> setup [ <options>... ]
exit 1
}
-local_daemons_setup ()
+local_daemons_setup()
{
_commented_config=""
_disable_failover=false
set -e
- while getopts "C:FN:n:P:Rr:S:6h?" _opt ; do
+ while getopts "C:FN:n:P:Rr:S:6h?" _opt; do
case "$_opt" in
- C) _t="${_commented_config}${_commented_config:+|}"
- _commented_config="${_t}${OPTARG}"
- ;;
+ C)
+ _t="${_commented_config}${_commented_config:+|}"
+ _commented_config="${_t}${OPTARG}"
+ ;;
F) _disable_failover=true ;;
N) _nodes_file="$OPTARG" ;;
n) _num_nodes="$OPTARG" ;;
P) _public_addresses_file="$OPTARG" ;;
R) _cluster_lock_use_command=true ;;
- r) _cluster_lock_use_command=true
- _cluster_lock_recheck_interval="$OPTARG"
- ;;
+ r)
+ _cluster_lock_use_command=true
+ _cluster_lock_recheck_interval="$OPTARG"
+ ;;
S) _socket_wrapper="$OPTARG" ;;
6) _use_ipv6=true ;;
- \?|h) local_daemons_setup_usage ;;
+ \? | h) local_daemons_setup_usage ;;
esac
done
shift $((OPTIND - 1))
mkdir -p "$directory"
_nodes_all="${directory}/nodes"
- if [ -n "$_nodes_file" ] ; then
+ if [ -n "$_nodes_file" ]; then
cp "$_nodes_file" "$_nodes_all"
else
setup_nodes "$_num_nodes" $_use_ipv6 >"$_nodes_all"
# If there are (strictly) greater than 2 nodes then we'll
# "randomly" choose a node to have no public addresses
_node_no_ips=-1
- if [ "$_num_nodes" -gt 2 ] ; then
+ if [ "$_num_nodes" -gt 2 ]; then
_node_no_ips=$(($$ % _num_nodes))
fi
_public_addresses_all="${directory}/public_addresses"
- if [ -n "$_public_addresses_file" ] ; then
+ if [ -n "$_public_addresses_file" ]; then
cp "$_public_addresses_file" "$_public_addresses_all"
else
setup_public_addresses "$_num_nodes" \
- $_node_no_ips \
- "$_use_ipv6" >"$_public_addresses_all"
+ $_node_no_ips \
+ "$_use_ipv6" >"$_public_addresses_all"
fi
_cluster_lock_dir="${directory}/shared/.ctdb"
mkdir -p "$_cluster_lock_dir"
_cluster_lock="${_cluster_lock_dir}/cluster.lock"
- if $_cluster_lock_use_command ; then
+ if $_cluster_lock_use_command; then
_helper="${CTDB_SCRIPTS_HELPER_BINDIR}/ctdb_mutex_fcntl_helper"
_t="! ${_helper} ${_cluster_lock}"
- if [ -n "$_cluster_lock_recheck_interval" ] ; then
+ if [ -n "$_cluster_lock_recheck_interval" ]; then
_t="${_t} ${_cluster_lock_recheck_interval}"
fi
_cluster_lock="$_t"
fi
- if [ -n "$_socket_wrapper" ] ; then
+ if [ -n "$_socket_wrapper" ]; then
setup_socket_wrapper "$_socket_wrapper"
fi
- for _n in $(seq 0 $((_num_nodes - 1))) ; do
+ for _n in $(seq 0 $((_num_nodes - 1))); do
# CTDB_TEST_SUITE_DIR needs to be correctly set so
# setup_ctdb_base() finds the etc-ctdb/ subdirectory
# and the test event script is correctly installed
# shellcheck disable=SC2034
CTDB_TEST_SUITE_DIR="$CTDB_TEST_DIR" \
- setup_ctdb_base "$directory" "node.${_n}" \
- functions notify.sh debug-hung-script.sh
+ setup_ctdb_base "$directory" "node.${_n}" \
+ functions notify.sh debug-hung-script.sh
cp "$_nodes_all" "${CTDB_BASE}/nodes"
_public_addresses="${CTDB_BASE}/public_addresses"
- if [ -z "$_public_addresses_file" ] && \
- [ "$_node_no_ips" -eq "$_n" ] ; then
+ if [ -z "$_public_addresses_file" ] &&
+ [ "$_node_no_ips" -eq "$_n" ]; then
echo "Node ${_n} will have no public IPs."
: >"$_public_addresses"
else
_node_ip=$(sed -n -e "$((_n + 1))p" "$_nodes_all")
_db_dir="${CTDB_BASE}/db"
- for _d in "volatile" "persistent" "state" ; do
+ for _d in "volatile" "persistent" "state"; do
mkdir -p "${_db_dir}/${_d}"
done
(
IFS='|'
- for _c in $_commented_config ; do
+ for _c in $_commented_config; do
# Quote all backslashes due to double-quotes
sed -i -e "s|^\\t\\(${_c}\\) = |\\t# \\1 = |" \
- "${CTDB_BASE}/ctdb.conf"
+ "${CTDB_BASE}/ctdb.conf"
done
)
done
}
-local_daemons_ssh_usage ()
+local_daemons_ssh_usage()
{
cat >&2 <<EOF
usage: $0 <directory> ssh [ -n ] <ip> <command>
exit 1
}
-local_daemons_ssh ()
+local_daemons_ssh()
{
- if [ $# -lt 2 ] ; then
+ if [ $# -lt 2 ]; then
local_daemons_ssh_usage
fi
# Only try to respect ssh -n option, others can't be used so discard them
_close_stdin=false
- while getopts "nh?" _opt ; do
+ while getopts "nh?" _opt; do
case "$_opt" in
n) _close_stdin=true ;;
- \?|h) local_daemons_ssh_usage ;;
+ \? | h) local_daemons_ssh_usage ;;
*) : ;;
esac
done
shift $((OPTIND - 1))
- if [ $# -lt 2 ] ; then
+ if [ $# -lt 2 ]; then
local_daemons_ssh_usage
fi
_nodes="${directory}/nodes"
# IP address of node. onnode can pass hostnames but not in these tests
- _ip="$1" ; shift
+ _ip="$1"
+ shift
# "$*" is command
-
# Determine the correct CTDB base directory
_num=$(awk -v ip="$_ip" '$1 == ip { print NR }' "$_nodes")
_node=$((_num - 1))
export CTDB_BASE="${directory}/node.${_node}"
- if [ ! -d "$CTDB_BASE" ] ; then
+ if [ ! -d "$CTDB_BASE" ]; then
die "$0 ssh: Unable to find base for node ${_ip}"
fi
- if $_close_stdin ; then
+ if $_close_stdin; then
exec sh -c "$*" </dev/null
else
exec sh -c "$*"
fi
}
-onnode_common ()
+onnode_common()
{
# onnode will execute this, which fakes ssh against local daemons
export ONNODE_SSH="${0} ${directory} ssh"
export CTDB_BASE="$directory"
}
-local_daemons_generic_usage ()
+local_daemons_generic_usage()
{
cat >&2 <<EOF
usage: $0 <directory> ${1} <nodes>
exit 1
}
-local_daemons_start_socket_wrapper ()
+local_daemons_start_socket_wrapper()
{
_so="${directory}/libsocket-wrapper.so"
_d="${directory}/sw"
- if [ -d "$_d" ] && [ -f "$_so" ] ; then
+ if [ -d "$_d" ] && [ -f "$_so" ]; then
export SOCKET_WRAPPER_DIR="$_d"
export LD_PRELOAD="$_so"
export SOCKET_WRAPPER_DIR_ALLOW_ORIG="1"
fi
}
-local_daemons_start ()
+local_daemons_start()
{
- if [ $# -ne 1 ] || [ "$1" = "-h" ] ; then
+ if [ $# -ne 1 ] || [ "$1" = "-h" ]; then
local_daemons_generic_usage "start"
fi
onnode -i "$_nodes" "${VALGRIND:-} ctdbd"
}
-local_daemons_stop ()
+local_daemons_stop()
{
- if [ $# -ne 1 ] || [ "$1" = "-h" ] ; then
+ if [ $# -ne 1 ] || [ "$1" = "-h" ]; then
local_daemons_generic_usage "stop"
fi
fi"
}
-local_daemons_onnode_usage ()
+local_daemons_onnode_usage()
{
cat >&2 <<EOF
usage: $0 <directory> onnode <nodes> <command>...
exit 1
}
-local_daemons_onnode ()
+local_daemons_onnode()
{
- if [ $# -lt 2 ] || [ "$1" = "-h" ] ; then
+ if [ $# -lt 2 ] || [ "$1" = "-h" ]; then
local_daemons_onnode_usage
fi
onnode "$_nodes" "$@"
}
-local_daemons_print_socket ()
+local_daemons_print_socket()
{
- if [ $# -ne 1 ] || [ "$1" = "-h" ] ; then
+ if [ $# -ne 1 ] || [ "$1" = "-h" ]; then
local_daemons_generic_usage "print-socket"
fi
onnode -q "$_nodes" "${VALGRIND:-} ${_path} socket ctdbd"
}
-local_daemons_print_log ()
+local_daemons_print_log()
{
- if [ $# -ne 1 ] || [ "$1" = "-h" ] ; then
+ if [ $# -ne 1 ] || [ "$1" = "-h" ]; then
local_daemons_generic_usage "print-log"
fi
# shellcheck disable=SC2016
# $CTDB_BASE must only be expanded under onnode, not in top-level shell
onnode -q "$_nodes" 'cat ${CTDB_BASE}/log.ctdb' |
- sort
+ sort
}
-local_daemons_tail_log ()
+local_daemons_tail_log()
{
- if [ $# -ne 1 ] || [ "$1" = "-h" ] ; then
+ if [ $# -ne 1 ] || [ "$1" = "-h" ]; then
local_daemons_generic_usage "tail-log"
fi
tail -f $(onnode -q "$_nodes" 'echo ${CTDB_BASE}/log.ctdb')
}
-usage ()
+usage()
{
cat <<EOF
usage: $0 <directory> <command> [ <options>... ]
exit 1
}
-if [ $# -lt 2 ] ; then
+if [ $# -lt 2 ]; then
usage
fi