Added use of $ctdb_test_exit_hook to function ctdb_test_exit. Removed
[vlendec/samba-autobuild/.git] / ctdb / tests / simple / 21_ctdb_disablemonitor.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that 'ctdb disablemonitor' works correctly.
7
8 Prerequisites:
9
10 * An active CTDB cluster with at least 2 active nodes.
11 * 00_ctdb_install_eventscript.sh successfully installed its event
12   script.
13
14 Steps:
15
16 1. Verify that the status on all of the ctdb nodes is 'OK'.
17 2. Create a file called /tmp/ctdb-test-unhealthy-trigger.<node> on a
18    node and verify that the status of the node changes to unhealthy
19    within the interval indicated by the MonitorInterval variable.
20 3. Check that the file /tmp/ctdb-test-unhealthy-detected.<node> is
21    created, indicating that the event script is the reason the node
22    has been marked as unhealthy.
23 4. Now disable monitoring on the node using 'ctdb disablemonitor -n <node>.
24 5. Verify that the message 'Monitoring mode:DISABLED' is printed.
25 6. Remove /tmp/ctdb-test-unhealthy-detected.<node> and ensure that it
26    is not recreated within the interval indicated by the
27    MonitorInterval variable.
28 7. Remove /tmp/ctdb-test-unhealthy-trigger.<node>.
29 8. Verify that the status of the node continues to be 'UNHEALTHY',
30    since monitoring has been disabled.
31
32 Expected results:
33
34 * When monitoring is disabled, event scripts are not executed and the
35   state of nodes is not monitored.
36 EOF
37 }
38
39 . ctdb_test_functions.bash
40
41 ctdb_test_init "$@"
42
43 set -e
44
45 onnode 0 $CTDB_TEST_WRAPPER cluster_is_healthy
46
47 test_node=1
48
49 # We need this for later, so we know how long to sleep.
50 try_command_on_node -v 0 ctdb getvar MonitorInterval -n $test_node
51 monitor_interval="${out#*= }"
52 echo "Monitor interval on node $test_node is $monitor_interval seconds."
53
54 trigger="/tmp/ctdb-test-unhealthy-trigger.${test_node}"
55 detected="/tmp/ctdb-test-unhealthy-detected.${test_node}"
56
57 recovered_flag="/tmp/ctdb-test-flag.recovered.${test_node}"
58 try_command_on_node $test_node touch "$recovered_flag"
59
60 ctdb_test_exit_hook="onnode $test_node rm -vf $trigger"
61
62 echo "Creating trigger file on node $test_node to make it unhealthy..."
63 try_command_on_node $test_node touch "$trigger"
64
65 onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node unhealthy $monitor_interval
66
67 try_command_on_node -v $test_node ls -l "$detected"
68
69 # Wait until recovery is complete before disabling monitoring,
70 # otherwise completion of the recover can turn monitoring back on!
71 echo "Waiting until recovery is complete..."
72 wait_until 30 onnode $test_node ! test -e "$recovered_flag"
73
74 try_command_on_node -v 0 ctdb disablemonitor -n $test_node
75
76 sanity_check_output \
77     1 \
78     '^Monitoring mode:DISABLED$' \
79     "$out"
80
81 onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node monoff
82
83 try_command_on_node -v $test_node rm -v "$detected"
84
85 sleep_for $monitor_interval
86
87 try_command_on_node $test_node test ! -e "$detected"
88
89 echo "OK: flag file was not recreated so monitoring must be disabled."
90
91 echo "Removing trigger file.  Monitoring is disabled so node will stay unhealthy."
92
93 try_command_on_node -v $test_node rm -v "$trigger"
94
95 sleep_for $monitor_interval
96
97 onnode 0 $CTDB_TEST_WRAPPER node_has_status $test_node unhealthy
98
99 echo "OK, that all worked.  Expect a restart..."
100
101 ctdb_test_exit