ctdb-tests: Fix "setreclock" test
[abartlet/samba.git/.git] / ctdb / tests / simple / 35_set_reclock.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that "ctdb setreclock" sets the recovery lock correctly.
7
8 This test only does something when there is a recovery lock
9 configured.
10 EOF
11 }
12
13 . "${TEST_SCRIPTS_DIR}/integration.bash"
14
15 ctdb_test_init "$@"
16
17 set -e
18
19 cluster_is_healthy
20
21 # Reset configuration
22 ctdb_restart_when_done
23
24 get_generation ()
25 {
26     local out
27     try_command_on_node any $CTDB status
28     generation=$(sed -n -e 's@^Generation:@@p' <<<"$out")
29 }
30
31 generation_has_changed ()
32 {
33     local old_generation="$generation"
34     get_generation
35     [ "$old_generation" != "$generation" ]
36 }
37
38 wait_until_generation_has_changed ()
39 {
40     echo
41     echo "Wait until generation has changed..."
42     wait_until 60 generation_has_changed
43 }
44
45 wait_until_recovered ()
46 {
47     wait_until_generation_has_changed
48     wait_until_node_has_status all recovered
49 }
50
51 echo "Check that recovery lock is set the same on all nodes..."
52 try_command_on_node -v -q all $CTDB getreclock
53 n=$(echo "$out" | sort -u | wc -l)
54 if [ "$n" = 1 ] ; then
55     echo "GOOD: All nodes have the same recovery lock setting"
56 else
57     echo "BAD: Recovery lock setting differs across nodes"
58     exit 1
59 fi
60
61 echo
62 echo "Check that recovery lock is actually enabled..."
63 t=$(echo "$out" | sed -e 's@^Reclock file:@@' | sort -u)
64 if [ "$t" != "No reclock file used." ] ; then
65     echo "OK: Recovery lock is set"
66 else
67     echo "OOPS: Recovery lock is unset. Skipping remainder of test"
68     exit 0
69 fi
70
71 echo
72 orig_reclock=$(sed -n -e '1s@^Reclock file:@@p' <<<"$out")
73 echo "Remember original recovery lock file: \"${orig_reclock}\""
74
75 echo
76 echo "Unset and test the recovery lock on all nodes..."
77 try_command_on_node -pq all $CTDB setreclock
78 wait_until_recovered
79 try_command_on_node -v -q all $CTDB getreclock
80 t=$(sort -u <<<"$out")
81 if [ "$t" = "No reclock file used." ] ; then
82     echo "GOOD: Recovery lock unset on all nodes"
83 else
84     echo "BAD: Recovery lock not unset on all nodes"
85     exit 1
86 fi
87
88 echo
89 get_generation
90 echo "Current generation is ${generation}"
91
92 alt="${orig_reclock}.test"
93 echo
94 echo "Set alternative recovery lock (${alt}) and test on all nodes..."
95 try_command_on_node -pq all $CTDB setreclock "$alt"
96 wait_until_recovered
97 try_command_on_node -v -q all $CTDB getreclock
98 t=$(echo "$out" | sed -e 's@^Reclock file:@@' | sort -u)
99 if [ "$t" = "$alt" ] ; then
100     echo "GOOD: Recovery lock set on all nodes"
101 else
102     echo "BAD: Recovery lock not set on all nodes"
103     try_command_on_node -vf all rm -v "$alt" || true
104     exit 1
105 fi
106
107 # Setting or updating the recovery lock file must cause a recovery
108 echo "Current generation is ${generation}"
109
110 echo
111 echo "Restore and test the recovery lock on all nodes..."
112 try_command_on_node -pq all $CTDB setreclock "$orig_reclock"
113 wait_until_recovered
114 try_command_on_node -v all rm -vf "$alt"
115 try_command_on_node -v -q all $CTDB getreclock
116 t=$(echo "$out" | sed -e 's@^Reclock file:@@' | sort -u)
117 if [ "$t" = "$orig_reclock" ] ; then
118     echo "GOOD: Recovery lock restored on all nodes"
119 else
120     echo "BAD: Recovery lock not restored on all nodes"
121     exit 1
122 fi
123
124 echo "Current generation is ${generation}"