From nobody Sat Feb 7 10:14:47 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589406165; cv=none; d=zohomail.com; s=zohoarc; b=MxjSQClFf9pXY4M2M4pSoLpIKbMyVFPJQHzvFnMJg7KH2MlEzxjGqsForuo/SnFRVgC7WmA+WBmlo+BDw0i6R68NutsGlXdoBR1y46ggsKgsD1jBskaj7SUjBHiNOJdfNMZmkrBsV0zSw3y+Vj795fcxoqNG+H4lbTVAsoqdRkg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589406165; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AQPoy5tHkY9or+yZngAsI3Otf/N2lSJ/rV5CdZXMGCw=; b=kA0oZyBxmG2dd2YzzzHxD/HolOU7ZjgZx+k7cF85cVqn4IM4XnISlj0cZ3mf65Zq+Sf1XtcSH80fE8rrFDPD7H60mKd2ma9CPdbzygVrkIjNeFRCZqlX6O7H+7eYP1SLMeovJq49l/g6xjcbpuClUljxVv/QmAVd1hf/SHMNa20= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1589406165967460.84147191515115; Wed, 13 May 2020 14:42:45 -0700 (PDT) Received: from localhost ([::1]:44648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYz9I-0007yk-Pj for importer@patchew.org; Wed, 13 May 2020 17:42:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYz8J-0006uY-85 for qemu-devel@nongnu.org; Wed, 13 May 2020 17:41:43 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:38042 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jYz8I-0005bY-8n for qemu-devel@nongnu.org; Wed, 13 May 2020 17:41:42 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-52-QpuKz1NNMhWdpQqL5AO6mw-1; Wed, 13 May 2020 17:41:35 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE4A5108BD09; Wed, 13 May 2020 21:41:34 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-80.rdu2.redhat.com [10.10.113.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBB512E034; Wed, 13 May 2020 21:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589406101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AQPoy5tHkY9or+yZngAsI3Otf/N2lSJ/rV5CdZXMGCw=; b=dEeNTr6dvKaHWg49m0ZvOTh/LAh+rWB3C5ojJrc8n3VJpztp87FkOIAHFgmRidKX8fnyNW h2TWBdPrAND/7Ghh0/hRD6BBb3kq263i7DzvIgWbshTdv1mGG4+WbMGQ5u589jTm8ftuN2 uE4skqS45X3CRc4tSdDK3pVXuj72g3s= X-MC-Unique: QpuKz1NNMhWdpQqL5AO6mw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC WIP 3/6] nbd-fault-injector: delint Date: Wed, 13 May 2020 17:41:27 -0400 Message-Id: <20200513214130.15375-4-jsnow@redhat.com> In-Reply-To: <20200513214130.15375-1-jsnow@redhat.com> References: <20200513214130.15375-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 01:56:38 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: Kevin Wolf , ehabkost@redhat.com, qemu-block@nongnu.org, philmd@redhat.com, Max Reitz , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow --- tests/qemu-iotests/Makefile | 2 +- tests/qemu-iotests/nbd-fault-injector.py | 34 ++++++++++++++---------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/qemu-iotests/Makefile b/tests/qemu-iotests/Makefile index 7dbb7f0fff..64db48342f 100644 --- a/tests/qemu-iotests/Makefile +++ b/tests/qemu-iotests/Makefile @@ -1,6 +1,6 @@ PYMODULES =3D $(wildcard *.py) =20 -KNOWN_GOOD =3D iotests.py +KNOWN_GOOD =3D iotests.py nbd-fault-injector.py =20 CLEANFILES=3D *.out.bad *.notrun check.log check.time* =20 diff --git a/tests/qemu-iotests/nbd-fault-injector.py b/tests/qemu-iotests/= nbd-fault-injector.py index 588d62aebf..0de6bc643e 100755 --- a/tests/qemu-iotests/nbd-fault-injector.py +++ b/tests/qemu-iotests/nbd-fault-injector.py @@ -47,10 +47,7 @@ import socket import struct import collections -if sys.version_info.major >=3D 3: - import configparser -else: - import ConfigParser as configparser +import configparser =20 FAKE_DISK_SIZE =3D 8 * 1024 * 1024 * 1024 # 8 GB =20 @@ -71,7 +68,9 @@ export_tuple =3D collections.namedtuple('Export', 'reserved magic opt len') export_struct =3D struct.Struct('>IQII') neg2_struct =3D struct.Struct('>QH124x') -request_tuple =3D collections.namedtuple('Request', 'magic type handle fro= m_ len') +request_tuple =3D collections.namedtuple( + 'Request', 'magic type handle from_ len' +) request_struct =3D struct.Struct('>IIQQI') reply_struct =3D struct.Struct('>IIQ') =20 @@ -84,13 +83,13 @@ def recvall(sock, bufsize): chunks =3D [] while received < bufsize: chunk =3D sock.recv(bufsize - received) - if len(chunk) =3D=3D 0: + if not chunk: raise Exception('unexpected disconnect') chunks.append(chunk) received +=3D len(chunk) return b''.join(chunks) =20 -class Rule(object): +class Rule: def __init__(self, name, event, io, when): self.name =3D name self.event =3D event @@ -104,7 +103,7 @@ def match(self, event, io): return False return True =20 -class FaultInjectionSocket(object): +class FaultInjectionSocket: def __init__(self, sock, rules): self.sock =3D sock self.rules =3D rules @@ -150,7 +149,7 @@ def negotiate_export(conn): export =3D export_tuple._make(export_struct.unpack(buf)) assert export.magic =3D=3D NBD_OPTS_MAGIC assert export.opt =3D=3D NBD_OPT_EXPORT_NAME - name =3D conn.recv(export.len, event=3D'export-name') + _name =3D conn.recv(export.len, event=3D'export-name') =20 # Send negotiation part 2 buf =3D neg2_struct.pack(FAKE_DISK_SIZE, 0) @@ -200,7 +199,8 @@ def parse_inject_error(name, options): if 'event' not in options: err('missing \"event\" option in %s' % name) event =3D options['event'] - if event not in ('neg-classic', 'neg1', 'export', 'neg2', 'request', '= reply', 'data'): + if event not in ('neg-classic', 'neg1', 'export', + 'neg2', 'request', 'reply', 'data'): err('invalid \"event\" option value \"%s\" in %s' % (event, name)) io =3D options.get('io', 'readwrite') if io not in ('read', 'write', 'readwrite'): @@ -229,8 +229,8 @@ def parse_config(config): =20 def load_rules(filename): config =3D configparser.RawConfigParser() - with open(filename, 'rt') as f: - config.readfp(f, filename) + with open(filename, 'rt') as infile: + config.read_file(infile) return parse_config(config) =20 def open_socket(path): @@ -252,8 +252,14 @@ def open_socket(path): return sock =20 def usage(args): - sys.stderr.write('usage: %s [--classic-negotiation] | \n' % args[0]) - sys.stderr.write('Run an fault injector NBD server with rules defined = in a config file.\n') + name =3D args[0] + sys.stderr.write( + f'usage: {name} [--classic-negotiation] ' + '| \n' + ) + sys.stderr.write( + 'Run a fault injector NBD server with ' + 'rules defined in a config file.\n') sys.exit(1) =20 def main(args): --=20 2.21.1