From nobody Mon May 6 00:08:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1572627345; cv=none; d=zoho.com; s=zohoarc; b=easHSpGleyw3QuE1SfmRBgfryvezM8CgktlVa1xY4CALJRwE5BO1s4GSwiBbWp9JYnorRDvHwGxAAjo+pPWI7XUOiy5NA2NTO4DONIgiuvvVO003iTQVVKFppU1F0y2t+1qYIsBeAqphc/c+UJtTY9AgI+5PHhuuf05pGtpbIQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572627345; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=gQhEx4uSITqpMJEP+iOCpO+pmwwWvP3MJjggkNjl0Lw=; b=LNKgM9NMW7QV8kyhsbAz8Qoi0FZXwovlKgCBu56U/jPbCdvpcssjQBgbp1CyIxWUxUc6KQd5E9AqLpp01RfUDaE9A02bRNLh7J+PNupCteQJRwNbkvaQYbGnjTz6SuFB738b/KR5B9kgrjvX1/xqalXBpXMkHKxAj/AxnjoO/lE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1572627344866629.0603830912444; Fri, 1 Nov 2019 09:55:44 -0700 (PDT) Received: from localhost ([::1]:41484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQaD8-0005KG-QX for importer@patchew.org; Fri, 01 Nov 2019 12:55:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38298) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQaCF-0004Xa-H5 for qemu-devel@nongnu.org; Fri, 01 Nov 2019 12:54:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iQaCD-0001SZ-Ub for qemu-devel@nongnu.org; Fri, 01 Nov 2019 12:54:47 -0400 Received: from relay.sw.ru ([185.231.240.75]:45004) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iQaCD-0001Qh-ND; Fri, 01 Nov 2019 12:54:45 -0400 Received: from [172.16.25.136] (helo=dhcp-172-16-25-136.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iQaC9-000771-FX; Fri, 01 Nov 2019 19:54:41 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v3] iotests: Test NBD client reconnection Date: Fri, 1 Nov 2019 19:54:32 +0300 Message-Id: <1572627272-23359-1-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The test for an NBD client. The NBD server is disconnected after the client write request. The NBD client should reconnect and complete the write operation. Suggested-by: Denis V. Lunev Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Andrey Shinkevich --- tests/qemu-iotests/277 | 102 +++++++++++++++++++++++++++= ++++ tests/qemu-iotests/277.out | 6 ++ tests/qemu-iotests/group | 1 + tests/qemu-iotests/iotests.py | 5 ++ tests/qemu-iotests/nbd-fault-injector.py | 3 +- 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100755 tests/qemu-iotests/277 create mode 100644 tests/qemu-iotests/277.out diff --git a/tests/qemu-iotests/277 b/tests/qemu-iotests/277 new file mode 100755 index 0000000..e4e6730 --- /dev/null +++ b/tests/qemu-iotests/277 @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# +# Test NBD client reconnection +# +# Copyright (c) 2019 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 subprocess +import iotests +from iotests import file_path, log + + +def make_conf_file(event): + """ + Create configuration file for the nbd-fault-injector.py + + :param event: which event the server should close a connection on + """ + if os.path.exists(conf_file): + os.remove(conf_file) + + with open(conf_file, "w+") as conff: + conff.write("[inject-error]\nevent=3D{}\nwhen=3Dafter".format(even= t)) + + +def start_server_NBD(event): + make_conf_file(event) + + srv =3D subprocess.Popen(["nbd-fault-injector.py", "--classic-negotiat= ion", + nbd_sock, conf_file], stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, universal_newlines= =3DTrue) + line =3D srv.stdout.readline() + if "Listening on " in line: + log('NBD server: started') + else: + log('NBD server: ' + line.rstrip()) + + return srv + + +def start_client_NBD(): + log('NBD client: QEMU-IO write') + args =3D iotests.qemu_io_args_no_fmt + \ + ['-c', 'write -P 0x7 0 3M', '--image-opts', + 'driver=3Dnbd,server.type=3Dunix,server.path=3D{},' + 'reconnect-delay=3D7'.format(nbd_sock)] + clt =3D subprocess.Popen(args, stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, + universal_newlines=3DTrue) + return clt + + +def check_proc_NBD(proc, connector): + try: + exitcode =3D proc.wait(timeout=3D10) + + if exitcode < 0: + log('NBD {}: EXIT SIGNAL {}\n'.format(connector, -exitcode)) + log(proc.communicate()[0]) + else: + line =3D proc.stdout.readline() + log('NBD {}: {}'.format(connector, line.rstrip())) + + except subprocess.TimeoutExpired: + proc.kill() + log('NBD {}: ERROR timeout expired'.format(connector)) + finally: + if connector =3D=3D 'server': + os.remove(nbd_sock) + os.remove(conf_file) + + +conf_file =3D os.path.join(iotests.test_dir, "nbd-fault-injector.conf") +nbd_sock =3D file_path('nbd-sock') +nbd_uri =3D 'nbd+unix:///?socket=3D' + nbd_sock +if os.path.exists(nbd_sock): + os.remove(nbd_sock) + +srv =3D start_server_NBD('data') +clt =3D start_client_NBD() +# The server should close the connection after a client write request +check_proc_NBD(srv, 'server') +# Start the NBD server again +srv =3D start_server_NBD('reply') +# The client should reconnect and complete the write operation +check_proc_NBD(clt, 'client') +# Make it sure that server terminated +check_proc_NBD(srv, 'server') diff --git a/tests/qemu-iotests/277.out b/tests/qemu-iotests/277.out new file mode 100644 index 0000000..45404b3 --- /dev/null +++ b/tests/qemu-iotests/277.out @@ -0,0 +1,6 @@ +NBD server: started +NBD client: QEMU-IO write +NBD server: Closing connection on rule match inject-error +NBD server: started +NBD client: wrote 3145728/3145728 bytes at offset 0 +NBD server: Closing connection on rule match inject-error diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index af322af..22ef1b8 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -282,3 +282,4 @@ 267 rw auto quick snapshot 268 rw auto quick 270 rw backing quick +277 rw diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 709def4..0d16303 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -47,6 +47,11 @@ qemu_io_args =3D [os.environ.get('QEMU_IO_PROG', 'qemu-i= o')] if os.environ.get('QEMU_IO_OPTIONS'): qemu_io_args +=3D os.environ['QEMU_IO_OPTIONS'].strip().split(' ') =20 +qemu_io_args_no_fmt =3D [os.environ.get('QEMU_IO_PROG', 'qemu-io')] +if os.environ.get('QEMU_IO_OPTIONS_NO_FMT'): + qemu_io_args_no_fmt +=3D \ + os.environ['QEMU_IO_OPTIONS_NO_FMT'].strip().split(' ') + qemu_nbd_args =3D [os.environ.get('QEMU_NBD_PROG', 'qemu-nbd')] if os.environ.get('QEMU_NBD_OPTIONS'): qemu_nbd_args +=3D os.environ['QEMU_NBD_OPTIONS'].strip().split(' ') diff --git a/tests/qemu-iotests/nbd-fault-injector.py b/tests/qemu-iotests/= nbd-fault-injector.py index 6b2d659..7e2dab6 100755 --- a/tests/qemu-iotests/nbd-fault-injector.py +++ b/tests/qemu-iotests/nbd-fault-injector.py @@ -115,7 +115,8 @@ class FaultInjectionSocket(object): if rule.match(event, io): if rule.when =3D=3D 0 or bufsize is None: print('Closing connection on rule match %s' % rule.nam= e) - self.sock.flush() + self.sock.close() + sys.stdout.flush() sys.exit(0) if rule.when !=3D -1: return rule.when --=20 1.8.3.1