iotests: Fix cleanup path in some tests
[qemu.git] / tests / qemu-iotests / 087
1 #!/usr/bin/env bash
2 #
3 # Test unsupported blockdev-add cases
4 #
5 # Copyright (C) 2014 Red Hat, Inc.
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=kwolf@redhat.com
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 status=1        # failure is the default!
28
29 _cleanup()
30 {
31     _cleanup_test_img
32 }
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38
39 _supported_fmt qcow2
40 _supported_proto file
41 _supported_os Linux
42
43 do_run_qemu()
44 {
45     echo Testing: "$@"
46     $QEMU -nographic -qmp stdio -serial none "$@"
47     echo
48 }
49
50 run_qemu()
51 {
52     do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
53                           | _filter_qemu | _filter_imgfmt \
54                           | _filter_actual_image_size
55 }
56
57 size=128M
58
59 _make_test_img $size
60
61 echo
62 echo === Missing ID and node-name ===
63 echo
64
65 run_qemu <<EOF
66 { "execute": "qmp_capabilities" }
67 { "execute": "blockdev-add",
68   "arguments": {
69       "driver": "$IMGFMT",
70       "file": {
71           "driver": "file",
72           "filename": "$TEST_IMG"
73       }
74     }
75   }
76 { "execute": "quit" }
77 EOF
78
79 echo
80 echo === Duplicate ID ===
81 echo
82
83 run_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EOF
84 { "execute": "qmp_capabilities" }
85 { "execute": "blockdev-add",
86   "arguments": {
87       "driver": "$IMGFMT",
88       "node-name": "disk",
89       "file": {
90           "driver": "null-co"
91       }
92     }
93   }
94 { "execute": "blockdev-add",
95   "arguments": {
96       "driver": "$IMGFMT",
97       "node-name": "test-node",
98       "file": {
99           "driver": "null-co"
100       }
101     }
102   }
103 { "execute": "quit" }
104 EOF
105
106 echo
107 echo === aio=native without O_DIRECT ===
108 echo
109
110 # Skip this test if AIO is not enabled in this build
111 run_qemu_filter_aio()
112 {
113     run_qemu "$@" | \
114         sed -e 's/is not supported in this build/it requires cache.direct=on, which was not specified/'
115 }
116
117 run_qemu_filter_aio <<EOF
118 { "execute": "qmp_capabilities" }
119 { "execute": "blockdev-add",
120   "arguments": {
121       "driver": "$IMGFMT",
122       "node-name": "disk",
123       "file": {
124           "driver": "file",
125           "filename": "$TEST_IMG",
126           "aio": "native"
127       }
128     }
129   }
130 { "execute": "quit" }
131 EOF
132
133 echo
134 echo === Encrypted image QCow ===
135 echo
136
137 _make_test_img --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 $size
138 run_qemu <<EOF
139 { "execute": "qmp_capabilities" }
140 { "execute": "object-add",
141   "arguments": {
142       "qom-type": "secret",
143       "id": "sec0",
144       "props": {
145           "data": "123456"
146       }
147   }
148 }
149 { "execute": "blockdev-add",
150   "arguments": {
151       "driver": "$IMGFMT",
152       "node-name": "disk",
153       "file": {
154           "driver": "file",
155           "filename": "$TEST_IMG"
156       },
157       "encrypt": {
158           "format": "aes",
159           "key-secret": "sec0"
160       }
161     }
162   }
163 { "execute": "quit" }
164 EOF
165
166 echo
167 echo === Encrypted image LUKS ===
168 echo
169
170 _make_test_img --object secret,id=sec0,data=123456 -o encrypt.format=luks,encrypt.key-secret=sec0 $size
171 run_qemu <<EOF
172 { "execute": "qmp_capabilities" }
173 { "execute": "object-add",
174   "arguments": {
175       "qom-type": "secret",
176       "id": "sec0",
177       "props": {
178           "data": "123456"
179       }
180   }
181 }
182 { "execute": "blockdev-add",
183   "arguments": {
184       "driver": "$IMGFMT",
185       "node-name": "disk",
186       "file": {
187           "driver": "file",
188           "filename": "$TEST_IMG"
189       },
190       "encrypt": {
191         "format": "luks",
192         "key-secret": "sec0"
193       }
194     }
195   }
196 { "execute": "quit" }
197 EOF
198
199 echo
200 echo === Missing driver ===
201 echo
202
203 _make_test_img --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 $size
204 run_qemu -S <<EOF
205 { "execute": "qmp_capabilities" }
206 { "execute": "blockdev-add",
207   "arguments": {
208       "node-name": "disk"
209     }
210   }
211 { "execute": "quit" }
212 EOF
213
214 # success, all done
215 echo "*** done"
216 rm -f $seq.full
217 status=0