Merge branch 'martins'
[martins/samba.git] / ctdb / tests / simple / 42_ctdb_unban.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify the operation of the 'ctdb unban' command.
7
8 This is a superficial test of the 'ctdb uban' command.  It trusts
9 information from CTDB that indicates that the IP failover and failback
10 has happened correctly.  Another test should check that the failover
11 and failback 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. Before the ban timeout expires, use 'ctdb unban' to unban the
26    node.
27 6. Verify that the status of the node changes back to 'OK' and that
28    the public IP addresses move back to the node.
29
30 Expected results:
31
32 * The 'ctdb unban' command successfully unbans a banned node.
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 # See 41_ctdb_ban.sh for an explanation of why test_node is chosen
52 # like this.
53 test_node=""
54
55 ips=""
56 while read ip pnn ; do
57     [ -z "$test_node" -a $recmaster -ne $pnn ] && test_node=$pnn
58     [ "$pnn" = "$test_node" ] && ips="${ips}${ips:+ }${ip}"
59 done <<<"$out" # bashism to avoid problem setting variable in pipeline.
60
61 if [ -z "$test_node" ] ; then
62     echo "BAD: unable to select a suitable node for banning."
63     exit 1
64 fi
65
66 echo "Selected node ${test_node} with IPs: $ips"
67
68 ban_time=60
69
70 echo "Banning node $test_node for $ban_time seconds"
71 try_command_on_node 1 $CTDB ban $ban_time -n $test_node
72
73 # Avoid a potential race condition...
74 onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node banned
75
76 if wait_until_ips_are_on_nodeglob "[!${test_node}]" $ips ; then
77     echo "All IPs moved."
78 else
79     echo "Some IPs didn't move."
80     testfailures=1
81 fi
82
83 echo "Unbanning node $test_node"
84 try_command_on_node 1 $CTDB unban -n $test_node
85
86 onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node unbanned
87
88 # BUG: this is only guaranteed if DeterministicIPs is 1 and
89 #      NoIPFailback is 0.
90 if wait_until_ips_are_on_nodeglob "$test_node" $ips ; then
91     echo "All IPs moved."
92 else
93     echo "Some IPs didn't move."
94     testfailures=1
95 fi
96
97 ctdb_test_exit