ctdb-tests: Avoid bulk output in $out, prefer $outfile
[samba.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 This test does not do any network level checks to make sure IP
9 addresses are actually on interfaces.  It just consults "ctdb ip".
10
11 To work, this test ensures that IPAllocAlgorithm is not set to 0
12 (Deterministic IPs) and sets NoIPFailback.
13 EOF
14 }
15
16 . "${TEST_SCRIPTS_DIR}/integration.bash"
17
18 ctdb_test_init
19
20 set -e
21
22 cluster_is_healthy
23
24 select_test_node_and_ips
25
26 sanity_check_ips ()
27 {
28     echo "Sanity checking IPs..."
29
30     local x ipp prev
31     prev=""
32     while read x ipp ; do
33         [ "$ipp" = "-1" ] && break
34         if [ -n "$prev" -a "$ipp" != "$prev" ] ; then
35             echo "OK"
36             return 0
37         fi
38         prev="$ipp"
39     done <"$outfile"
40
41     echo "BAD: a node was -1 or IPs are only assigned to one node:"
42     cat "$outfile"
43     echo "Are you running an old version of CTDB?"
44     return 1
45 }
46
47 sanity_check_ips
48
49 # Find a target node - it must be willing to host $test_ip
50 try_command_on_node any "$CTDB listnodes | wc -l"
51 num_nodes="$out"
52 to_node=""
53 for i in $(seq 0 $(($num_nodes - 1)) ) ; do
54     [ $i -ne $test_node ] || continue
55     all_ips_on_node $i
56     while read ip x ; do
57         if [ "$ip" = "$test_ip" ] ; then
58             to_node="$i"
59             break 2
60         fi
61     done <"$outfile"
62 done
63
64 if [ -z "$to_node" ] ; then
65     echo "Unable to find target node"
66     exit 1
67 fi
68
69 echo "Target node is ${to_node}"
70
71 echo "Setting IPAllocAlgorithm=2 to avoid Deterministic IPs..."
72 try_command_on_node -q all $CTDB setvar IPAllocAlgorithm 2
73
74 echo "Turning on NoIPFailback..."
75 try_command_on_node -q all $CTDB setvar NoIPFailback 1
76
77 echo "Attempting to move ${test_ip} from node ${test_node} to node ${to_node}"
78 try_command_on_node $test_node $CTDB moveip $test_ip $to_node
79 wait_until_ips_are_on_node '!' $test_node $test_ip
80 wait_until_ips_are_on_node $to_node $test_ip