From 6eba9f01bbfbd92ddd5520be83520df06805dabb Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 12 Mar 2018 16:11:56 -0500 Subject: iotests: Fix stuck NBD process on 33 Commit afe35cde6 added additional actions to test 33, but forgot to reset the image between tests. As a result, './check -nbd 33' fails because the qemu-nbd process from the first half is still occupying the port, preventing the second half from starting a new qemu-nbd process. Worse, the failure leaves a rogue qemu-nbd process behind even after the test fails, which causes knock-on failures to later tests that also want to start qemu-nbd. Reported-by: Max Reitz Signed-off-by: Eric Blake Message-Id: <20180312211156.452139-1-eblake@redhat.com> Reviewed-by: Max Reitz --- tests/qemu-iotests/033 | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/qemu-iotests/033 b/tests/qemu-iotests/033 index a1d8357..ee8a133 100755 --- a/tests/qemu-iotests/033 +++ b/tests/qemu-iotests/033 @@ -105,6 +105,7 @@ for align in 512 4k; do done done +_cleanup_test_img # Trigger truncate that would shrink qcow2 L1 table, which is done by # clearing one entry (8 bytes) with bdrv_co_pwrite_zeroes() -- cgit v1.1 From 44a8174e0a2919693dc28f19c3ce8eef6d4ac2c3 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Mon, 12 Mar 2018 16:04:39 -0500 Subject: iotests: add 208 nbd-server + blockdev-snapshot-sync test case This test case adds an NBD server export and then invokes blockdev-snapshot-sync, which changes the BlockDriverState node that the NBD server's BlockBackend points to. This is an interesting scenario to test and exercises the code path fixed by the previous commit. Signed-off-by: Stefan Hajnoczi Message-Id: <20180306204819.11266-3-stefanha@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Eric Blake --- tests/qemu-iotests/208 | 55 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/208.out | 9 ++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 65 insertions(+) create mode 100755 tests/qemu-iotests/208 create mode 100644 tests/qemu-iotests/208.out (limited to 'tests') diff --git a/tests/qemu-iotests/208 b/tests/qemu-iotests/208 new file mode 100755 index 0000000..4e82b96 --- /dev/null +++ b/tests/qemu-iotests/208 @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# +# Copyright (C) 2018 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 . +# +# Creator/Owner: Stefan Hajnoczi +# +# Check that the runtime NBD server does not crash when stopped after +# blockdev-snapshot-sync. + +import iotests + +with iotests.FilePath('disk.img') as disk_img_path, \ + iotests.FilePath('disk-snapshot.img') as disk_snapshot_img_path, \ + iotests.FilePath('nbd.sock') as nbd_sock_path, \ + iotests.VM() as vm: + + img_size = '10M' + iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk_img_path, img_size) + + iotests.log('Launching VM...') + (vm.add_drive(disk_img_path, 'node-name=drive0-node', interface='none') + .launch()) + + iotests.log('Starting NBD server...') + iotests.log(vm.qmp('nbd-server-start', addr={ + "type": "unix", + "data": { + "path": nbd_sock_path, + } + })) + + iotests.log('Adding NBD export...') + iotests.log(vm.qmp('nbd-server-add', device='drive0-node', writable=True)) + + iotests.log('Creating external snapshot...') + iotests.log(vm.qmp('blockdev-snapshot-sync', + node_name='drive0-node', + snapshot_node_name='drive0-snapshot-node', + snapshot_file=disk_snapshot_img_path)) + + iotests.log('Stopping NBD server...') + iotests.log(vm.qmp('nbd-server-stop')) diff --git a/tests/qemu-iotests/208.out b/tests/qemu-iotests/208.out new file mode 100644 index 0000000..3687e9d --- /dev/null +++ b/tests/qemu-iotests/208.out @@ -0,0 +1,9 @@ +Launching VM... +Starting NBD server... +{u'return': {}} +Adding NBD export... +{u'return': {}} +Creating external snapshot... +{u'return': {}} +Stopping NBD server... +{u'return': {}} diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index c401791..890fe91 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -204,3 +204,4 @@ 205 rw auto quick 206 rw auto 207 rw auto +208 rw auto quick -- cgit v1.1 From 02f3a9119955891abb2ead5e0bb9cc2f0af42150 Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Mon, 12 Mar 2018 18:21:24 +0300 Subject: iotests.py: tiny refactor: move system imports up Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20180312152126.286890-7-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/iotests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 1bcc9ca..c1302a2 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -23,13 +23,14 @@ import subprocess import string import unittest import sys -sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts')) -import qtest import struct import json import signal import logging +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts')) +import qtest + # This will not work if arguments contain spaces but is necessary if we # want to support the override options that ./check supports. -- cgit v1.1 From ef6e92280ef90f808adf0032f073331c36f58baf Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Mon, 12 Mar 2018 18:21:25 +0300 Subject: iotests: add file_path helper Simple way to have auto generated filenames with auto cleanup. Like FilePath but without using 'with' statement and without additional indentation of the whole test. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180312152126.286890-8-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: grammar tweak] Signed-off-by: Eric Blake --- tests/qemu-iotests/iotests.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index c1302a2..90cd751 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -27,6 +27,7 @@ import struct import json import signal import logging +import atexit sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts')) import qtest @@ -250,6 +251,37 @@ class FilePath(object): return False +def file_path_remover(): + for path in reversed(file_path_remover.paths): + try: + os.remove(path) + except OSError: + pass + + +def file_path(*names): + ''' Another way to get auto-generated filename that cleans itself up. + + Use is as simple as: + + img_a, img_b = file_path('a.img', 'b.img') + sock = file_path('socket') + ''' + + if not hasattr(file_path_remover, 'paths'): + file_path_remover.paths = [] + atexit.register(file_path_remover) + + paths = [] + for name in names: + filename = '{0}-{1}'.format(os.getpid(), name) + path = os.path.join(test_dir, filename) + file_path_remover.paths.append(path) + paths.append(path) + + return paths[0] if len(paths) == 1 else paths + + class VM(qtest.QEMUQtestMachine): '''A QEMU VM''' -- cgit v1.1 From 65374c1aa6263a4e2b566d15a9fd9b2105954a1b Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Mon, 12 Mar 2018 18:21:26 +0300 Subject: iotests: new test 209 for NBD BLOCK_STATUS Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180312152126.286890-9-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/209 | 34 ++++++++++++++++++++++++++++++++++ tests/qemu-iotests/209.out | 2 ++ tests/qemu-iotests/group | 1 + 3 files changed, 37 insertions(+) create mode 100755 tests/qemu-iotests/209 create mode 100644 tests/qemu-iotests/209.out (limited to 'tests') diff --git a/tests/qemu-iotests/209 b/tests/qemu-iotests/209 new file mode 100755 index 0000000..259e991 --- /dev/null +++ b/tests/qemu-iotests/209 @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# +# Tests for NBD BLOCK_STATUS extension +# +# Copyright (c) 2018 Virtuozzo International GmbH +# +# 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 . +# + +import iotests +from iotests import qemu_img_create, qemu_io, qemu_img_verbose, qemu_nbd, \ + file_path + +iotests.verify_image_format(supported_fmts=['qcow2']) + +disk, nbd_sock = file_path('disk', 'nbd-sock') +nbd_uri = 'nbd+unix:///exp?socket=' + nbd_sock + +qemu_img_create('-f', iotests.imgfmt, disk, '1M') +qemu_io('-f', iotests.imgfmt, '-c', 'write 0 512K', disk) + +qemu_nbd('-k', nbd_sock, '-x', 'exp', '-f', iotests.imgfmt, disk) +qemu_img_verbose('map', '-f', 'raw', '--output=json', nbd_uri) diff --git a/tests/qemu-iotests/209.out b/tests/qemu-iotests/209.out new file mode 100644 index 0000000..0d29724 --- /dev/null +++ b/tests/qemu-iotests/209.out @@ -0,0 +1,2 @@ +[{ "start": 0, "length": 524288, "depth": 0, "zero": false, "data": true}, +{ "start": 524288, "length": 524288, "depth": 0, "zero": true, "data": false}] diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 890fe91..624e1fb 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -205,3 +205,4 @@ 206 rw auto 207 rw auto 208 rw auto quick +209 rw auto quick -- cgit v1.1