2019-03-07 17:58:38 +03:00
|
|
|
#!/usr/bin/env bash
|
2021-01-16 16:44:19 +03:00
|
|
|
# group: quick
|
2016-08-15 16:29:27 +03:00
|
|
|
#
|
|
|
|
# Test case for specifying runtime options of the wrong type to some
|
|
|
|
# block drivers
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
# creator
|
2022-03-22 20:42:12 +03:00
|
|
|
owner=hreitz@redhat.com
|
2016-08-15 16:29:27 +03:00
|
|
|
|
|
|
|
seq="$(basename $0)"
|
|
|
|
echo "QA output created by $seq"
|
|
|
|
|
|
|
|
status=1 # failure is the default!
|
|
|
|
|
2017-07-27 16:13:20 +03:00
|
|
|
_cleanup()
|
|
|
|
{
|
|
|
|
rm -f "${TEST_DIR}/qemu-nbd.pid"
|
|
|
|
rm -f 42
|
|
|
|
}
|
|
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
|
|
2016-08-15 16:29:27 +03:00
|
|
|
# get standard environment, filters and checks
|
|
|
|
. ./common.rc
|
|
|
|
. ./common.filter
|
|
|
|
|
|
|
|
_supported_fmt generic
|
2019-08-23 16:35:52 +03:00
|
|
|
_require_drivers ssh
|
2016-10-12 23:49:07 +03:00
|
|
|
|
2016-08-15 16:29:27 +03:00
|
|
|
echo
|
|
|
|
echo '=== NBD ==='
|
|
|
|
# NBD expects all of its arguments to be strings
|
|
|
|
|
|
|
|
# So this should not crash
|
2019-10-02 20:40:52 +03:00
|
|
|
$QEMU_IMG info 'json:{"driver": "nbd", "host": -1}'
|
2016-08-15 16:29:27 +03:00
|
|
|
|
|
|
|
# And this should not treat @port as if it had not been specified
|
2016-09-28 23:46:44 +03:00
|
|
|
# (We need to set up a server here, because the error message for "Connection
|
|
|
|
# refused" does not contain the destination port)
|
|
|
|
|
|
|
|
# Launching qemu-nbd is done in a loop: We try to set up an NBD server on some
|
|
|
|
# random port and continue until success, i.e. until we have found a port that
|
|
|
|
# is not in use yet.
|
|
|
|
while true; do
|
|
|
|
port=$((RANDOM + 32768))
|
|
|
|
if $QEMU_NBD -p $port -f raw --fork null-co:// 2> /dev/null; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
$QEMU_IMG info "json:{'driver': 'nbd', 'host': 'localhost', 'port': $port}" \
|
|
|
|
| grep '^image' | sed -e "s/$port/PORT/"
|
2016-08-15 16:29:27 +03:00
|
|
|
|
|
|
|
# This is a test for NBD's bdrv_refresh_filename() implementation: It expects
|
|
|
|
# either host or path to be set, but it must not assume that they are set to
|
|
|
|
# strings in the options QDict
|
2016-09-28 23:46:43 +03:00
|
|
|
$QEMU_NBD -k "$PWD/42" -f raw --fork null-co://
|
2016-08-15 16:29:27 +03:00
|
|
|
$QEMU_IMG info 'json:{"driver": "nbd", "path": 42}' | grep '^image'
|
|
|
|
rm -f 42
|
|
|
|
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo '=== SSH ==='
|
|
|
|
# SSH expects all of its arguments to be strings, except for @port, which is
|
|
|
|
# expected to be an integer
|
|
|
|
|
|
|
|
# So "0" should be converted to an integer here (instead of crashing)
|
|
|
|
$QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": "0", "path": "/foo"}'
|
|
|
|
# The same, basically (all values for --image-opts are seen as strings in qemu)
|
|
|
|
$QEMU_IMG info --image-opts \
|
|
|
|
driver=ssh,host=localhost,port=0,path=/foo
|
|
|
|
|
|
|
|
# This, however, should fail because of the wrong type
|
|
|
|
$QEMU_IMG info 'json:{"driver": "ssh", "host": "localhost", "port": 0.42, "path": "/foo"}'
|
|
|
|
# Not really the same: Here, "0.42" will be passed instead of 0.42, but still,
|
|
|
|
# qemu should not try to convert "0.42" to an integer
|
|
|
|
$QEMU_IMG info --image-opts \
|
|
|
|
driver=ssh,host=localhost,port=0.42,path=/foo
|
|
|
|
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo '=== blkdebug ==='
|
|
|
|
# blkdebug expects all of its arguments to be strings, but its
|
|
|
|
# bdrv_refresh_filename() implementation should not assume that they have been
|
|
|
|
# passed as strings in the original options QDict.
|
|
|
|
# So this should emit blkdebug:42:null-co:// as the filename:
|
|
|
|
touch 42
|
|
|
|
$QEMU_IMG info 'json:{"driver": "blkdebug", "config": 42,
|
|
|
|
"image.driver": "null-co"}' \
|
|
|
|
| grep '^image'
|
|
|
|
rm -f 42
|
|
|
|
|
|
|
|
|
|
|
|
# success, all done
|
|
|
|
echo
|
|
|
|
echo '*** done'
|
|
|
|
rm -f $seq.full
|
|
|
|
status=0
|