From nobody Mon Feb 9 20:30:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15126620206581018.5545707528744; Thu, 7 Dec 2017 07:53:40 -0800 (PST) Received: from localhost ([::1]:32968 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMyUP-0004x0-To for importer@patchew.org; Thu, 07 Dec 2017 10:53:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMySW-0003bk-VV for qemu-devel@nongnu.org; Thu, 07 Dec 2017 10:51:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMySU-0008BP-0g for qemu-devel@nongnu.org; Thu, 07 Dec 2017 10:51:37 -0500 Received: from [195.214.232.25] (port=38302 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMyST-00086c-Gf for qemu-devel@nongnu.org; Thu, 07 Dec 2017 10:51:33 -0500 Received: from kvm.sw.ru ([195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vB7Fp3Zh005896; Thu, 7 Dec 2017 18:51:04 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 7 Dec 2017 18:51:02 +0300 Message-Id: <20171207155102.66622-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20171207155102.66622-1-vsementsov@virtuozzo.com> References: <20171207155102.66622-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v2 6/6] iotest 201: new test for qmp nbd-server-remove X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, mreitz@redhat.com, den@openvz.org, pbonzini@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/201 | 130 +++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/201.out | 5 ++ tests/qemu-iotests/group | 1 + 3 files changed, 136 insertions(+) create mode 100644 tests/qemu-iotests/201 create mode 100644 tests/qemu-iotests/201.out diff --git a/tests/qemu-iotests/201 b/tests/qemu-iotests/201 new file mode 100644 index 0000000000..28d0324195 --- /dev/null +++ b/tests/qemu-iotests/201 @@ -0,0 +1,130 @@ +#!/usr/bin/env python +# +# Tests for qmp command nbd-server-remove. +# +# Copyright (c) 2017 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 os +import sys +import iotests +import time +from iotests import qemu_img, qemu_io, filter_qemu_io, QemuIoInteractive + +nbd_port =3D '10900' +nbd_uri =3D 'nbd+tcp://localhost:' + nbd_port + '/exp' +disk =3D os.path.join(iotests.test_dir, 'disk') + +class TestNbdServerRemove(iotests.QMPTestCase): + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, disk, '1M') + + self.vm =3D iotests.VM().add_drive(disk) + self.vm.launch() + + address =3D { + 'type': 'inet', + 'data': { + 'host': 'localhost', + 'port': nbd_port + } + } + + result =3D self.vm.qmp('nbd-server-start', addr=3Daddress) + self.assert_qmp(result, 'return', {}) + result =3D self.vm.qmp('nbd-server-add', device=3D'drive0', name= =3D'exp') + self.assert_qmp(result, 'return', {}) + + def tearDown(self): + self.vm.shutdown() + os.remove(disk) + + def remove_export(self, name, force=3DNone): + if force is None: + result =3D self.vm.qmp('nbd-server-remove', name=3Dname) + else: + result =3D self.vm.qmp('nbd-server-remove', name=3Dname, force= =3Dforce) + self.assert_qmp(result, 'return', {}) + + def assertExportNotFound(self, name): + result =3D self.vm.qmp('nbd-server-remove', name=3Dname) + self.assert_qmp(result, 'error/desc', "Export 'exp' is not found") + + def assertReadOk(self, qemu_io_output): + self.assertEqual(filter_qemu_io(qemu_io_output).strip(), + 'read 512/512 bytes at offset 0\n' + + '512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec= )') + + def assertReadFailed(self, qemu_io_output): + self.assertEqual(filter_qemu_io(qemu_io_output).strip(), + 'read failed: Input/output error') + + def assertConnectFailed(self, qemu_io_output): + self.assertEqual(filter_qemu_io(qemu_io_output).strip(), + "can't open device nbd+tcp://localhost:10900/exp:= " + + "Requested export not available\nserver reported:= " + + "export 'exp' not present") + + def do_test_connect_after_remove(self, force=3DNone): + args =3D ('-r', '-f', 'raw', '-c', 'read 0 512', nbd_uri) + self.assertReadOk(qemu_io(*args)) + self.remove_export('exp', force) + self.assertExportNotFound('exp') + self.assertConnectFailed(qemu_io(*args)) + + def test_connect_after_remove_default(self): + self.do_test_connect_after_remove() + + def test_connect_after_remove_safe(self): + self.do_test_connect_after_remove(False) + + def test_connect_after_remove_force(self): + self.do_test_connect_after_remove(True) + + def do_test_remove_during_connect(self, force=3DNone): + qio =3D QemuIoInteractive('-r', '-f', 'raw', nbd_uri) + self.assertReadOk(qio.cmd('read 0 512')) + self.remove_export('exp', force) + if force: + self.assertReadFailed(qio.cmd('read 0 512')) + self.assertExportNotFound('exp') + else: + self.assertReadOk(qio.cmd('read 0 512')) + qio.close() + self.assertExportNotFound('exp') + + def test_remove_during_connect_default(self): + self.do_test_remove_during_connect() + + def test_remove_during_connect_safe(self): + self.do_test_remove_during_connect(False) + + def test_remove_during_connect_force(self): + self.do_test_remove_during_connect(True) + + def test_remove_during_connect_safe_force(self): + qio =3D QemuIoInteractive('-r', '-f', 'raw', nbd_uri) + self.assertReadOk(qio.cmd('read 0 512')) + self.remove_export('exp', False) + self.assertReadOk(qio.cmd('read 0 512')) + self.remove_export('exp', True) + self.assertExportNotFound('exp') + self.assertReadFailed(qio.cmd('read 0 512')) + qio.close() + + +if __name__ =3D=3D '__main__': + iotests.main() diff --git a/tests/qemu-iotests/201.out b/tests/qemu-iotests/201.out new file mode 100644 index 0000000000..2f7d3902f2 --- /dev/null +++ b/tests/qemu-iotests/201.out @@ -0,0 +1,5 @@ +....... +---------------------------------------------------------------------- +Ran 7 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 3e688678dd..15df7678b3 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -197,3 +197,4 @@ 197 rw auto quick 198 rw auto 200 rw auto +201 rw auto quick --=20 2.11.1