1c75203c8SKevin Wolf#!/bin/bash 2c75203c8SKevin Wolf# 3c75203c8SKevin Wolf# Test unsupported blockdev-add cases 4c75203c8SKevin Wolf# 5c75203c8SKevin Wolf# Copyright (C) 2014 Red Hat, Inc. 6c75203c8SKevin Wolf# 7c75203c8SKevin Wolf# This program is free software; you can redistribute it and/or modify 8c75203c8SKevin Wolf# it under the terms of the GNU General Public License as published by 9c75203c8SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10c75203c8SKevin Wolf# (at your option) any later version. 11c75203c8SKevin Wolf# 12c75203c8SKevin Wolf# This program is distributed in the hope that it will be useful, 13c75203c8SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14c75203c8SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15c75203c8SKevin Wolf# GNU General Public License for more details. 16c75203c8SKevin Wolf# 17c75203c8SKevin Wolf# You should have received a copy of the GNU General Public License 18c75203c8SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19c75203c8SKevin Wolf# 20c75203c8SKevin Wolf 21c75203c8SKevin Wolf# creator 22c75203c8SKevin Wolfowner=kwolf@redhat.com 23c75203c8SKevin Wolf 24c75203c8SKevin Wolfseq=`basename $0` 25c75203c8SKevin Wolfecho "QA output created by $seq" 26c75203c8SKevin Wolf 27c75203c8SKevin Wolfhere=`pwd` 28c75203c8SKevin Wolfstatus=1 # failure is the default! 29c75203c8SKevin Wolf 30c75203c8SKevin Wolf# get standard environment, filters and checks 31c75203c8SKevin Wolf. ./common.rc 32c75203c8SKevin Wolf. ./common.filter 33c75203c8SKevin Wolf 34c75203c8SKevin Wolf_supported_fmt qcow2 35c75203c8SKevin Wolf_supported_proto file 36c75203c8SKevin Wolf_supported_os Linux 37c75203c8SKevin Wolf 38c75203c8SKevin Wolffunction do_run_qemu() 39c75203c8SKevin Wolf{ 40c75203c8SKevin Wolf echo Testing: "$@" 41c75203c8SKevin Wolf $QEMU -nographic -qmp stdio -serial none "$@" 42c75203c8SKevin Wolf echo 43c75203c8SKevin Wolf} 44c75203c8SKevin Wolf 45c75203c8SKevin Wolffunction run_qemu() 46c75203c8SKevin Wolf{ 47e6ff69bfSDaniel P. Berrange do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ 48e6ff69bfSDaniel P. Berrange | _filter_qemu | _filter_imgfmt \ 494dd7b8d3SMax Reitz | sed -e 's/\("actual-size":\s*\)[0-9]\+/\1SIZE/g' 50c75203c8SKevin Wolf} 51c75203c8SKevin Wolf 52c75203c8SKevin Wolfsize=128M 53c75203c8SKevin Wolf 54c75203c8SKevin Wolf_make_test_img $size 55c75203c8SKevin Wolf 56c75203c8SKevin Wolfecho 57be4b67bcSMax Reitzecho === Missing ID and node-name === 58c75203c8SKevin Wolfecho 59c75203c8SKevin Wolf 60c75203c8SKevin Wolfrun_qemu <<EOF 61c75203c8SKevin Wolf{ "execute": "qmp_capabilities" } 62c75203c8SKevin Wolf{ "execute": "blockdev-add", 63c75203c8SKevin Wolf "arguments": { 64c75203c8SKevin Wolf "driver": "$IMGFMT", 65c75203c8SKevin Wolf "file": { 66c75203c8SKevin Wolf "driver": "file", 67c75203c8SKevin Wolf "filename": "$TEST_IMG" 68c75203c8SKevin Wolf } 69c75203c8SKevin Wolf } 70c75203c8SKevin Wolf } 71c75203c8SKevin Wolf{ "execute": "quit" } 72c75203c8SKevin WolfEOF 73c75203c8SKevin Wolf 74c75203c8SKevin Wolfecho 75f2d953ecSKevin Wolfecho === Duplicate ID === 76f2d953ecSKevin Wolfecho 77f2d953ecSKevin Wolf 785feb08edSKevin Wolfrun_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EOF 79f2d953ecSKevin Wolf{ "execute": "qmp_capabilities" } 80f2d953ecSKevin Wolf{ "execute": "blockdev-add", 81f2d953ecSKevin Wolf "arguments": { 82f2d953ecSKevin Wolf "driver": "$IMGFMT", 8390d9d301SKevin Wolf "node-name": "disk", 8490d9d301SKevin Wolf "file": { 85d5b8336aSFam Zheng "driver": "null-co" 8690d9d301SKevin Wolf } 8790d9d301SKevin Wolf } 8890d9d301SKevin Wolf } 8990d9d301SKevin Wolf{ "execute": "blockdev-add", 9090d9d301SKevin Wolf "arguments": { 9190d9d301SKevin Wolf "driver": "$IMGFMT", 9290d9d301SKevin Wolf "node-name": "test-node", 9390d9d301SKevin Wolf "file": { 94d5b8336aSFam Zheng "driver": "null-co" 9590d9d301SKevin Wolf } 9690d9d301SKevin Wolf } 9790d9d301SKevin Wolf } 98f2d953ecSKevin Wolf{ "execute": "quit" } 99f2d953ecSKevin WolfEOF 100f2d953ecSKevin Wolf 101f2d953ecSKevin Wolfecho 102c75203c8SKevin Wolfecho === aio=native without O_DIRECT === 103c75203c8SKevin Wolfecho 104c75203c8SKevin Wolf 105c75203c8SKevin Wolfrun_qemu <<EOF 106c75203c8SKevin Wolf{ "execute": "qmp_capabilities" } 107c75203c8SKevin Wolf{ "execute": "blockdev-add", 108c75203c8SKevin Wolf "arguments": { 109c75203c8SKevin Wolf "driver": "$IMGFMT", 1105feb08edSKevin Wolf "node-name": "disk", 111c75203c8SKevin Wolf "file": { 112c75203c8SKevin Wolf "driver": "file", 1130a4279d9SKevin Wolf "filename": "$TEST_IMG", 1140a4279d9SKevin Wolf "aio": "native" 115c75203c8SKevin Wolf } 116c75203c8SKevin Wolf } 117c75203c8SKevin Wolf } 118c75203c8SKevin Wolf{ "execute": "quit" } 119c75203c8SKevin WolfEOF 120c75203c8SKevin Wolf 121c75203c8SKevin Wolfecho 122*426d52d8SDaniel P. Berrangeecho === Encrypted image QCow === 123c75203c8SKevin Wolfecho 124c75203c8SKevin Wolf 125b25b387fSDaniel P. Berrange_make_test_img --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 $size 126c75203c8SKevin Wolfrun_qemu <<EOF 127c75203c8SKevin Wolf{ "execute": "qmp_capabilities" } 128b25b387fSDaniel P. Berrange{ "execute": "object-add", 129b25b387fSDaniel P. Berrange "arguments": { 130b25b387fSDaniel P. Berrange "qom-type": "secret", 131b25b387fSDaniel P. Berrange "id": "sec0", 132b25b387fSDaniel P. Berrange "props": { 133b25b387fSDaniel P. Berrange "data": "123456" 134b25b387fSDaniel P. Berrange } 135b25b387fSDaniel P. Berrange } 136b25b387fSDaniel P. Berrange} 137c75203c8SKevin Wolf{ "execute": "blockdev-add", 138c75203c8SKevin Wolf "arguments": { 139c75203c8SKevin Wolf "driver": "$IMGFMT", 1405feb08edSKevin Wolf "node-name": "disk", 141c75203c8SKevin Wolf "file": { 142c75203c8SKevin Wolf "driver": "file", 143c75203c8SKevin Wolf "filename": "$TEST_IMG" 144b25b387fSDaniel P. Berrange }, 145b25b387fSDaniel P. Berrange "encrypt": { 146b25b387fSDaniel P. Berrange "format": "aes", 147b25b387fSDaniel P. Berrange "key-secret": "sec0" 148c75203c8SKevin Wolf } 149c75203c8SKevin Wolf } 150c75203c8SKevin Wolf } 151c75203c8SKevin Wolf{ "execute": "quit" } 152c75203c8SKevin WolfEOF 153c75203c8SKevin Wolf 154fe509ee2SFam Zhengecho 155*426d52d8SDaniel P. Berrangeecho === Encrypted image LUKS === 156*426d52d8SDaniel P. Berrangeecho 157*426d52d8SDaniel P. Berrange 158*426d52d8SDaniel P. Berrange_make_test_img --object secret,id=sec0,data=123456 -o encrypt.format=luks,encrypt.key-secret=sec0 $size 159*426d52d8SDaniel P. Berrangerun_qemu <<EOF 160*426d52d8SDaniel P. Berrange{ "execute": "qmp_capabilities" } 161*426d52d8SDaniel P. Berrange{ "execute": "object-add", 162*426d52d8SDaniel P. Berrange "arguments": { 163*426d52d8SDaniel P. Berrange "qom-type": "secret", 164*426d52d8SDaniel P. Berrange "id": "sec0", 165*426d52d8SDaniel P. Berrange "props": { 166*426d52d8SDaniel P. Berrange "data": "123456" 167*426d52d8SDaniel P. Berrange } 168*426d52d8SDaniel P. Berrange } 169*426d52d8SDaniel P. Berrange} 170*426d52d8SDaniel P. Berrange{ "execute": "blockdev-add", 171*426d52d8SDaniel P. Berrange "arguments": { 172*426d52d8SDaniel P. Berrange "driver": "$IMGFMT", 173*426d52d8SDaniel P. Berrange "node-name": "disk", 174*426d52d8SDaniel P. Berrange "file": { 175*426d52d8SDaniel P. Berrange "driver": "file", 176*426d52d8SDaniel P. Berrange "filename": "$TEST_IMG" 177*426d52d8SDaniel P. Berrange }, 178*426d52d8SDaniel P. Berrange "encrypt": { 179*426d52d8SDaniel P. Berrange "format": "luks", 180*426d52d8SDaniel P. Berrange "key-secret": "sec0" 181*426d52d8SDaniel P. Berrange } 182*426d52d8SDaniel P. Berrange } 183*426d52d8SDaniel P. Berrange } 184*426d52d8SDaniel P. Berrange{ "execute": "quit" } 185*426d52d8SDaniel P. BerrangeEOF 186*426d52d8SDaniel P. Berrange 187*426d52d8SDaniel P. Berrangeecho 188fe509ee2SFam Zhengecho === Missing driver === 189fe509ee2SFam Zhengecho 190fe509ee2SFam Zheng 191b25b387fSDaniel P. Berrange_make_test_img --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 $size 192fe509ee2SFam Zhengrun_qemu -S <<EOF 193fe509ee2SFam Zheng{ "execute": "qmp_capabilities" } 194fe509ee2SFam Zheng{ "execute": "blockdev-add", 195fe509ee2SFam Zheng "arguments": { 1965feb08edSKevin Wolf "node-name": "disk" 197fe509ee2SFam Zheng } 198fe509ee2SFam Zheng } 199fe509ee2SFam Zheng{ "execute": "quit" } 200fe509ee2SFam ZhengEOF 201fe509ee2SFam Zheng 202c75203c8SKevin Wolf# success, all done 203c75203c8SKevin Wolfecho "*** done" 204c75203c8SKevin Wolfrm -f $seq.full 205c75203c8SKevin Wolfstatus=0 206