TMP: add a ctdb snapshot of current ctdb master (git://git.samba.org/ctdb.git) to...
[obnox/samba/samba-obnox.git] / ctdb / tests / simple / 23_ctdb_moveip.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that  'ctdb moveip' allows movement of public IPs between cluster nodes.
7
8 To work, this test unsets DeterministicIPs and sets NoIPFailback.
9
10 This test does not do any network level checks that the IP address is
11 no longer reachable but simply trusts 'ctdb ip' that the address has
12 been deleted.
13
14 Prerequisites:
15
16 * An active CTDB cluster with at least 2 active nodes.
17
18 Steps:
19
20 1. Verify that the status on all of the ctdb nodes is 'OK'.
21 2. Use 'ctdb ip' on one of the nodes to list the IP addresses being
22    served.
23 3. Use 'ctdb moveip' to move an address from one node to another.
24 4. Verify that the IP is no longer being hosted by the first node and is now being hosted by the second node.
25
26 Expected results:
27
28 * 'ctdb moveip' allows an IP address to be moved between cluster nodes.
29 EOF
30 }
31
32 . ctdb_test_functions.bash
33
34 ctdb_test_init "$@"
35
36 set -e
37
38 cluster_is_healthy
39
40 # Reset configuration
41 ctdb_restart_when_done
42
43 try_command_on_node 0 "$CTDB listnodes | wc -l"
44 num_nodes="$out"
45 echo "There are $num_nodes nodes..."
46
47 if [ $num_nodes -lt 2 ] ; then
48     echo "Less than 2 nodes!"
49     exit 1
50 fi
51
52 echo "Getting list of public IPs..."
53 all_ips_on_node -v 0
54
55 sanity_check_ips "$out"
56
57 # Select an IP/node to move.
58 num_ips=$(echo "$out" | wc -l)
59 num_to_move=$(($RANDOM % $num_ips))
60
61 # Find the details in the list.
62 i=0
63 while [ $i -le $num_to_move ] ; do
64     read ip_to_move test_node
65     i=$(($i + 1))
66 done <<<"$out"
67
68 # Can only move address to a node that is willing to host $ip_to_move.
69 # This inefficient but shouldn't take long or get stuck.
70 to_node=$test_node
71 while [ $test_node -eq $to_node ] ; do
72     n=$(($RANDOM % $num_ips))
73     i=0
74     while [ $i -le $n ] ; do
75         read x to_node
76         i=$(($i + 1))
77     done <<<"$out"
78 done
79
80 echo "Turning off DeterministicIPs..."
81 try_command_on_node 0 $CTDB setvar DeterministicIPs 0 -n all
82
83 echo "Turning on NoIPFailback..."
84 try_command_on_node 0 $CTDB setvar NoIPFailback 1 -n all
85
86 echo "Attempting to move ${ip_to_move} from node ${test_node} to node ${to_node}."
87 try_command_on_node $test_node $CTDB moveip $ip_to_move $to_node
88
89 if wait_until_ips_are_on_nodeglob "[!${test_node}]" $ip_to_move ; then
90     echo "IP moved from ${test_node}."
91 else
92     echo "BAD: IP didn't move from ${test_node}."
93     exit 1
94 fi
95
96 if wait_until_ips_are_on_nodeglob "$to_node" $ip_to_move ; then
97     echo "IP moved to ${to_node}."
98 else
99     echo "BAD: IP didn't move to ${to_node}."
100     exit 1
101 fi