Merge branch 'martins'
[martins/samba.git] / ctdb / tests / simple / 41_ctdb_ban.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify the operation of the 'ctdb ban' command.
7
8 This is a superficial test of the 'ctdb ban' command.  It trusts
9 information from CTDB that indicates that the IP failover has
10 happened correctly.  Another test should check that the failover
11 has actually happened at the networking level.
12
13 Prerequisites:
14
15 * An active CTDB cluster with at least 2 active nodes.
16
17 Steps:
18
19 1. Verify that the status on all of the ctdb nodes is 'OK'.
20 2. Ban one of the nodes using the 'ctdb ban <timeout>' command.
21 3. Before the ban timeout expires, verify that the status of the
22    node changes to 'banned'.
23 4. Verify that the public IP addresses that were being served by
24    the node are failed over to one of the other nodes.
25 5. When the ban expires ensure that the status of the node changes
26    back to 'OK' and that the public IP addresses move back to the
27    node.
28
29 Expected results:
30
31 * The status of the banned nodes changes as expected and IP addresses
32   failover as expected.
33 EOF
34 }
35
36 . ctdb_test_functions.bash
37
38 ctdb_test_init "$@"
39
40 set -e
41
42 onnode 0 $CTDB_TEST_WRAPPER cluster_is_healthy
43
44 echo "Finding out which node is the recovery master..."
45 try_command_on_node -v 0 "$CTDB recmaster"
46 recmaster=$out
47
48 echo "Getting list of public IPs..."
49 try_command_on_node 0 "$CTDB ip -n all | sed -e '1d'"
50
51 # When selecting test_node we want a node that has public IPs and that
52 # is not the recmaster.  We pick the first one that satisfies both
53 # conditions.  We avoid the recmaster because banning the recmaster
54 # (obviously) causes the recmaster to change... and changing the
55 # recmaster causes all nodes to become unbanned!
56 test_node=""
57
58 ips=""
59 while read ip pnn ; do
60     [ -z "$test_node" -a $recmaster -ne $pnn ] && test_node=$pnn
61     [ "$pnn" = "$test_node" ] && ips="${ips}${ips:+ }${ip}"
62 done <<<"$out" # bashism to avoid problem setting variable in pipeline.
63
64 if [ -z "$test_node" ] ; then
65     echo "BAD: unable to select a suitable node for banning."
66     exit 1
67 fi
68
69 echo "Selected node ${test_node} with IPs: $ips"
70
71 ban_time=15
72
73 echo "Banning node $test_node for $ban_time seconds"
74 try_command_on_node 1 $CTDB ban $ban_time -n $test_node
75
76 # Avoid a potential race condition...
77 onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node banned
78
79 if wait_until_ips_are_on_nodeglob "[!${test_node}]" $ips ; then
80     echo "All IPs moved."
81 else
82     echo "Some IPs didn't move."
83     testfailures=1
84 fi
85
86 echo "Sleeping until ban expires..."
87 sleep_for $ban_time
88
89 onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node unbanned
90
91 # BUG: this is only guaranteed if DeterministicIPs is 1 and
92 #      NoIPFailback is 0.
93 if wait_until_ips_are_on_nodeglob "$test_node" $ips ; then
94     echo "All IPs moved."
95 else
96     echo "Some IPs didn't move."
97     testfailures=1
98 fi
99
100 ctdb_test_exit