Skip to content

Commit

Permalink
iotests: Do not rely on unavailable domains in 162
Browse files Browse the repository at this point in the history
There are some (mostly ISP-specific) name servers who will redirect
non-existing domains to special hosts. In this case, we will get a
different error message when trying to connect to such a host, which
breaks test 162.

162 needed this specific error message so it can confirm that qemu was
indeed trying to connect to the user-specified port. However, we can
also confirm this by setting up a local NBD server on exactly that port;
so we can fix the issue by doing just that.

Reported-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
XanClic authored and kevmw committed Oct 24, 2016
1 parent 668b440 commit 12ac9d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions tests/qemu-iotests/162
Expand Up @@ -43,10 +43,21 @@ echo '=== NBD ==='
$QEMU_IMG info 'json:{"driver": "nbd", "host": 42}'

# And this should not treat @port as if it had not been specified
# (We cannot use localhost with an invalid port here, but we need to use a
# non-existing domain, because otherwise the error message will not contain
# the port)
$QEMU_IMG info 'json:{"driver": "nbd", "host": "does.not.exist.example.com", "port": 42}'
# (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/"

# 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
Expand Down
2 changes: 1 addition & 1 deletion tests/qemu-iotests/162.out
Expand Up @@ -2,7 +2,7 @@ QA output created by 162

=== NBD ===
qemu-img: Could not open 'json:{"driver": "nbd", "host": 42}': Failed to connect socket: Invalid argument
qemu-img: Could not open 'json:{"driver": "nbd", "host": "does.not.exist.example.com", "port": 42}': address resolution failed for does.not.exist.example.com:42: Name or service not known
image: nbd://localhost:PORT
image: nbd+unix://?socket=42

=== SSH ===
Expand Down

0 comments on commit 12ac9d9

Please sign in to comment.