73c52038e87a48aca51a9b14cd02ba5f6d53069a
[metze/ctdb/wip.git] / tests / complex / 31_nfs_tickle.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that NFS connections are monitored and that NFS tickles are sent.
7
8 We create a connection to the NFS server on a node and confirm that
9 this connection is registered in the nfs-tickles/ subdirectory in
10 shared storage.  Then disable the relevant NFS server node and ensure
11 that it send an appropriate reset packet.
12
13 Prerequisites:
14
15 * An active CTDB cluster with at least 2 nodes with public addresses.
16
17 * Test must be run on a real or virtual cluster rather than against
18   local daemons.
19
20 * Test must not be run from a cluster node.
21
22 * Cluster nodes must be listening on the NFS TCP port (2049).
23
24 Steps:
25
26 1. Verify that the cluster is healthy.
27 2. Connect from the current host (test client) to TCP port 2049 using
28    the public address of a cluster node.
29 3. Determine the source socket used for the connection.
30 4. Ensure that CTDB records the source socket details in the nfs-tickles
31    directory on shared storage.
32 5. Disable the node that the connection has been made to.
33 6. Verify that a TCP tickle (a reset packet) is sent to the test client.
34
35 Expected results:
36
37 * CTDB should correctly record the socket in the nfs-tickles directory
38   and should send a reset packet when the node is disabled.
39 EOF
40 }
41
42 . ctdb_test_functions.bash
43
44 set -e
45
46 ctdb_test_init "$@"
47
48 ctdb_test_check_real_cluster
49
50 cluster_is_healthy
51
52 # Reset configuration
53 ctdb_restart_when_done
54
55 ctdb_test_exit_hook_add ctdb_test_eventscript_uninstall
56
57 ctdb_test_eventscript_install
58
59 # We need this for later, so we know how long to sleep.
60 try_command_on_node 0 $CTDB getvar MonitorInterval
61 monitor_interval="${out#*= }"
62 #echo "Monitor interval on node $test_node is $monitor_interval seconds."
63
64 select_test_node_and_ips
65
66 test_port=2049
67
68 echo "Connecting to node ${test_node} on IP ${test_ip}:${test_port} with netcat..."
69
70 nc -d -w $(($monitor_interval * 4)) $test_ip $test_port &
71 nc_pid=$!
72 ctdb_test_exit_hook_add "kill $nc_pid >/dev/null 2>&1"
73
74 wait_until_get_src_socket "tcp" "${test_ip}:${test_port}" $nc_pid "nc"
75 src_socket="$out"
76 echo "Source socket is $src_socket"
77
78 wait_for_monitor_event $test_node
79
80 if try_command_on_node 0 "test -r /etc/ctdb/events.d/61.nfstickle" ; then
81     echo "Trying to determine NFS_TICKLE_SHARED_DIRECTORY..."
82     f="/etc/sysconfig/nfs"
83     try_command_on_node -v 0 "[ -r $f ] &&  sed -n -e s@^NFS_TICKLE_SHARED_DIRECTORY=@@p $f" || true
84
85     nfs_tickle_shared_directory="${out:-/gpfs/.ctdb/nfs-tickles}"
86
87     try_command_on_node $test_node hostname
88     test_hostname=$out
89
90     try_command_on_node -v 0 cat "${nfs_tickle_shared_directory}/$test_hostname/$test_ip"
91 else
92     echo "That's OK, we'll use \"ctdb gettickles\", which is newer..."
93     try_command_on_node -v 0 "ctdb -Y gettickles $test_ip $test_port"
94 fi
95
96 if [ "${out/${src_socket}/}" != "$out" ] ; then
97     echo "GOOD: NFS connection tracked OK."
98 else
99     echo "BAD: Socket not tracked in NFS tickles."
100     testfailures=1
101 fi
102
103 tcptickle_sniff_start $src_socket "${test_ip}:${test_port}"
104
105 echo "Disabling node $test_node"
106 try_command_on_node 1 $CTDB disable -n $test_node
107 wait_until_node_has_status $test_node disabled
108
109 tcptickle_sniff_wait_show