Merge branch 'master' of ctdb into 'master' of samba
[samba.git] / ctdb / 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 . "${TEST_SCRIPTS_DIR}/integration.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 any $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 echo "Sleeping until tickles are synchronised across nodes..."
81 try_command_on_node $test_node $CTDB getvar TickleUpdateInterval
82 sleep_for "${out#*= }"
83
84 if try_command_on_node any "test -r /etc/ctdb/events.d/61.nfstickle" ; then
85     echo "Trying to determine NFS_TICKLE_SHARED_DIRECTORY..."
86     if [ -f /etc/sysconfig/nfs ]; then
87         f="/etc/sysconfig/nfs"
88     elif [ -f /etc/default/nfs ]; then
89         f="/etc/default/nfs"
90     elif [ -f /etc/ctdb/sysconfig/nfs ]; then
91         f="/etc/ctdb/sysconfig/nfs"
92     fi
93     try_command_on_node -v any "[ -r $f ] &&  sed -n -e s@^NFS_TICKLE_SHARED_DIRECTORY=@@p $f" || true
94
95     nfs_tickle_shared_directory="${out:-/gpfs/.ctdb/nfs-tickles}"
96
97     try_command_on_node $test_node hostname
98     test_hostname=$out
99
100     try_command_on_node -v any cat "${nfs_tickle_shared_directory}/$test_hostname/$test_ip"
101 else
102     echo "That's OK, we'll use \"ctdb gettickles\", which is newer..."
103     try_command_on_node -v any "ctdb -Y gettickles $test_ip $test_port"
104 fi
105
106 if [ "${out/${src_socket}/}" != "$out" ] ; then
107     echo "GOOD: NFS connection tracked OK."
108 else
109     echo "BAD: Socket not tracked in NFS tickles."
110     testfailures=1
111 fi
112
113 tcptickle_sniff_start $src_socket "${test_ip}:${test_port}"
114
115 # We need to be nasty to make that the node being failed out doesn't
116 # get a chance to send any tickles and confuse our sniff.
117 echo "Killing ctdbd on ${test_node}..."
118 try_command_on_node $test_node killall -9 ctdbd
119
120 wait_until_node_has_status $test_node disconnected
121
122 tcptickle_sniff_wait_show