summaryrefslogtreecommitdiffstats
path: root/ctdb/tests/simple/23_ctdb_moveip.sh
blob: 7c09e58503021fd165f1f4f42a0c9f8cab9cb965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash

test_info()
{
    cat <<EOF
Verify that  'ctdb moveip' allows movement of public IPs between cluster nodes.

To work, this test unsets DeterministicIPs and sets NoIPFailback.

This test does not do any network level checks that the IP address is
no longer reachable but simply trusts 'ctdb ip' that the address has
been deleted.

Prerequisites:

* An active CTDB cluster with at least 2 active nodes.

Steps:

1. Verify that the status on all of the ctdb nodes is 'OK'.
2. Use 'ctdb ip' on one of the nodes to list the IP addresses being
   served.
3. Use 'ctdb moveip' to move an address from one node to another.
4. Verify that the IP is no longer being hosted by the first node and is now being hosted by the second node.

Expected results:

* 'ctdb moveip' allows an IP address to be moved between cluster nodes.
EOF
}

. "${TEST_SCRIPTS_DIR}/integration.bash"

ctdb_test_init "$@"

set -e

cluster_is_healthy

# Reset configuration
ctdb_restart_when_done

try_command_on_node 0 "$CTDB listnodes | wc -l"
num_nodes="$out"
echo "There are $num_nodes nodes..."

if [ $num_nodes -lt 2 ] ; then
    echo "Less than 2 nodes!"
    exit 1
fi

echo "Getting list of public IPs..."
all_ips_on_node -v 0

sanity_check_ips "$out"

# Select an IP/node to move.
num_ips=$(echo "$out" | wc -l)
num_to_move=$(($RANDOM % $num_ips))

# Find the details in the list.
i=0
while [ $i -le $num_to_move ] ; do
    read ip_to_move test_node
    i=$(($i + 1))
done <<<"$out"

# Can only move address to a node that is willing to host $ip_to_move.
# This inefficient but shouldn't take long or get stuck.
to_node=$test_node
while [ $test_node -eq $to_node ] ; do
    n=$(($RANDOM % $num_ips))
    i=0
    while [ $i -le $n ] ; do
	read x to_node
	i=$(($i + 1))
    done <<<"$out"
done

echo "Turning off DeterministicIPs..."
try_command_on_node 0 $CTDB setvar DeterministicIPs 0 -n all

echo "Turning on NoIPFailback..."
try_command_on_node 0 $CTDB setvar NoIPFailback 1 -n all

echo "Attempting to move ${ip_to_move} from node ${test_node} to node ${to_node}."
try_command_on_node $test_node $CTDB moveip $ip_to_move $to_node

if wait_until_ips_are_on_nodeglob "[!${test_node}]" $ip_to_move ; then
    echo "IP moved from ${test_node}."
else
    echo "BAD: IP didn't move from ${test_node}."
    exit 1
fi

if wait_until_ips_are_on_nodeglob "$to_node" $ip_to_move ; then
    echo "IP moved to ${to_node}."
else
    echo "BAD: IP didn't move to ${to_node}."
    exit 1
fi