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 4/6] qed.py: delint
Date: Wed, 13 May 2020 17:41:28 -0400 [thread overview]
Message-ID: <20200513214130.15375-5-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/qed.py | 46 ++++++++++++++++++++++++-------------
2 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/tests/qemu-iotests/Makefile b/tests/qemu-iotests/Makefile
index 64db48342f..5a3a1e8092 100644
--- a/tests/qemu-iotests/Makefile
+++ b/tests/qemu-iotests/Makefile
@@ -1,6 +1,6 @@
PYMODULES = $(wildcard *.py)
-KNOWN_GOOD = iotests.py nbd-fault-injector.py
+KNOWN_GOOD = iotests.py nbd-fault-injector.py qed.py
CLEANFILES= *.out.bad *.notrun check.log check.time*
diff --git a/tests/qemu-iotests/qed.py b/tests/qemu-iotests/qed.py
index d6bec96069..9e016cc2a2 100755
--- a/tests/qemu-iotests/qed.py
+++ b/tests/qemu-iotests/qed.py
@@ -13,7 +13,6 @@
import sys
import struct
import random
-import optparse
# This can be used as a module
__all__ = ['QED_F_NEED_CHECK', 'QED']
@@ -47,7 +46,7 @@ def unpack_table_elem(s):
def pack_table_elem(elem):
return struct.pack(table_elem_fmt, elem)
-class QED(object):
+class QED:
def __init__(self, f):
self.f = f
@@ -74,19 +73,22 @@ def store_header(self):
def read_table(self, offset):
size = self.header['table_size'] * self.header['cluster_size']
s = self.raw_pread(offset, size)
- table = [unpack_table_elem(s[i:i + table_elem_size]) for i in xrange(0, size, table_elem_size)]
+ table = [unpack_table_elem(s[i:i + table_elem_size])
+ for i in range(0, size, table_elem_size)]
return table
def load_l1_table(self):
self.l1_table = self.read_table(self.header['l1_table_offset'])
- self.table_nelems = self.header['table_size'] * self.header['cluster_size'] // table_elem_size
+ self.table_nelems = (self.header['table_size']
+ * self.header['cluster_size'] // table_elem_size)
def write_table(self, offset, table):
s = ''.join(pack_table_elem(x) for x in table)
self.raw_pwrite(offset, s)
def random_table_item(table):
- vals = [(index, offset) for index, offset in enumerate(table) if offset != 0]
+ vals = [(index, offset) for index, offset
+ in enumerate(table) if offset != 0]
if not vals:
err('cannot pick random item because table is empty')
return random.choice(vals)
@@ -103,7 +105,8 @@ def corrupt_table_duplicate(table):
def corrupt_table_invalidate(qed, table):
'''Corrupt a table by introducing an invalid offset'''
index, _ = random_table_item(table)
- table[index] = qed.filesize + random.randint(0, 100 * 1024 * 1024 * 1024 * 1024)
+ table[index] = (qed.filesize
+ + random.randint(0, 100 * 1024 * 1024 * 1024 * 1024))
def cmd_show(qed, *args):
'''show [header|l1|l2 <offset>]- Show header or l1/l2 tables'''
@@ -144,7 +147,11 @@ def cmd_invalidate(qed, table_level):
qed.write_table(offset, table)
def cmd_need_check(qed, *args):
- '''need-check [on|off] - Test, set, or clear the QED_F_NEED_CHECK header bit'''
+ """
+ need-check [on|off]
+
+ Test, set, or clear the QED_F_NEED_CHECK header bit
+ """
if not args:
print(bool(qed.header['features'] & QED_F_NEED_CHECK))
return
@@ -165,7 +172,7 @@ def cmd_zero_cluster(qed, pos, *args):
err('expected one argument')
n = int(args[0])
- for i in xrange(n):
+ for _ in range(n):
l1_index = pos // qed.header['cluster_size'] // len(qed.l1_table)
if qed.l1_table[l1_index] == 0:
err('no l2 table allocated')
@@ -179,7 +186,11 @@ def cmd_zero_cluster(qed, pos, *args):
pos += qed.header['cluster_size']
def cmd_copy_metadata(qed, outfile):
- '''copy-metadata <outfile> - Copy metadata only (for scrubbing corrupted images)'''
+ """
+ copy-metadata <outfile>
+
+ Copy metadata only (for scrubbing corrupted images)
+ """
out = open(outfile, 'wb')
# Match file size
@@ -213,23 +224,26 @@ def usage():
print('Supported commands:')
for cmd in sorted(x for x in globals() if x.startswith('cmd_')):
print(globals()[cmd].__doc__)
- sys.exit(1)
+ return 1
def main():
if len(sys.argv) < 3:
- usage()
- filename, cmd = sys.argv[1:3]
+ return usage()
+ filename = sys.argv[1]
+ cmd = sys.argv[2]
cmd = 'cmd_' + cmd.replace('-', '_')
if cmd not in globals():
- usage()
+ return usage()
qed = QED(open(filename, 'r+b'))
try:
globals()[cmd](qed, *sys.argv[3:])
- except TypeError as e:
+ except TypeError:
sys.stderr.write(globals()[cmd].__doc__ + '\n')
- sys.exit(1)
+ return 1
+
+ return 0
if __name__ == '__main__':
- main()
+ sys.exit(main())
--
2.21.1
next prev parent reply other threads:[~2020-05-13 21:46 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 ` [PATCH RFC WIP 3/6] nbd-fault-injector: delint John Snow
2020-05-13 21:41 ` John Snow [this message]
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-5-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).