ctdb-tests: Don't use nc -d or -w options
[vlendec/samba-autobuild/.git] / ctdb / tests / complex / 36_smb_reset_server.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that the server end of an SMB connection is correctly reset
7
8 Prerequisites:
9
10 * An active CTDB cluster with at least 2 nodes with public addresses.
11
12 * Test must be run on a real or virtual cluster rather than against
13   local daemons.
14
15 * Test must not be run from a cluster node.
16
17 * Clustered Samba must be listening on TCP port 445.
18
19 Expected results:
20
21 * CTDB should correctly record the connection and the releasing node
22   should reset the server end of the connection.
23 EOF
24 }
25
26 . "${TEST_SCRIPTS_DIR}/integration.bash"
27
28 set -e
29
30 ctdb_test_init "$@"
31
32 ctdb_test_check_real_cluster
33
34 cluster_is_healthy
35
36 # Reset configuration
37 ctdb_restart_when_done
38
39 # We need this for later, so we know how long to sleep.
40 try_command_on_node 0 $CTDB getvar MonitorInterval
41 monitor_interval="${out#*= }"
42
43 select_test_node_and_ips
44
45 test_port=445
46
47 echo "Set NoIPTakeover=1 on all nodes"
48 try_command_on_node all $CTDB setvar NoIPTakeover 1
49
50 echo "Give the recovery daemon some time to reload tunables"
51 sleep_for 5
52
53 echo "Connecting to node ${test_node} on IP ${test_ip}:${test_port} with nc..."
54
55 sleep $((monitor_interval * 4)) | nc $test_ip $test_port &
56 nc_pid=$!
57 ctdb_test_exit_hook_add "kill $nc_pid >/dev/null 2>&1"
58
59 wait_until_get_src_socket "tcp" "${test_ip}:${test_port}" $nc_pid "nc"
60 src_socket="$out"
61 echo "Source socket is $src_socket"
62
63 # This should happen as soon as connection is up... but unless we wait
64 # we sometimes beat the registration.
65 echo "Checking if CIFS connection is tracked by CTDB on test node..."
66 wait_until 10 check_tickles $test_node $test_ip $test_port $src_socket
67 echo "$out"
68
69 if [ "${out/SRC: ${src_socket} /}" != "$out" ] ; then
70     echo "GOOD: CIFS connection tracked OK by CTDB."
71 else
72     echo "BAD: Socket not tracked by CTDB."
73     exit 1
74 fi
75
76 # It would be nice if ss consistently used local/peer instead of src/dst
77 ss_filter="src ${test_ip}:${test_port} dst ${src_socket}"
78
79 try_command_on_node $test_node \
80                     "ss -tn state established '${ss_filter}' | tail -n +2"
81 if [ -z "$out" ] ; then
82         echo "BAD: ss did not list the socket"
83         exit 1
84 fi
85 echo "GOOD: ss lists the socket:"
86 echo "$out"
87
88 echo "Disabling node $test_node"
89 try_command_on_node 1 $CTDB disable -n $test_node
90 wait_until_node_has_status $test_node disabled
91
92 try_command_on_node $test_node \
93                     "ss -tn state established '${ss_filter}' | tail -n +2"
94 if [ -n "$out" ] ; then
95         echo "BAD: ss listed the socket after failover"
96         exit 1
97 fi
98 echo "GOOD: ss no longer lists the socket"