4ce74f9ad1f8d434f5a8765f69389b8f9733cbf7
[samba.git] / ctdb / tests / complex / 32_cifs_tickle.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that CIFS connections are monitored and that CIFS tickles are sent.
7
8 We create a connection to the CIFS server on a node and confirm that
9 this connection is registered by CTDB.  Then disable the relevant CIFS
10 server node and ensure that it send an appropriate reset packet.
11
12 Prerequisites:
13
14 * An active CTDB cluster with at least 2 nodes with public addresses.
15
16 * Test must be run on a real or virtual cluster rather than against
17   local daemons.
18
19 * Test must not be run from a cluster node.
20
21 * Clustered Samba must be listening on TCP port 445.
22
23 Steps:
24
25 1. Verify that the cluster is healthy.
26 2. Connect from the current host (test client) to TCP port 445 using
27    the public address of a cluster node.
28 3. Determine the source socket used for the connection.
29 4. Using the "ctdb gettickle" command, ensure that CTDB records the
30    connection details.
31 5. Disable the node that the connection has been made to.
32 6. Verify that a TCP tickle (a reset packet) is sent to the test client.
33
34 Expected results:
35
36 * CTDB should correctly record the connection and should send a reset
37   packet when the node is disabled.
38 EOF
39 }
40
41 . ctdb_test_functions.bash
42
43 set -e
44
45 ctdb_test_init "$@"
46
47 ctdb_test_check_real_cluster
48
49 cluster_is_healthy
50
51 # Reset configuration
52 ctdb_restart_when_done
53
54 # We need this for later, so we know how long to sleep.
55 try_command_on_node 0 $CTDB getvar MonitorInterval
56 monitor_interval="${out#*= }"
57 #echo "Monitor interval on node $test_node is $monitor_interval seconds."
58
59 select_test_node_and_ips
60
61 test_port=445
62
63 echo "Connecting to node ${test_node} on IP ${test_ip}:${test_port} with netcat..."
64
65 nc -d -w $(($monitor_interval * 4)) $test_ip $test_port &
66 nc_pid=$!
67 ctdb_test_exit_hook_add "kill $nc_pid >/dev/null 2>&1"
68
69 wait_until_get_src_socket "tcp" "${test_ip}:${test_port}" $nc_pid "nc"
70 src_socket="$out"
71 echo "Source socket is $src_socket"
72
73 # Right here we assume that Samba is able to register the tickle with
74 # CTDB faster than it takes us to wait for netstat to register the
75 # connection and then use onnode below to ask CTDB about it.
76
77 try_command_on_node -v 0 ctdb gettickles $test_ip -n $test_node
78
79 if [ "${out/SRC: ${src_socket} /}" != "$out" ] ; then
80     echo "GOOD: CIFS connection tracked OK by CTDB."
81 else
82     echo "BAD: Socket not tracked by CTDB."
83     testfailures=1
84 fi
85
86 tcptickle_sniff_start $src_socket "${test_ip}:${test_port}"
87
88 echo "Disabling node $test_node"
89 try_command_on_node 1 $CTDB disable -n $test_node
90 onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node disabled
91
92 tcptickle_sniff_wait_show