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