From cbda1a78dc8a121e01e014144fe4f35ca83c2c62 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 3 Jul 2023 09:26:34 +1000 Subject: [PATCH] ctdb-tests: Reformat with "shfmt -w -p -i 0 -fn" Best reviewed with "git show -w". Signed-off-by: Martin Schwenke Reviewed-by: Andreas Schneider --- .../UNIT/eventscripts/scripts/00.ctdb.sh | 4 +- .../UNIT/eventscripts/scripts/01.reclock.sh | 6 +- .../UNIT/eventscripts/scripts/05.system.sh | 14 +- .../tests/UNIT/eventscripts/scripts/06.nfs.sh | 2 +- .../UNIT/eventscripts/scripts/10.interface.sh | 12 +- .../UNIT/eventscripts/scripts/11.natgw.sh | 27 +- .../eventscripts/scripts/13.per_ip_routing.sh | 33 +- .../eventscripts/scripts/20.multipathd.sh | 7 +- .../UNIT/eventscripts/scripts/31.clamd.sh | 2 +- .../UNIT/eventscripts/scripts/40.vsftpd.sh | 4 +- .../UNIT/eventscripts/scripts/41.httpd.sh | 8 +- .../UNIT/eventscripts/scripts/48.netbios.sh | 8 +- .../UNIT/eventscripts/scripts/49.winbind.sh | 6 +- .../UNIT/eventscripts/scripts/50.samba.sh | 12 +- .../tests/UNIT/eventscripts/scripts/60.nfs.sh | 94 ++--- .../tests/UNIT/eventscripts/scripts/91.lvs.sh | 12 +- .../UNIT/eventscripts/scripts/debug_locks.sh | 137 ++++--- ctdb/tests/UNIT/eventscripts/scripts/local.sh | 348 +++++++++--------- .../eventscripts/scripts/statd-callout.sh | 18 +- 19 files changed, 394 insertions(+), 360 deletions(-) diff --git a/ctdb/tests/UNIT/eventscripts/scripts/00.ctdb.sh b/ctdb/tests/UNIT/eventscripts/scripts/00.ctdb.sh index 610924b702e..a192e058edf 100644 --- a/ctdb/tests/UNIT/eventscripts/scripts/00.ctdb.sh +++ b/ctdb/tests/UNIT/eventscripts/scripts/00.ctdb.sh @@ -1,4 +1,4 @@ -setup () +setup() { setup_dbdir setup_date @@ -15,7 +15,7 @@ setup () " } -result_filter () +result_filter() { _date="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" _time="[0-9][0-9][0-9][0-9][0-9][0-9]" diff --git a/ctdb/tests/UNIT/eventscripts/scripts/01.reclock.sh b/ctdb/tests/UNIT/eventscripts/scripts/01.reclock.sh index cc1f086bb2c..7365dd8e114 100644 --- a/ctdb/tests/UNIT/eventscripts/scripts/01.reclock.sh +++ b/ctdb/tests/UNIT/eventscripts/scripts/01.reclock.sh @@ -1,13 +1,13 @@ -setup () +setup() { - if [ $# -eq 1 ] ; then + if [ $# -eq 1 ]; then reclock="$1" else reclock="${CTDB_TEST_TMP_DIR}/reclock_subdir/rec.lock" fi CTDB_RECOVERY_LOCK="$reclock" - if [ -n "$CTDB_RECOVERY_LOCK" ] ; then + if [ -n "$CTDB_RECOVERY_LOCK" ]; then cat >>"${CTDB_BASE}/ctdb.conf" <"$FAKE_NETSTAT_TCP_ESTABLISHED_FILE" } -setup_tcp_connections_unkillable () +setup_tcp_connections_unkillable() { # These connections are listed by the "ss" stub but are not # killed by the "ctdb killtcp" stub. So killing these @@ -44,7 +44,7 @@ setup_tcp_connections_unkillable () # arg1 is interface name, arg2 is currently active slave (use "None" # if none), arg3 is MII status ("up" or "down"). -setup_bond () +setup_bond() { _iface="$1" _slave="${2:-${_iface}_sl_0}" diff --git a/ctdb/tests/UNIT/eventscripts/scripts/11.natgw.sh b/ctdb/tests/UNIT/eventscripts/scripts/11.natgw.sh index 511dc27a694..d3f591f4de1 100644 --- a/ctdb/tests/UNIT/eventscripts/scripts/11.natgw.sh +++ b/ctdb/tests/UNIT/eventscripts/scripts/11.natgw.sh @@ -1,4 +1,4 @@ -setup () +setup() { debug "Setting up NAT gateway" @@ -9,10 +9,10 @@ setup () # A separate function for this makes sense because it can be done # multiple times per test -setup_ctdb_natgw () +setup_ctdb_natgw() { # Read from stdin - while read _ip _opts ; do + while read _ip _opts; do case "$_opts" in leader) export FAKE_CTDB_NATGW_LEADER="$_ip" @@ -43,11 +43,11 @@ CTDB_NATGW_DEFAULT_GATEWAY="10.1.1.254" EOF } -ok_natgw_leader_ip_addr_show () +ok_natgw_leader_ip_addr_show() { _mac=$(echo "$CTDB_NATGW_PUBLIC_IFACE" | - cksum | - sed -r -e 's@(..)(..)(..).*@fe:fe:fe:\1:\2:\3@') + cksum | + sed -r -e 's@(..)(..)(..).*@fe:fe:fe:\1:\2:\3@') # This is based on CTDB_NATGW_PUBLIC_IP _brd="10.1.1.255" @@ -60,11 +60,11 @@ ok_natgw_leader_ip_addr_show () EOF } -ok_natgw_follower_ip_addr_show () +ok_natgw_follower_ip_addr_show() { _mac=$(echo "$CTDB_NATGW_PUBLIC_IFACE" | - cksum | - sed -r -e 's@(..)(..)(..).*@fe:fe:fe:\1:\2:\3@') + cksum | + sed -r -e 's@(..)(..)(..).*@fe:fe:fe:\1:\2:\3@') ok < mtu 1500 qdisc pfifo_fast state UP qlen 1000 @@ -72,12 +72,12 @@ ok_natgw_follower_ip_addr_show () EOF } -ok_natgw_leader_static_routes () +ok_natgw_leader_static_routes() { _nl=" " _t="" - for _i in $CTDB_NATGW_STATIC_ROUTES ; do + for _i in $CTDB_NATGW_STATIC_ROUTES; do # This is intentionally different to the code in 11.natgw ;-) case "$_i" in *@*) @@ -87,6 +87,7 @@ ok_natgw_leader_static_routes () *) _net="$_i" _gw="$CTDB_NATGW_DEFAULT_GATEWAY" + ;; esac [ -n "$_gw" ] || continue @@ -97,12 +98,12 @@ ok_natgw_leader_static_routes () ok "$_t" } -ok_natgw_follower_static_routes () +ok_natgw_follower_static_routes() { _nl=" " _t="" - for _i in $CTDB_NATGW_STATIC_ROUTES ; do + for _i in $CTDB_NATGW_STATIC_ROUTES; do # This is intentionally different to the code in 11.natgw ;-) _net=$(echo "$_i" | sed -e 's|@.*||') diff --git a/ctdb/tests/UNIT/eventscripts/scripts/13.per_ip_routing.sh b/ctdb/tests/UNIT/eventscripts/scripts/13.per_ip_routing.sh index e57e91a50c2..e2e29a64931 100644 --- a/ctdb/tests/UNIT/eventscripts/scripts/13.per_ip_routing.sh +++ b/ctdb/tests/UNIT/eventscripts/scripts/13.per_ip_routing.sh @@ -1,4 +1,4 @@ -setup () +setup() { setup_public_addresses @@ -18,25 +18,28 @@ EOF # Create policy routing configuration in $CTDB_PER_IP_ROUTING_CONF. # $1 is the number of assigned IPs to use (, all), defaulting to # 1. If $2 is "default" then a default route is also added. -create_policy_routing_config () +create_policy_routing_config() { _num_ips="${1:-1}" _should_add_default="$2" ctdb_get_my_public_addresses | - if [ "$_num_ips" = "all" ] ; then - cat - else - { head -n "$_num_ips" ; cat >/dev/null ; } - fi | - while read _dev _ip _bits ; do - _net=$(ipv4_host_addr_to_net "$_ip" "$_bits") - _gw="${_net%.*}.254" # a dumb, calculated default + if [ "$_num_ips" = "all" ]; then + cat + else + { + head -n "$_num_ips" + cat >/dev/null + } + fi | + while read _dev _ip _bits; do + _net=$(ipv4_host_addr_to_net "$_ip" "$_bits") + _gw="${_net%.*}.254" # a dumb, calculated default - echo "$_ip $_net" + echo "$_ip $_net" - if [ "$_should_add_default" = "default" ] ; then - echo "$_ip 0.0.0.0/0 $_gw" - fi - done >"$CTDB_PER_IP_ROUTING_CONF" + if [ "$_should_add_default" = "default" ]; then + echo "$_ip 0.0.0.0/0 $_gw" + fi + done >"$CTDB_PER_IP_ROUTING_CONF" } diff --git a/ctdb/tests/UNIT/eventscripts/scripts/20.multipathd.sh b/ctdb/tests/UNIT/eventscripts/scripts/20.multipathd.sh index 2a69ae868b4..9add0bca209 100644 --- a/ctdb/tests/UNIT/eventscripts/scripts/20.multipathd.sh +++ b/ctdb/tests/UNIT/eventscripts/scripts/20.multipathd.sh @@ -1,16 +1,17 @@ -setup () +setup() { _failures="" _devices="" - for i ; do + for i; do case "$i" in \!*) _t="${i#!}" echo "Marking ${_t} as having no active paths" _failures="${_failures}${_failures:+ }${_t}" - ;; + ;; *) _t="$i" + ;; esac _devices="${_devices}${_devices:+ }${_t}" done diff --git a/ctdb/tests/UNIT/eventscripts/scripts/31.clamd.sh b/ctdb/tests/UNIT/eventscripts/scripts/31.clamd.sh index 8fe3bbc6186..27016cb296c 100644 --- a/ctdb/tests/UNIT/eventscripts/scripts/31.clamd.sh +++ b/ctdb/tests/UNIT/eventscripts/scripts/31.clamd.sh @@ -1,4 +1,4 @@ -setup () +setup() { setup_script_options <"$_rc_file" echo "ERROR: ${_rpc_check_out}" >>"$_out" @@ -306,18 +308,18 @@ program $_rpc_service${_ver:+ version }${_ver} is not available" echo 0 >"$_rc_file" fi - if [ $restart_every -gt 0 ] && \ - [ $(($_numfails % $restart_every)) -eq 0 ] ; then - if ! $_unhealthy ; then + if [ $restart_every -gt 0 ] && + [ $(($_numfails % $restart_every)) -eq 0 ]; then + if ! $_unhealthy; then echo "WARNING: ${_rpc_check_out}" >>"$_out" fi - echo "Trying to restart service \"${_rpc_service}\"..."\ - >>"$_out" + echo "Trying to restart service \"${_rpc_service}\"..." \ + >>"$_out" guess_output "$service_stop_cmd" >>"$_out" - if [ -n "$service_debug_cmd" ] ; then + if [ -n "$service_debug_cmd" ]; then $service_debug_cmd 2>&1 >>"$_out" fi @@ -331,18 +333,18 @@ program $_rpc_service${_ver:+ version }${_ver} is not available" rm -f "$_out" "$_rc_file" } -program_stack_traces () +program_stack_traces() { _prog="$1" _max="${2:-1}" _count=1 - if [ "$_prog" = "nfsd" ] ; then + if [ "$_prog" = "nfsd" ]; then _pids="$FAKE_NFSD_THREAD_PIDS" else _pids="$FAKE_RPC_THREAD_PIDS" fi - for _pid in $_pids ; do + for _pid in $_pids; do [ $_count -le $_max ] || break program_stack_trace "$_prog" "$_pid" @@ -373,11 +375,11 @@ program_stack_traces () # These arguments can allow a service to be started or stopped # before a particular iteration. # -nfs_iterate_test () +nfs_iterate_test() { _repeats="$1" _rpc_service="$2" - if [ -n "$2" ] ; then + if [ -n "$2" ]; then shift 2 else shift @@ -386,10 +388,10 @@ nfs_iterate_test () echo "Running $_repeats iterations of \"$script $event\" $args" _iterate_failcount=0 - for _iteration in $(seq 1 $_repeats) ; do + for _iteration in $(seq 1 $_repeats); do # This is not a numerical comparison because $1 will # often not be set. - if [ "$_iteration" = "$1" ] ; then + if [ "$_iteration" = "$1" ]; then debug </dev/null 2>&1 ; then + >/dev/null 2>&1; then _ok=true fi fi - if $_ok ; then + if $_ok; then _iterate_failcount=0 else _iterate_failcount=$(($_iterate_failcount + 1)) @@ -422,14 +424,14 @@ EOF fi _out=$(simple_test 2>&1) _ret=$? - if "$CTDB_TEST_VERBOSE" || [ $_ret -ne 0 ] ; then + if "$CTDB_TEST_VERBOSE" || [ $_ret -ne 0 ]; then cat <"$CTDB_LVS_NODES" } -check_ipvsadm () +check_ipvsadm() { - if [ "$1" = "NULL" ] ; then + if [ "$1" = "NULL" ]; then required_result 0 < mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 diff --git a/ctdb/tests/UNIT/eventscripts/scripts/debug_locks.sh b/ctdb/tests/UNIT/eventscripts/scripts/debug_locks.sh index c303c60f777..7fe53604099 100644 --- a/ctdb/tests/UNIT/eventscripts/scripts/debug_locks.sh +++ b/ctdb/tests/UNIT/eventscripts/scripts/debug_locks.sh @@ -1,4 +1,4 @@ -setup () +setup() { setup_dbdir } @@ -8,20 +8,20 @@ result_filter() sed -e 's|\( of debug locks PID=\)[0-9]*|\1PID|' } -tdb_path () +tdb_path() { echo "${CTDB_DBDIR}/${1}.${FAKE_CTDB_PNN}" } -fake_file_id () +fake_file_id() { _path="$1" echo "$FAKE_FILE_ID_MAP" | - awk -v path="$_path" '$1 == path { print $2 }' + awk -v path="$_path" '$1 == path { print $2 }' } -fake_stack_trace () +fake_stack_trace() { _pid="$1" _command="${2:-smbd}" @@ -47,7 +47,7 @@ EOF esac } -do_test () +do_test() { _holder_scope="$1" _holder_state="$2" @@ -56,26 +56,28 @@ do_test () _lock_helper_pid="4132032" - FAKE_PS_MAP=$(cat < POSIX ADVISORY WRITE ${_lock_helper_pid} ${_locking_tdb_id} 168 170 EOF - ) - elif [ "$_helper_scope" = "RECORD" ] && \ - [ "$_lock_type" = "FCNTL" ] ; then - _helper_lock=$(cat < POSIX ADVISORY WRITE ${_lock_helper_pid} ${_locking_tdb_id} 112736 112736 EOF - ) + ) fi - _t=$(cat <&2 else cat >&2 fi } else - debug () { : ; } + debug() + { + : + } fi ###################################################################### @@ -70,17 +72,17 @@ fi # Default is to use script name with ".options" appended. With # arguments, this can specify an alternate script name (and # component). -setup_script_options () +setup_script_options() { - if [ $# -eq 2 ] ; then + if [ $# -eq 2 ]; then _script="$2" - elif [ $# -eq 0 ] ; then + elif [ $# -eq 0 ]; then _script="" else die "usage: setup_script_options [ component script ]" fi - if [ -n "$_script" ] ; then + if [ -n "$_script" ]; then _options="${CTDB_BASE}/events/legacy/${_script}.options" else _options="${script_dir}/${script%.script}.options" @@ -92,7 +94,7 @@ setup_script_options () . "$_options" } -setup_dbdir () +setup_dbdir() { export CTDB_DBDIR_BASE="${CTDB_TEST_TMP_DIR}/db" CTDB_DBDIR="${CTDB_DBDIR_BASE}/volatile" @@ -109,31 +111,31 @@ EOF mkdir -p "$CTDB_DBDIR_STATE" } -setup_date () +setup_date() { export FAKE_DATE_OUTPUT="$1" } -setup_tcp_listen () +setup_tcp_listen() { export FAKE_TCP_LISTEN="$*" } -tcp_port_listening () +tcp_port_listening() { - for _i ; do - FAKE_TCP_LISTEN="${FAKE_TCP_LISTEN} ${_i}" + for _i; do + FAKE_TCP_LISTEN="${FAKE_TCP_LISTEN} ${_i}" done } -tcp_port_down () +tcp_port_down() { _port="$1" debug "Marking TCP port \"${_port}\" as not listening" _t="" - for _i in $FAKE_TCP_LISTEN ; do - if [ "$_i" = "$_port" ] ; then + for _i in $FAKE_TCP_LISTEN; do + if [ "$_i" = "$_port" ]; then continue fi _t="${_t} ${_i}" @@ -142,43 +144,44 @@ tcp_port_down () FAKE_TCP_LISTEN="$_t" } -setup_unix_listen () +setup_unix_listen() { export FAKE_NETSTAT_UNIX_LISTEN="$*" } -unix_socket_listening () +unix_socket_listening() { _s="$1" FAKE_NETSTAT_UNIX_LISTEN="${FAKE_NETSTAT_UNIX_LISTEN} ${_s}" } -setup_shares () +setup_shares() { debug "Setting up shares (3 existing shares)" # Create 3 fake shares/exports. export FAKE_SHARES="" - for i in $(seq 1 3) ; do + for i in $(seq 1 3); do _s="${CTDB_TEST_TMP_DIR}/shares/share${i}" mkdir -p "$_s" FAKE_SHARES="${FAKE_SHARES}${FAKE_SHARES:+ }${_s}" done } -shares_missing () +shares_missing() { # Mark some shares as non-existent - _fmt="$1" ; shift + _fmt="$1" + shift _out="" _nl=" " _n=1 - for _i in $FAKE_SHARES ; do - for _j ; do - if [ $_n -ne "$_j" ] ; then + for _i in $FAKE_SHARES; do + for _j; do + if [ $_n -ne "$_j" ]; then continue fi @@ -193,82 +196,85 @@ shares_missing () echo "$_out" } -_ethtool_setup () +_ethtool_setup() { FAKE_ETHTOOL_LINK_DOWN="${FAKE_NETWORK_STATE}/ethtool-link-down" export FAKE_ETHTOOL_LINK_DOWN mkdir -p "$FAKE_ETHTOOL_LINK_DOWN" } -ethtool_interfaces_down () +ethtool_interfaces_down() { _ethtool_setup - for _i ; do + for _i; do echo "Marking interface $_i DOWN for ethtool" touch "${FAKE_ETHTOOL_LINK_DOWN}/${_i}" done } -ethtool_interfaces_up () +ethtool_interfaces_up() { _ethtool_setup - for _i ; do + for _i; do echo "Marking interface $_i UP for ethtool" rm -f "${FAKE_ETHTOOL_LINK_DOWN}/${_i}" done } -dump_routes () +dump_routes() { - echo "# ip rule show" - ip rule show + echo "# ip rule show" + ip rule show - ip rule show | - while read _p _x _i _x _t ; do - # Remove trailing colon after priority/preference. - _p="${_p%:}" - # Only remove rules that match our priority/preference. - [ "$CTDB_PER_IP_ROUTING_RULE_PREF" = "$_p" ] || continue + ip rule show | + while read _p _x _i _x _t; do + # Remove trailing colon after priority/preference. + _p="${_p%:}" + # Only remove rules that match our priority/preference. + [ "$CTDB_PER_IP_ROUTING_RULE_PREF" = "$_p" ] || continue - echo "# ip route show table $_t" - ip route show table "$_t" - done + echo "# ip route show table $_t" + ip route show table "$_t" + done } # Copied from 13.per_ip_routing for now... so this is lazy testing :-( -ipv4_host_addr_to_net () +ipv4_host_addr_to_net() { - _host="$1" - _maskbits="$2" + _host="$1" + _maskbits="$2" - # Convert the host address to an unsigned long by splitting out - # the octets and doing the math. - _host_ul=0 - for _o in $(export IFS="." ; echo $_host) ; do - _host_ul=$(( ($_host_ul << 8) + $_o)) # work around Emacs color bug - done + # Convert the host address to an unsigned long by splitting out + # the octets and doing the math. + _host_ul=0 + for _o in $( + export IFS="." + echo $_host + ); do + _host_ul=$((($_host_ul << 8) + $_o)) # work around Emacs color bug + done - # Calculate the mask and apply it. - _mask_ul=$(( 0xffffffff << (32 - $_maskbits) )) - _net_ul=$(( $_host_ul & $_mask_ul )) + # Calculate the mask and apply it. + _mask_ul=$((0xffffffff << (32 - $_maskbits))) + _net_ul=$(($_host_ul & $_mask_ul)) - # Now convert to a network address one byte at a time. - _net="" - for _o in $(seq 1 4) ; do - _net="$(($_net_ul & 255))${_net:+.}${_net}" - _net_ul=$(($_net_ul >> 8)) - done + # Now convert to a network address one byte at a time. + _net="" + for _o in $(seq 1 4); do + _net="$(($_net_ul & 255))${_net:+.}${_net}" + _net_ul=$(($_net_ul >> 8)) + done - echo "${_net}/${_maskbits}" + echo "${_net}/${_maskbits}" } ###################################################################### # CTDB fakery -setup_numnodes () +setup_numnodes() { export FAKE_CTDB_NUMNODES="${1:-3}" echo "Setting up CTDB with ${FAKE_CTDB_NUMNODES} fake nodes" @@ -276,7 +282,7 @@ setup_numnodes () # For now this creates the same public addresses each time. However, # it could be made more flexible. -setup_public_addresses () +setup_public_addresses() { _f="${CTDB_BASE}/public_addresses" @@ -294,117 +300,122 @@ setup_public_addresses () 10.0.1.3/24 dev456 EOF - # Needed for IP allocation - setup_numnodes + # Needed for IP allocation + setup_numnodes } # Need to cope with ctdb_get_pnn(). If a test changes PNN then it # needs to be using a different state directory, otherwise the wrong # PNN can already be cached in the state directory. -ctdb_set_pnn () +ctdb_set_pnn() { - export FAKE_CTDB_PNN="$1" - echo "Setting up PNN ${FAKE_CTDB_PNN}" + export FAKE_CTDB_PNN="$1" + echo "Setting up PNN ${FAKE_CTDB_PNN}" - CTDB_SCRIPT_VARDIR="${CTDB_TEST_TMP_DIR}/scripts/${FAKE_CTDB_PNN}" - export CTDB_SCRIPT_VARDIR - mkdir -p "$CTDB_SCRIPT_VARDIR" + CTDB_SCRIPT_VARDIR="${CTDB_TEST_TMP_DIR}/scripts/${FAKE_CTDB_PNN}" + export CTDB_SCRIPT_VARDIR + mkdir -p "$CTDB_SCRIPT_VARDIR" } -ctdb_get_interfaces () +ctdb_get_interfaces() { - # The echo/subshell forces all the output onto 1 line. - echo $(ctdb ifaces -X | awk -F'|' 'FNR > 1 {print $2}') + # The echo/subshell forces all the output onto 1 line. + echo $(ctdb ifaces -X | awk -F'|' 'FNR > 1 {print $2}') } -ctdb_get_1_interface () +ctdb_get_1_interface() { - _t=$(ctdb_get_interfaces) - echo ${_t%% *} + _t=$(ctdb_get_interfaces) + echo ${_t%% *} } # Print public addresses on this node as: interface IP maskbits # Each line is suitable for passing to takeip/releaseip -ctdb_get_my_public_addresses () +ctdb_get_my_public_addresses() { - ctdb ip -v -X | { - read _x # skip header line + ctdb ip -v -X | { + read _x # skip header line - while IFS="|" read _x _ip _x _iface _x ; do - [ -n "$_iface" ] || continue - while IFS="/$IFS" read _i _maskbits _x ; do - if [ "$_ip" = "$_i" ] ; then - echo $_iface $_ip $_maskbits - break - fi - done <"${CTDB_BASE}/public_addresses" - done - } + while IFS="|" read _x _ip _x _iface _x; do + [ -n "$_iface" ] || continue + while IFS="/$IFS" read _i _maskbits _x; do + if [ "$_ip" = "$_i" ]; then + echo $_iface $_ip $_maskbits + break + fi + done <"${CTDB_BASE}/public_addresses" + done + } } # Prints the 1st public address as: interface IP maskbits # This is suitable for passing to takeip/releaseip -ctdb_get_1_public_address () +ctdb_get_1_public_address() { - ctdb_get_my_public_addresses | { head -n 1 ; cat >/dev/null ; } + ctdb_get_my_public_addresses | { + head -n 1 + cat >/dev/null + } } # Check the routes against those that are expected. $1 is the number # of assigned IPs to use (, all), defaulting to 1. If $2 is # "default" then expect default routes to have been added. -check_routes () +check_routes() { - _num_ips="${1:-1}" - _should_add_default="$2" + _num_ips="${1:-1}" + _should_add_default="$2" - _policy_rules="" - _policy_routes="" + _policy_rules="" + _policy_routes="" - ctdb_get_my_public_addresses | - if [ "$_num_ips" = "all" ] ; then - cat - else - { head -n "$_num_ips" ; cat >/dev/null ; } - fi | { - while read _dev _ip _bits ; do - _net=$(ipv4_host_addr_to_net "$_ip" "$_bits") - _gw="${_net%.*}.254" # a dumb, calculated default + ctdb_get_my_public_addresses | + if [ "$_num_ips" = "all" ]; then + cat + else + { + head -n "$_num_ips" + cat >/dev/null + } + fi | { + while read _dev _ip _bits; do + _net=$(ipv4_host_addr_to_net "$_ip" "$_bits") + _gw="${_net%.*}.254" # a dumb, calculated default - _policy_rules="${_policy_rules} + _policy_rules="${_policy_rules} ${CTDB_PER_IP_ROUTING_RULE_PREF}: from $_ip lookup ctdb.$_ip " - _policy_routes="${_policy_routes} + _policy_routes="${_policy_routes} # ip route show table ctdb.$_ip $_net dev $_dev scope link " - if [ "$_should_add_default" = "default" ] ; then - _policy_routes="${_policy_routes} + if [ "$_should_add_default" = "default" ]; then + _policy_routes="${_policy_routes} default via $_gw dev $_dev " - fi - done + fi + done - ok < ${_cip}, MON_NAME=${_sip}, STATE=${_state_even} SM_NOTIFY: ${_sip} -> ${_cip}, MON_NAME=${NFS_HOSTNAME}, STATE=${_state_even}