Merge branch 'master' of ctdb into 'master' of samba
[sfrench/samba-autobuild/.git] / ctdb / tests / simple / 12_ctdb_getdebug.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that 'ctdb getdebug' works as expected.
7
8 Prerequisites:
9
10 * An active CTDB cluster with at least 2 active nodes.
11
12 Steps:
13
14 1. Verify that the status on all of the ctdb nodes is 'OK'.
15 2. Get the current debug level on a node, using 'ctdb getdebug -n <node>'.
16 3. Verify that colon-separated output is generated with the -Y option.
17 4. Verify that the '-n all' option shows the debug level on all nodes.
18
19 Expected results:
20
21 * 'ctdb getdebug' shows the debug level on all the nodes.
22 EOF
23 }
24
25 . "${TEST_SCRIPTS_DIR}/integration.bash"
26
27 ctdb_test_init "$@"
28
29 set -e
30
31 cluster_is_healthy
32
33 try_command_on_node 0 "$CTDB listnodes | wc -l"
34 num_nodes="$out"
35
36 try_command_on_node -v 1 "onnode -q all $CTDB getdebug"
37 getdebug_onnode="$out"
38
39 sanity_check_output \
40     $num_nodes \
41     '^Node [[:digit:]]+ is at debug level [[:alpha:]]+ \([[:digit:]]+\)$' \
42     "$out"
43
44 try_command_on_node -v 1 "$CTDB getdebug -n all"
45 getdebug_all="$out"
46
47 cmd=""
48 n=0
49 while [ $n -lt $num_nodes ] ; do
50     cmd="${cmd}${cmd:+; }$CTDB getdebug -n $n"
51     n=$(($n + 1))
52 done
53 try_command_on_node -v 1 "$cmd"
54 getdebug_n="$out"
55
56 if [ "$getdebug_onnode" = "$getdebug_all" -a \
57     "$getdebug_all" = "$getdebug_n" ] ; then
58     echo "They're the same... cool!"
59 else
60     echo "Error: they differ."
61     testfailures=1
62 fi
63
64 colons=""
65 nl="
66 "
67 while read line ; do
68     t=$(echo "$line" | sed -r -e 's@Node [[:digit:]]+ is at debug level ([[:alpha:]]+) \((-?[[:digit:]]+)\)$@:\1:\2:@')
69     colons="${colons}${colons:+${nl}}:Name:Level:${nl}${t}"
70 done <<<"$getdebug_onnode"
71
72 cmd="$CTDB -Y getdebug -n all"
73 echo "Checking that \"$cmd\" produces expected output..."
74
75 try_command_on_node 1 "$cmd"
76 if [ "$out" = "$colons" ] ; then
77     echo "Yep, looks good!"
78 else
79     echo "Nope, it looks like this:"
80     echo "$out"
81     testfailures=1
82 fi