Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw quick |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 3 | # |
| 4 | # Test unsupported blockdev-add cases |
| 5 | # |
| 6 | # Copyright (C) 2014 Red Hat, Inc. |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | # |
| 21 | |
| 22 | # creator |
| 23 | owner=kwolf@redhat.com |
| 24 | |
| 25 | seq=`basename $0` |
| 26 | echo "QA output created by $seq" |
| 27 | |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 28 | status=1 # failure is the default! |
| 29 | |
Max Reitz | 801ddbd | 2020-02-24 18:16:31 +0100 | [diff] [blame] | 30 | _cleanup() |
| 31 | { |
| 32 | _cleanup_test_img |
| 33 | } |
| 34 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 35 | |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 36 | # get standard environment, filters and checks |
| 37 | . ./common.rc |
| 38 | . ./common.filter |
| 39 | |
| 40 | _supported_fmt qcow2 |
| 41 | _supported_proto file |
| 42 | _supported_os Linux |
Max Reitz | d2a839e | 2020-06-25 14:55:35 +0200 | [diff] [blame] | 43 | _require_working_luks |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 44 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 45 | do_run_qemu() |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 46 | { |
| 47 | echo Testing: "$@" |
| 48 | $QEMU -nographic -qmp stdio -serial none "$@" |
| 49 | echo |
| 50 | } |
| 51 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 52 | run_qemu() |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 53 | { |
Daniel P. Berrange | e6ff69b | 2016-03-21 14:11:48 +0000 | [diff] [blame] | 54 | do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ |
| 55 | | _filter_qemu | _filter_imgfmt \ |
Max Reitz | 44673a0 | 2017-10-09 18:34:55 +0200 | [diff] [blame] | 56 | | _filter_actual_image_size |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | size=128M |
| 60 | |
| 61 | _make_test_img $size |
| 62 | |
| 63 | echo |
Max Reitz | be4b67b | 2015-10-19 17:53:09 +0200 | [diff] [blame] | 64 | echo === Missing ID and node-name === |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 65 | echo |
| 66 | |
| 67 | run_qemu <<EOF |
| 68 | { "execute": "qmp_capabilities" } |
| 69 | { "execute": "blockdev-add", |
| 70 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 71 | "driver": "$IMGFMT", |
| 72 | "file": { |
| 73 | "driver": "file", |
| 74 | "filename": "$TEST_IMG" |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | } |
| 78 | { "execute": "quit" } |
| 79 | EOF |
| 80 | |
| 81 | echo |
Kevin Wolf | f2d953e | 2014-04-17 13:27:05 +0200 | [diff] [blame] | 82 | echo === Duplicate ID === |
| 83 | echo |
| 84 | |
Kevin Wolf | 5feb08e | 2016-09-21 14:56:04 +0200 | [diff] [blame] | 85 | run_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EOF |
Kevin Wolf | f2d953e | 2014-04-17 13:27:05 +0200 | [diff] [blame] | 86 | { "execute": "qmp_capabilities" } |
| 87 | { "execute": "blockdev-add", |
| 88 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 89 | "driver": "$IMGFMT", |
| 90 | "node-name": "disk", |
| 91 | "file": { |
Fam Zheng | d5b8336 | 2017-05-03 00:35:46 +0800 | [diff] [blame] | 92 | "driver": "null-co" |
Kevin Wolf | 90d9d30 | 2014-04-17 13:40:30 +0200 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | } |
| 96 | { "execute": "blockdev-add", |
| 97 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 98 | "driver": "$IMGFMT", |
| 99 | "node-name": "test-node", |
| 100 | "file": { |
Fam Zheng | d5b8336 | 2017-05-03 00:35:46 +0800 | [diff] [blame] | 101 | "driver": "null-co" |
Kevin Wolf | 90d9d30 | 2014-04-17 13:40:30 +0200 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | } |
Kevin Wolf | f2d953e | 2014-04-17 13:27:05 +0200 | [diff] [blame] | 105 | { "execute": "quit" } |
| 106 | EOF |
| 107 | |
| 108 | echo |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 109 | echo === aio=native without O_DIRECT === |
| 110 | echo |
| 111 | |
Max Reitz | c0012e9 | 2017-11-15 19:07:32 +0100 | [diff] [blame] | 112 | # Skip this test if AIO is not enabled in this build |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 113 | run_qemu_filter_aio() |
Max Reitz | c0012e9 | 2017-11-15 19:07:32 +0100 | [diff] [blame] | 114 | { |
| 115 | run_qemu "$@" | \ |
| 116 | sed -e 's/is not supported in this build/it requires cache.direct=on, which was not specified/' |
| 117 | } |
| 118 | |
| 119 | run_qemu_filter_aio <<EOF |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 120 | { "execute": "qmp_capabilities" } |
| 121 | { "execute": "blockdev-add", |
| 122 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 123 | "driver": "$IMGFMT", |
| 124 | "node-name": "disk", |
| 125 | "file": { |
| 126 | "driver": "file", |
| 127 | "filename": "$TEST_IMG", |
| 128 | "aio": "native" |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | } |
| 132 | { "execute": "quit" } |
| 133 | EOF |
| 134 | |
| 135 | echo |
Daniel P. Berrange | 426d52d | 2017-06-23 17:24:13 +0100 | [diff] [blame] | 136 | echo === Encrypted image QCow === |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 137 | echo |
| 138 | |
Daniel P. Berrange | b25b387 | 2017-06-23 17:24:10 +0100 | [diff] [blame] | 139 | _make_test_img --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 $size |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 140 | run_qemu <<EOF |
| 141 | { "execute": "qmp_capabilities" } |
Daniel P. Berrange | b25b387 | 2017-06-23 17:24:10 +0100 | [diff] [blame] | 142 | { "execute": "object-add", |
| 143 | "arguments": { |
| 144 | "qom-type": "secret", |
| 145 | "id": "sec0", |
Alberto Garcia | fa818b2 | 2021-02-22 12:57:37 +0100 | [diff] [blame] | 146 | "data": "123456" |
Daniel P. Berrange | b25b387 | 2017-06-23 17:24:10 +0100 | [diff] [blame] | 147 | } |
| 148 | } |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 149 | { "execute": "blockdev-add", |
| 150 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 151 | "driver": "$IMGFMT", |
| 152 | "node-name": "disk", |
| 153 | "file": { |
| 154 | "driver": "file", |
| 155 | "filename": "$TEST_IMG" |
Daniel P. Berrange | b25b387 | 2017-06-23 17:24:10 +0100 | [diff] [blame] | 156 | }, |
| 157 | "encrypt": { |
| 158 | "format": "aes", |
| 159 | "key-secret": "sec0" |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | } |
| 163 | { "execute": "quit" } |
| 164 | EOF |
| 165 | |
Fam Zheng | fe509ee | 2014-09-18 15:36:43 -0500 | [diff] [blame] | 166 | echo |
Daniel P. Berrange | 426d52d | 2017-06-23 17:24:13 +0100 | [diff] [blame] | 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", |
Alberto Garcia | fa818b2 | 2021-02-22 12:57:37 +0100 | [diff] [blame] | 177 | "data": "123456" |
Daniel P. Berrange | 426d52d | 2017-06-23 17:24:13 +0100 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | { "execute": "blockdev-add", |
| 181 | "arguments": { |
| 182 | "driver": "$IMGFMT", |
| 183 | "node-name": "disk", |
| 184 | "file": { |
| 185 | "driver": "file", |
| 186 | "filename": "$TEST_IMG" |
| 187 | }, |
| 188 | "encrypt": { |
| 189 | "format": "luks", |
| 190 | "key-secret": "sec0" |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | { "execute": "quit" } |
| 195 | EOF |
| 196 | |
| 197 | echo |
Fam Zheng | fe509ee | 2014-09-18 15:36:43 -0500 | [diff] [blame] | 198 | echo === Missing driver === |
| 199 | echo |
| 200 | |
Daniel P. Berrange | b25b387 | 2017-06-23 17:24:10 +0100 | [diff] [blame] | 201 | _make_test_img --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 $size |
Fam Zheng | fe509ee | 2014-09-18 15:36:43 -0500 | [diff] [blame] | 202 | run_qemu -S <<EOF |
| 203 | { "execute": "qmp_capabilities" } |
| 204 | { "execute": "blockdev-add", |
| 205 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 206 | "node-name": "disk" |
Fam Zheng | fe509ee | 2014-09-18 15:36:43 -0500 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | { "execute": "quit" } |
| 210 | EOF |
| 211 | |
Kevin Wolf | c75203c | 2014-03-06 15:52:14 +0100 | [diff] [blame] | 212 | # success, all done |
| 213 | echo "*** done" |
| 214 | rm -f $seq.full |
| 215 | status=0 |