Test suite: Fixes for node state parsing plus new stop/continue tests.
[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 cluster_is_healthy
46
47 # Reset configuration
48 ctdb_restart_when_done
49
50 test_node=1
51
52 # We need this for later, so we know how long to sleep.
53 try_command_on_node -v 0 $CTDB getvar MonitorInterval -n $test_node
54 monitor_interval="${out#*= }"
55 echo "Monitor interval on node $test_node is $monitor_interval seconds."
56
57 trigger="/tmp/ctdb-test-unhealthy-trigger.${test_node}"
58 detected="/tmp/ctdb-test-unhealthy-detected.${test_node}"
59
60 recovered_flag="/tmp/ctdb-test-flag.recovered.${test_node}"
61 try_command_on_node $test_node touch "$recovered_flag"
62
63 ctdb_test_exit_hook_add "onnode $test_node rm -vf $trigger"
64
65 echo "Creating trigger file on node $test_node to make it unhealthy..."
66 try_command_on_node $test_node touch "$trigger"
67
68 onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node unhealthy $monitor_interval
69
70 try_command_on_node -v $test_node ls -l "$detected"
71
72 # Wait until recovery is complete before disabling monitoring,
73 # otherwise completion of the recover can turn monitoring back on!
74 echo "Waiting until recovery is complete..."
75 wait_until 30 onnode $test_node ! test -e "$recovered_flag"
76
77 try_command_on_node -v 0 $CTDB disablemonitor -n $test_node
78
79 sanity_check_output \
80     1 \
81     '^Monitoring mode:DISABLED$' \
82     "$out"
83
84 onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node monoff
85
86 try_command_on_node -v $test_node rm -v "$detected"
87
88 sleep_for $monitor_interval
89
90 try_command_on_node $test_node test ! -e "$detected"
91
92 echo "OK: flag file was not recreated so monitoring must be disabled."
93
94 echo "Removing trigger file.  Monitoring is disabled so node will stay unhealthy."
95
96 try_command_on_node -v $test_node rm -v "$trigger"
97
98 sleep_for $monitor_interval
99
100 onnode 0 $CTDB_TEST_WRAPPER node_has_status $test_node unhealthy