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