706358510b3385bfda65ad5b677eb8dc4e7db6e7
[samba.git] / ctdb / tests / simple / 15_ctdb_statisticsreset.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that 'ctdb statisticsreset' works as expected.
7
8 This is pretty superficial.  It just checks that a few particular
9 items reduce.
10
11 Prerequisites:
12
13 * An active CTDB cluster with at least 2 active nodes.
14
15 Steps:
16
17 1. Verify that the status on all of the ctdb nodes is 'OK'.
18 2. Run 'ctdb statisticsreset' on all nodes and verify that it executes
19    successfully.
20
21 Expected results:
22
23 * 'ctdb statisticsreset' executes successfully.
24 EOF
25 }
26
27 . "${TEST_SCRIPTS_DIR}/integration.bash"
28
29 ctdb_test_init "$@"
30
31 set -e
32
33 cluster_is_healthy
34
35 try_command_on_node 0 "$CTDB listnodes | wc -l"
36 num_nodes="$out"
37
38 get_stat ()
39 {
40     local label="$1"
41     local out="$2"
42
43     echo "$out" | sed -rn -e "s@^[[:space:]]+${label}[[:space:]]+([[:digit:]])@\1@p" | head -1
44 }
45
46 check_reduced ()
47 {
48     local label="$1"
49     local before="$2"
50     local after="$3"
51
52     if [ $after -lt $before ] ; then
53         echo "GOOD: ${label} reduced from ${before} to ${after}"
54     else
55         die "BAD: ${label} did not reduce from ${before} to ${after}"
56     fi
57 }
58
59 n=0
60 while [ $n -lt $num_nodes ] ; do
61     echo "Getting initial statistics for node ${n}..."
62     
63     try_command_on_node -v $n $CTDB statistics
64
65     before_req_control=$(get_stat "req_control" "$out")
66     before_reply_control=$(get_stat "reply_control" "$out")
67     before_node_packets_recv=$(get_stat "node_packets_recv" "$out")
68
69     try_command_on_node $n $CTDB statisticsreset
70
71     try_command_on_node -v $n $CTDB statistics
72
73     after_req_control=$(get_stat "req_control" "$out")
74     after_reply_control=$(get_stat "reply_control" "$out")
75     after_node_packets_recv=$(get_stat "node_packets_recv" "$out")
76
77     check_reduced "req_control" "$before_req_control" "$after_req_control"
78     check_reduced "reply_control" "$before_reply_control" "$after_reply_control"
79     check_reduced "node_packets_recv" "$before_node_packets_recv" "$after_node_packets_recv"
80
81     n=$(($n + 1))
82 done