From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
ehabkost@redhat.com, qemu-block@nongnu.org, philmd@redhat.com,
Max Reitz <mreitz@redhat.com>, John Snow <jsnow@redhat.com>
Subject: [PATCH RFC WIP 3/6] nbd-fault-injector: delint
Date: Wed, 13 May 2020 17:41:27 -0400 [thread overview]
Message-ID: <20200513214130.15375-4-jsnow@redhat.com> (raw)
In-Reply-To: <20200513214130.15375-1-jsnow@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
---
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 = $(wildcard *.py)
-KNOWN_GOOD = iotests.py
+KNOWN_GOOD = iotests.py nbd-fault-injector.py
CLEANFILES= *.out.bad *.notrun check.log check.time*
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 >= 3:
- import configparser
-else:
- import ConfigParser as configparser
+import configparser
FAKE_DISK_SIZE = 8 * 1024 * 1024 * 1024 # 8 GB
@@ -71,7 +68,9 @@
export_tuple = collections.namedtuple('Export', 'reserved magic opt len')
export_struct = struct.Struct('>IQII')
neg2_struct = struct.Struct('>QH124x')
-request_tuple = collections.namedtuple('Request', 'magic type handle from_ len')
+request_tuple = collections.namedtuple(
+ 'Request', 'magic type handle from_ len'
+)
request_struct = struct.Struct('>IIQQI')
reply_struct = struct.Struct('>IIQ')
@@ -84,13 +83,13 @@ def recvall(sock, bufsize):
chunks = []
while received < bufsize:
chunk = sock.recv(bufsize - received)
- if len(chunk) == 0:
+ if not chunk:
raise Exception('unexpected disconnect')
chunks.append(chunk)
received += len(chunk)
return b''.join(chunks)
-class Rule(object):
+class Rule:
def __init__(self, name, event, io, when):
self.name = name
self.event = event
@@ -104,7 +103,7 @@ def match(self, event, io):
return False
return True
-class FaultInjectionSocket(object):
+class FaultInjectionSocket:
def __init__(self, sock, rules):
self.sock = sock
self.rules = rules
@@ -150,7 +149,7 @@ def negotiate_export(conn):
export = export_tuple._make(export_struct.unpack(buf))
assert export.magic == NBD_OPTS_MAGIC
assert export.opt == NBD_OPT_EXPORT_NAME
- name = conn.recv(export.len, event='export-name')
+ _name = conn.recv(export.len, event='export-name')
# Send negotiation part 2
buf = 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 = 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 = options.get('io', 'readwrite')
if io not in ('read', 'write', 'readwrite'):
@@ -229,8 +229,8 @@ def parse_config(config):
def load_rules(filename):
config = 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)
def open_socket(path):
@@ -252,8 +252,14 @@ def open_socket(path):
return sock
def usage(args):
- sys.stderr.write('usage: %s [--classic-negotiation] <tcp-port>|<unix-path> <config-file>\n' % args[0])
- sys.stderr.write('Run an fault injector NBD server with rules defined in a config file.\n')
+ name = args[0]
+ sys.stderr.write(
+ f'usage: {name} [--classic-negotiation] '
+ '<tcp-port>|<unix-path> <config-file>\n'
+ )
+ sys.stderr.write(
+ 'Run a fault injector NBD server with '
+ 'rules defined in a config file.\n')
sys.exit(1)
def main(args):
--
2.21.1
next prev parent reply other threads:[~2020-05-13 21:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 21:41 [PATCH RFC WIP 0/6] iotests: delinting work-in-progress John Snow
2020-05-13 21:41 ` [PATCH RFC WIP 1/6] iotests: type hint wip John Snow
2020-05-13 21:41 ` [PATCH RFC WIP 2/6] Makefile: add delint WIP John Snow
2020-05-13 21:41 ` John Snow [this message]
2020-05-13 21:41 ` [PATCH RFC WIP 4/6] qed.py: delint John Snow
2020-05-13 21:41 ` [PATCH RFC WIP 5/6] qcow2.py: delint John Snow
2020-05-13 21:41 ` [PATCH RFC WIP 6/6] WIP: delint test files John Snow
2020-05-14 3:15 ` [PATCH RFC WIP 0/6] iotests: delinting work-in-progress no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200513214130.15375-4-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=ehabkost@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).