2019-12-10 06:50:42 +03:00
#!/usr/bin/env bash
2012-05-11 06:13:24 +04:00
2019-12-10 06:50:42 +03:00
# Verify that IPs can be reconfigured using 'ctdb reloadips'
2012-05-11 06:13:24 +04:00
2019-12-10 06:50:42 +03:00
# Various sub-tests that remove addresses from the public_addresses file
# on a node or delete the entire contents of the public_addresses file.
2012-05-11 06:13:24 +04:00
. " ${ TEST_SCRIPTS_DIR } /integration.bash "
set -e
2019-12-10 06:50:42 +03:00
ctdb_test_init
2012-05-11 06:13:24 +04:00
select_test_node_and_ips
2018-03-08 07:11:51 +03:00
try_command_on_node $test_node $CTDB_TEST_WRAPPER ctdb_base_show
addresses = " ${ out } /public_addresses "
2012-05-14 09:11:14 +04:00
echo " Public addresses file on node $test_node is \" $addresses \" "
2012-05-11 06:13:24 +04:00
backup = " ${ addresses } . $$ "
restore_public_addresses ( )
{
try_command_on_node $test_node " mv $backup $addresses >/dev/null 2>&1 || true "
}
ctdb_test_exit_hook_add restore_public_addresses
2019-05-07 08:29:19 +03:00
# ctdb reloadips will fail if it can't disable takover runs. The most
# likely reason for this is that there is already a takeover run in
# progress. We can't predict when this will happen, so retry if this
# occurs.
do_ctdb_reloadips ( )
{
local retry_max = 10
local retry_count = 0
while : ; do
2019-12-10 03:33:02 +03:00
if ctdb_onnode " $test_node " "reloadips all" ; then
2019-05-07 08:29:19 +03:00
return 0
fi
if [ " $out " != "Failed to disable takeover runs" ] ; then
return 1
fi
if [ $retry_count -ge $retry_max ] ; then
return 1
fi
retry_count = $(( retry_count + 1 ))
echo "Retrying..."
sleep_for 1
done
}
2019-05-07 08:42:49 +03:00
echo " Removing IP $test_ip from node $test_node "
try_command_on_node $test_node " mv $addresses $backup && grep -v '^ ${ test_ip } /' $backup > $addresses "
2012-05-11 06:13:24 +04:00
2019-05-07 08:29:19 +03:00
do_ctdb_reloadips
2012-05-11 06:13:24 +04:00
2019-05-07 08:42:49 +03:00
try_command_on_node $test_node $CTDB ip
2012-05-11 06:13:24 +04:00
2019-05-07 08:42:49 +03:00
if grep " ^ ${ test_ip } " <<< " $out " ; then
2012-05-11 06:13:24 +04:00
cat <<EOF
2019-05-07 08:42:49 +03:00
BAD: node $test_node can still host IP $test_ip :
2012-05-11 06:13:24 +04:00
$out
EOF
exit 1
fi
2019-05-07 08:42:49 +03:00
cat <<EOF
GOOD: node $test_node is no longer hosting IP $test_ip :
$out
EOF
2012-05-11 06:13:24 +04:00
2019-12-10 03:33:02 +03:00
ctdb_onnode " $test_node " sync
2017-02-15 11:33:02 +03:00
2019-05-07 08:42:49 +03:00
2012-05-11 06:13:24 +04:00
echo "Restoring addresses"
restore_public_addresses
2019-05-07 08:29:19 +03:00
do_ctdb_reloadips
2012-05-11 06:13:24 +04:00
echo " Getting list of public IPs on node $test_node "
try_command_on_node $test_node " $CTDB ip | tail -n +2 "
if [ -z " $out " ] ; then
echo " BAD: node $test_node has no ips "
exit 1
fi
cat <<EOF
GOOD: node $test_node has these addresses:
$out
EOF
2019-12-10 03:33:02 +03:00
ctdb_onnode " $test_node " sync
2012-05-11 06:13:24 +04:00
2019-05-07 08:42:49 +03:00
echo " Emptying public addresses file on $test_node "
try_command_on_node $test_node " mv $addresses $backup && touch $addresses "
2012-05-11 06:13:24 +04:00
2019-05-07 08:29:19 +03:00
do_ctdb_reloadips
2012-05-11 06:13:24 +04:00
2019-05-07 08:42:49 +03:00
echo " Getting list of public IPs on node $test_node "
try_command_on_node $test_node " $CTDB ip | tail -n +2 "
2012-05-11 06:13:24 +04:00
2019-05-07 08:42:49 +03:00
if [ -n " $out " ] ; then
2012-05-11 06:13:24 +04:00
cat <<EOF
2019-05-07 08:42:49 +03:00
BAD: node $test_node still has ips:
2012-05-11 06:13:24 +04:00
$out
EOF
exit 1
fi
2019-05-07 08:42:49 +03:00
echo " GOOD: no IPs left on node $test_node "