0e02b5e8171496aaedf698abaa6bb47d1a00b83e
[obnox/samba/samba-obnox.git] / ctdb / tests / simple / 11_ctdb_ip.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that 'ctdb ip' shows the correct output.
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. Run 'ctdb ip' on one of the nodes and verify the list of IP
16    addresses displayed (cross check the result with the output of
17    'ip addr show' on the node).
18 3. Verify that pipe-separated output is generated with the -X option.
19
20 Expected results:
21
22 * 'ctdb ip' shows the list of public IPs being served by a node.
23 EOF
24 }
25
26 . "${TEST_SCRIPTS_DIR}/integration.bash"
27
28 ctdb_test_init "$@"
29
30 set -e
31
32 cluster_is_healthy
33
34 echo "Getting list of public IPs..."
35 try_command_on_node -v 1 "$CTDB ip -n all | tail -n +2"
36 ips=$(echo "$out" | sed \
37         -e 's@ node\[@ @' \
38         -e 's@\].*$@@')
39 machineout=$(echo "$out" | sed -r \
40         -e 's@^| |$@\|@g' \
41         -e 's@[[:alpha:]]+\[@@g' \
42         -e 's@\]@@g')
43
44 if [ -z "$TEST_LOCAL_DAEMONS" ]; then
45     while read ip pnn ; do
46         try_command_on_node $pnn "ip addr show"
47         if [ "${out/inet* ${ip}\/}" != "$out" ] ; then
48             echo "GOOD: node $pnn appears to have $ip assigned"
49         else
50             echo "BAD:  node $pnn does not appear to have $ip assigned"
51             testfailures=1
52         fi
53     done <<<"$ips" # bashism to avoid problem setting variable in pipeline.
54 fi
55
56 [ "$testfailures" != 1 ] && echo "Looks good!"
57
58 cmd="$CTDB -X ip -n all | tail -n +2"
59 echo "Checking that \"$cmd\" produces expected output..."
60
61 try_command_on_node 1 "$cmd"
62 if [ "$out" = "$machineout" ] ; then
63     echo "Yep, looks good!"
64 else
65     echo "Nope, it looks like this:"
66     echo "$out"
67     echo "Should be like this:"
68     echo "$machineout"
69     testfailures=1
70 fi