]>
Commit | Line | Data |
---|---|---|
dc668ded SH |
1 | #!/bin/bash |
2 | # | |
3 | # Test NBD client unexpected disconnect | |
4 | # | |
5 | # Copyright Red Hat, Inc. 2014 | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | # | |
20 | ||
21 | # creator | |
22 | owner=stefanha@redhat.com | |
23 | ||
24 | seq=`basename $0` | |
25 | echo "QA output created by $seq" | |
26 | ||
27 | here=`pwd` | |
28 | tmp=/tmp/$$ | |
29 | status=1 # failure is the default! | |
30 | ||
31 | # get standard environment, filters and checks | |
32 | . ./common.rc | |
33 | . ./common.filter | |
34 | ||
35 | _supported_fmt generic | |
36 | _supported_proto nbd | |
37 | _supported_os Linux | |
38 | ||
39 | # Pick a TCP port based on our pid. This way multiple instances of this test | |
40 | # can run in parallel without conflicting. | |
41 | choose_tcp_port() { | |
42 | echo $((($$ % 31744) + 1024)) # 1024 <= port < 32768 | |
43 | } | |
44 | ||
45 | wait_for_tcp_port() { | |
46 | while ! (netstat --tcp --listening --numeric | \ | |
f5264553 | 47 | grep "$1.*0\\.0\\.0\\.0:\\*.*LISTEN") 2>&1 >/dev/null; do |
dc668ded SH |
48 | sleep 0.1 |
49 | done | |
50 | } | |
51 | ||
52 | filter_nbd() { | |
53 | # nbd.c error messages contain function names and line numbers that are prone | |
54 | # to change. Message ordering depends on timing between send and receive | |
55 | # callbacks sometimes, making them unreliable. | |
56 | # | |
57 | # Filter out the TCP port number since this changes between runs. | |
f5264553 HR |
58 | sed -e 's#^.*nbd\.c:.*##g' \ |
59 | -e 's#nbd:127\.0\.0\.1:[^:]*:#nbd:127\.0\.0\.1:PORT:#g' | |
dc668ded SH |
60 | } |
61 | ||
62 | check_disconnect() { | |
63 | event=$1 | |
64 | when=$2 | |
65 | negotiation=$3 | |
66 | echo "=== Check disconnect $when $event ===" | |
67 | echo | |
68 | ||
69 | port=$(choose_tcp_port) | |
70 | ||
71 | cat > "$TEST_DIR/nbd-fault-injector.conf" <<EOF | |
72 | [inject-error] | |
73 | event=$event | |
74 | when=$when | |
75 | EOF | |
76 | ||
77 | if [ "$negotiation" = "--classic-negotiation" ]; then | |
78 | extra_args=--classic-negotiation | |
79 | nbd_url="nbd:127.0.0.1:$port" | |
80 | else | |
81 | nbd_url="nbd:127.0.0.1:$port:exportname=foo" | |
82 | fi | |
83 | ||
ea81ca9d | 84 | $PYTHON nbd-fault-injector.py $extra_args "127.0.0.1:$port" "$TEST_DIR/nbd-fault-injector.conf" 2>&1 >/dev/null & |
f5264553 | 85 | wait_for_tcp_port "127\\.0\\.0\\.1:$port" |
dc668ded SH |
86 | $QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | filter_nbd |
87 | ||
88 | echo | |
89 | } | |
90 | ||
91 | for event in neg1 "export" neg2 request reply data; do | |
92 | for when in before after; do | |
93 | check_disconnect "$event" "$when" | |
94 | done | |
95 | ||
96 | # Also inject short replies from the NBD server | |
97 | case "$event" in | |
98 | neg1) | |
99 | for when in 8 16; do | |
100 | check_disconnect "$event" "$when" | |
101 | done | |
102 | ;; | |
103 | "export") | |
104 | for when in 4 12 16; do | |
105 | check_disconnect "$event" "$when" | |
106 | done | |
107 | ;; | |
108 | neg2) | |
109 | for when in 8 10; do | |
110 | check_disconnect "$event" "$when" | |
111 | done | |
112 | ;; | |
113 | reply) | |
114 | for when in 4 8; do | |
115 | check_disconnect "$event" "$when" | |
116 | done | |
117 | ;; | |
118 | esac | |
119 | done | |
120 | ||
121 | # Also check classic negotiation without export information | |
122 | for when in before 8 16 24 28 after; do | |
123 | check_disconnect "neg-classic" "$when" --classic-negotiation | |
124 | done | |
125 | ||
126 | # success, all done | |
127 | echo "*** done" | |
128 | rm -f $seq.full | |
129 | status=0 |