TMP: add a ctdb snapshot of current ctdb master (git://git.samba.org/ctdb.git) to...
[obnox/samba/samba-obnox.git] / ctdb / tests / simple / 13_ctdb_setdebug.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that 'ctdb setdebug' works as expected.
7
8 This is a little superficial.  It checks that CTDB thinks the debug
9 level has been changed but doesn't actually check that logging occurs
10 at the new level.
11
12 A test should also be added to see if setting the debug value via a
13 numerical value works too.
14
15 Prerequisites:
16
17 * An active CTDB cluster with at least 2 active nodes.
18
19 Steps:
20
21 1. Verify that the status on all of the ctdb nodes is 'OK'.
22 2. Get the current debug level on a node, using 'ctdb getdebug'.
23 3. Change the debug level to some other value (e.g. EMERG) using
24    'ctdb setdebug'.
25 4. Verify that the new debug level is correctly set using 'ctdb getdebug'.
26
27 Expected results:
28
29 * 'ctdb setdebug' correctly sets the debug level on a node.
30 EOF
31 }
32
33 . ctdb_test_functions.bash
34
35 ctdb_test_init "$@"
36
37 set -e
38
39 cluster_is_healthy
40
41 get_debug ()
42 {
43     # Sets; check_debug
44     local node="$1"
45
46     local out
47     
48     try_command_on_node -v $node "$CTDB getdebug"
49     check_debug=$(echo "$out" |
50         sed -r -e 's@Node [[:digit:]]+ is at debug level ([[:alpha:]]+) \(-?[[:digit:]]+\)$@\1@')
51 }
52
53 set_and_check_debug ()
54 {
55     local node="$1"
56     local level="$2"
57
58     echo "Setting debug level on node ${node} to ${level}."
59     try_command_on_node $node "$CTDB setdebug ${level}"
60
61     local check_debug
62     get_debug $node
63
64     if [ "$level" = "$check_debug" ] ; then
65         echo "That seemed to work... cool!"
66     else
67         echo "BAD: Debug level should have changed to \"$level\" but it is \"$check_debug\"."
68         testfailures=1
69     fi
70 }
71
72 get_debug 1
73 initial_debug="$check_debug"
74
75 new_debug="EMERG"
76 [ "$initial_debug" = "$new_debug" ] && new_debug="ALERT"
77
78 set_and_check_debug 1 "$new_debug"
79
80 if [ "$testfailures" != 1 ] ; then
81     echo "Returning the debug level to its initial value..."
82     set_and_check_debug 1 "$initial_debug"
83 fi