iotests: python3 compatibility
cover iotests: python3 compatibility
Hi,
This is a very boring series.
I a later series I refactor the iotests.py class, however when the first version of series [1] was posted I received comments that this class should no support Python 3.
I didn't tested with very old CentOS release, but this should work with Python versions >= 2.6.0a2.
Note: in today's IRC chat we suggest to drop Python 2 support for block iotests, continuing to support it for common scripts used by the build system.
I'm not a Python expert, so I'll be very happy/relieved if someone is willing to fix/continue/improve this series :)
Regards,
Phil.
[1]: http://lists.nongnu.org/archive/html/qemu-devel/2017-12/msg02339.html
Philippe Mathieu-Daudé (9):
qemu.py: replace iteritems() by items() for python3 compatibility qmp.py: encode JSON unicode as byte strings for python3 compatibility
iotests: replace print statement by print() function for python3
compatibility
iotests: use octal numbers for python3 compatibility
iotests: replace xrange() by range() for python3 compatibility
iotests: replace dict.has_key() by 'in' operator for python3
compatibility
iotests: replace lambda function by lambda expression for python3
compatibility
iotests: replace assertEquals() by assertEqual() for python3
compatibility
iotests.py: use io.StringIO with python3
scripts/qemu.py | 2 +- scripts/qmp/qmp.py | 2 +- tests/qemu-iotests/041 | 6 +++--- tests/qemu-iotests/044 | 14 +++++++------- tests/qemu-iotests/065 | 4 ++-- tests/qemu-iotests/093 | 2 +- tests/qemu-iotests/096 | 4 ++-- tests/qemu-iotests/118 | 28 ++++++++++++++-------------- tests/qemu-iotests/136 | 2 +- tests/qemu-iotests/139 | 2 +- tests/qemu-iotests/149 | 3 ++- tests/qemu-iotests/163 | 2 +- tests/qemu-iotests/165 | 3 ++- tests/qemu-iotests/iotests.py | 14 +++++++++----- 14 files changed, 47 insertions(+), 41 deletions(-)
Signature · 1 line
2.15.1
PATCH 1/9 qemu.py: replace iteritems() by items() for python3 compatibility
--- scripts/qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qemu.py +1 -1
@@ -247,7 +247,7 @@ class QEMUMachine(object): def qmp(self, cmd, conv_keys=True, **args): '''Invoke a QMP command and return the response dict''' qmp_args = dict() - for key, value in args.iteritems(): + for key, value in args.items(): if conv_keys: qmp_args[key.replace('_', '-')] = value else:
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 1/9] qemu.py: replace iteritems() by items() for python3 compatibility
Quoted 4 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- scripts/qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 2/9 qmp.py: encode JSON unicode as byte strings for python3 compatibility
In reply to Philippe Mathieu-Daudéthe socket API expects byte strings.
--- scripts/qmp/qmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qmp/qmp.py +1 -1
@@ -166,7 +166,7 @@ class QEMUMonitorProtocol(object): """ self.logger.debug(">>> %s", qmp_cmd) try: - self.__sock.sendall(json.dumps(qmp_cmd)) + self.__sock.sendall(json.dumps(qmp_cmd).encode()) except socket.error as err: if err[0] == errno.EPIPE: return
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 2/9] qmp.py: encode JSON unicode as byte strings for python3 compatibility
Quoted 6 lines · Philippe Mathieu-Daudé
the socket API expects byte strings.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- scripts/qmp/qmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 17 lines
scripts/qmp/qmp.py +1
-1@@ -166,7 +166,7 @@ class QEMUMonitorProtocol(object): """ self.logger.debug(">>> %s", qmp_cmd) try: - self.__sock.sendall(json.dumps(qmp_cmd)) + self.__sock.sendall(json.dumps(qmp_cmd).encode()) except socket.error as err: if err[0] == errno.EPIPE: returnSignature · 1 line
2.15.1
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 3/9 iotests: replace print statement by print() function for python3 compatibility
In reply to Philippe Mathieu-Daudé--- tests/qemu-iotests/149 | 3 ++- tests/qemu-iotests/165 | 3 ++- tests/qemu-iotests/iotests.py | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-)
tests/qemu-iotests/149 +2 -1
@@ -20,6 +20,7 @@ # Exercise the QEMU 'luks' block driver to validate interoperability # with the Linux dm-crypt + cryptsetup implementation +from __future__ import print_function import subprocess import os import os.path
@@ -376,7 +377,7 @@ def test_once(config, qemu_img=False): finally: iotests.log("# Delete image") delete_image(config) - print + print() # Obviously we only work with the luks image format
tests/qemu-iotests/165 +2 -1
@@ -18,6 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +from __future__ import print_function import os import re import iotests
@@ -85,7 +86,7 @@ class TestPersistentDirtyBitmap(iotests.QMPTestCase): log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) log = re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) if log: - print log + print(log) self.vm = self.mkVm() self.vm.launch()
tests/qemu-iotests/iotests.py +3 -2
@@ -16,6 +16,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +from __future__ import print_function import errno import os import re
@@ -145,7 +146,7 @@ def filter_qmp_event(event): def log(msg, filters=[]): for flt in filters: msg = flt(msg) - print msg + print(msg) class Timeout: def __init__(self, seconds, errmsg = "Timeout"):
@@ -417,7 +418,7 @@ def notrun(reason): seq = os.path.basename(sys.argv[0]) open('%s/%s.notrun' % (output_dir, seq), 'wb').write(reason + '\n') - print '%s not run: %s' % (seq, reason) + print("{} not run: {}".format(seq, reason)) sys.exit(0) def verify_image_format(supported_fmts=[], unsupported_fmts=[]):
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 3/9] iotests: replace print statement by print() function for python3 compatibility
Quoted 71 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/qemu-iotests/149 | 3 ++- tests/qemu-iotests/165 | 3 ++- tests/qemu-iotests/iotests.py | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-)tests/qemu-iotests/149 +2
-1@@ -20,6 +20,7 @@ # Exercise the QEMU 'luks' block driver to validate interoperability # with the Linux dm-crypt + cryptsetup implementation +from __future__ import print_function import subprocess import os import os.path@@ -376,7 +377,7 @@ def test_once(config, qemu_img=False): finally: iotests.log("# Delete image") delete_image(config) - print + print() # Obviously we only work with the luks image formattests/qemu-iotests/165 +2
-1@@ -18,6 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +from __future__ import print_function import os import re import iotests@@ -85,7 +86,7 @@ class TestPersistentDirtyBitmap(iotests.QMPTestCase): log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) log = re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) if log: - print log + print(log) self.vm = self.mkVm() self.vm.launch()tests/qemu-iotests/iotests.py +2
-1@@ -16,6 +16,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +from __future__ import print_function import errno import os import re@@ -145,7 +146,7 @@ def filter_qmp_event(event): def log(msg, filters=[]): for flt in filters: msg = flt(msg) - print msg + print(msg) class Timeout: def __init__(self, seconds, errmsg = "Timeout"):
tests/qemu-iotests/iotests.py def notrun(reason): · line 421
Quoted 5 lines
tests/qemu-iotests/iotests.py +1
-1@@ -417,7 +418,7 @@ def notrun(reason): seq = os.path.basename(sys.argv[0]) open('%s/%s.notrun' % (output_dir, seq), 'wb').write(reason + '\n') - print '%s not run: %s' % (seq, reason) + print("{} not run: {}".format(seq, reason))
I don't see the benefit in changing '%s' to '{}' and '%s' to '.format'. The original code is the idiomatic python IME.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 4/9 iotests: use octal numbers for python3 compatibility
In reply to Philippe Mathieu-Daudé--- tests/qemu-iotests/118 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
tests/qemu-iotests/118 +12 -12
@@ -417,14 +417,14 @@ class TestChangeReadOnly(ChangeBaseClass): def tearDown(self): self.vm.shutdown() - os.chmod(old_img, 0666) - os.chmod(new_img, 0666) + os.chmod(old_img, 0o666) + os.chmod(new_img, 0o666) os.remove(old_img) os.remove(new_img) def test_ro_ro_retain(self): - os.chmod(old_img, 0444) - os.chmod(new_img, 0444) + os.chmod(old_img, 0o444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy') self.vm.launch()
@@ -443,7 +443,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_ro_rw_retain(self): - os.chmod(old_img, 0444) + os.chmod(old_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy') self.vm.launch()
@@ -462,7 +462,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_rw_ro_retain(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'floppy') self.vm.launch()
@@ -483,7 +483,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img) def test_ro_rw(self): - os.chmod(old_img, 0444) + os.chmod(old_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy') self.vm.launch()
@@ -503,7 +503,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_rw_ro(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'floppy') self.vm.launch()
@@ -542,7 +542,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_make_ro_rw(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'floppy') self.vm.launch()
@@ -562,7 +562,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img) def test_make_rw_ro_by_retain(self): - os.chmod(old_img, 0444) + os.chmod(old_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy') self.vm.launch()
@@ -581,7 +581,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_make_ro_rw_by_retain(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'floppy') self.vm.launch()
@@ -600,7 +600,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img) def test_rw_ro_cycle(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'floppy') self.vm.launch()
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 4/9] iotests: use octal numbers for python3 compatibility
Quoted 4 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/qemu-iotests/118 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
Quoted 99 lines
tests/qemu-iotests/118 +12
-12@@ -417,14 +417,14 @@ class TestChangeReadOnly(ChangeBaseClass): def tearDown(self): self.vm.shutdown() - os.chmod(old_img, 0666) - os.chmod(new_img, 0666) + os.chmod(old_img, 0o666) + os.chmod(new_img, 0o666) os.remove(old_img) os.remove(new_img) def test_ro_ro_retain(self): - os.chmod(old_img, 0444) - os.chmod(new_img, 0444) + os.chmod(old_img, 0o444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy') self.vm.launch()@@ -443,7 +443,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_ro_rw_retain(self): - os.chmod(old_img, 0444) + os.chmod(old_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy') self.vm.launch()@@ -462,7 +462,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_rw_ro_retain(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'floppy') self.vm.launch()@@ -483,7 +483,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img) def test_ro_rw(self): - os.chmod(old_img, 0444) + os.chmod(old_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy') self.vm.launch()@@ -503,7 +503,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_rw_ro(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'floppy') self.vm.launch()@@ -542,7 +542,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_make_ro_rw(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'floppy') self.vm.launch()@@ -562,7 +562,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img) def test_make_rw_ro_by_retain(self): - os.chmod(old_img, 0444) + os.chmod(old_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy') self.vm.launch()@@ -581,7 +581,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_make_ro_rw_by_retain(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'floppy') self.vm.launch()@@ -600,7 +600,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img) def test_rw_ro_cycle(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'floppy') self.vm.launch()Signature · 1 line
2.15.1
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 5/9 iotests: replace xrange() by range() for python3 compatibility
In reply to Philippe Mathieu-Daudé--- tests/qemu-iotests/044 | 14 +++++++------- tests/qemu-iotests/163 | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-)
tests/qemu-iotests/044 +7 -7
@@ -52,23 +52,23 @@ class TestRefcountTableGrowth(iotests.QMPTestCase): # Write a refcount table fd.seek(off_reftable) - for i in xrange(0, h.refcount_table_clusters): + for i in range(0, h.refcount_table_clusters): sector = ''.join(struct.pack('>Q', off_refblock + i * 64 * 512 + j * 512) - for j in xrange(0, 64)) + for j in range(0, 64)) fd.write(sector) # Write the refcount blocks assert(fd.tell() == off_refblock) - sector = ''.join(struct.pack('>H', 1) for j in xrange(0, 64 * 256)) - for block in xrange(0, h.refcount_table_clusters): + sector = ''.join(struct.pack('>H', 1) for j in range(0, 64 * 256)) + for block in range(0, h.refcount_table_clusters): fd.write(sector) # Write the L1 table assert(fd.tell() == off_l1) assert(off_l2 + 512 * h.l1_size == off_data) table = ''.join(struct.pack('>Q', (1 << 63) | off_l2 + 512 * j) - for j in xrange(0, h.l1_size)) + for j in range(0, h.l1_size)) fd.write(table) # Write the L2 tables
@@ -79,14 +79,14 @@ class TestRefcountTableGrowth(iotests.QMPTestCase): off = off_data while remaining > 1024 * 512: pytable = list((1 << 63) | off + 512 * j - for j in xrange(0, 1024)) + for j in range(0, 1024)) table = struct.pack('>1024Q', *pytable) fd.write(table) remaining = remaining - 1024 * 512 off = off + 1024 * 512 table = ''.join(struct.pack('>Q', (1 << 63) | off + 512 * j) - for j in xrange(0, remaining / 512)) + for j in range(0, remaining / 512)) fd.write(table)
tests/qemu-iotests/163 +1 -1
@@ -41,7 +41,7 @@ class ShrinkBaseClass(iotests.QMPTestCase): div_roundup = lambda n, d: (n + d - 1) / d def split_by_n(data, n): - for x in xrange(0, len(data), n): + for x in range(0, len(data), n): yield struct.unpack('>Q', data[x:x + n])[0] & l1_mask def check_l1_table(h, l1_data):
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 5/9] iotests: replace xrange() by range() for python3 compatibility
Quoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/qemu-iotests/044 | 14 +++++++------- tests/qemu-iotests/163 | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-)
Quoted 67 lines
tests/qemu-iotests/044 +7
-7@@ -52,23 +52,23 @@ class TestRefcountTableGrowth(iotests.QMPTestCase): # Write a refcount table fd.seek(off_reftable) - for i in xrange(0, h.refcount_table_clusters): + for i in range(0, h.refcount_table_clusters): sector = ''.join(struct.pack('>Q', off_refblock + i * 64 * 512 + j * 512) - for j in xrange(0, 64)) + for j in range(0, 64)) fd.write(sector) # Write the refcount blocks assert(fd.tell() == off_refblock) - sector = ''.join(struct.pack('>H', 1) for j in xrange(0, 64 * 256)) - for block in xrange(0, h.refcount_table_clusters): + sector = ''.join(struct.pack('>H', 1) for j in range(0, 64 * 256)) + for block in range(0, h.refcount_table_clusters): fd.write(sector) # Write the L1 table assert(fd.tell() == off_l1) assert(off_l2 + 512 * h.l1_size == off_data) table = ''.join(struct.pack('>Q', (1 << 63) | off_l2 + 512 * j) - for j in xrange(0, h.l1_size)) + for j in range(0, h.l1_size)) fd.write(table) # Write the L2 tables@@ -79,14 +79,14 @@ class TestRefcountTableGrowth(iotests.QMPTestCase): off = off_data while remaining > 1024 * 512: pytable = list((1 << 63) | off + 512 * j - for j in xrange(0, 1024)) + for j in range(0, 1024)) table = struct.pack('>1024Q', *pytable) fd.write(table) remaining = remaining - 1024 * 512 off = off + 1024 * 512 table = ''.join(struct.pack('>Q', (1 << 63) | off + 512 * j) - for j in xrange(0, remaining / 512)) + for j in range(0, remaining / 512)) fd.write(table)tests/qemu-iotests/163 +1
-1@@ -41,7 +41,7 @@ class ShrinkBaseClass(iotests.QMPTestCase): div_roundup = lambda n, d: (n + d - 1) / d def split_by_n(data, n): - for x in xrange(0, len(data), n): + for x in range(0, len(data), n): yield struct.unpack('>Q', data[x:x + n])[0] & l1_mask def check_l1_table(h, l1_data):Signature · 1 line
2.15.1
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 6/9 iotests: replace dict.has_key() by 'in' operator for python3 compatibility
In reply to Philippe Mathieu-Daudé--- tests/qemu-iotests/093 | 2 +- tests/qemu-iotests/096 | 4 ++-- tests/qemu-iotests/136 | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
tests/qemu-iotests/093 +1 -1
@@ -237,7 +237,7 @@ class ThrottleTestGroupNames(iotests.QMPTestCase): if name: self.assertEqual(info["group"], name) else: - self.assertFalse(info.has_key('group')) + self.assertFalse('group' in info) return raise Exception("No group information found for '%s'" % device)
tests/qemu-iotests/096 +2 -2
@@ -53,9 +53,9 @@ class TestLiveSnapshot(iotests.QMPTestCase): self.assertEqual(r['iops'], self.iops) self.assertEqual(r['iops_size'], self.iops_size) else: - self.assertFalse(r.has_key('group')) + self.assertFalse('group' in r) self.assertEqual(r['iops'], 0) - self.assertFalse(r.has_key('iops_size')) + self.assertFalse('iops_size' in r) def testSnapshot(self): self.checkConfig('base')
tests/qemu-iotests/136 +1 -1
@@ -203,7 +203,7 @@ sector = "%d" if (self.accounted_ops(read = True, write = True, flush = True) != 0): self.assertLess(0, stats['idle_time_ns']) else: - self.assertFalse(stats.has_key('idle_time_ns')) + self.assertFalse('idle_time_ns' in stats) # This test does not alter these, so they must be all 0 self.assertEqual(0, stats['rd_merged'])
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 6/9] iotests: replace dict.has_key() by 'in' operator for python3 compatibility
Quoted 6 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/qemu-iotests/093 | 2 +- tests/qemu-iotests/096 | 4 ++-- tests/qemu-iotests/136 | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
Quoted 46 lines
tests/qemu-iotests/093 +1
-1@@ -237,7 +237,7 @@ class ThrottleTestGroupNames(iotests.QMPTestCase): if name: self.assertEqual(info["group"], name) else: - self.assertFalse(info.has_key('group')) + self.assertFalse('group' in info) return raise Exception("No group information found for '%s'" % device)tests/qemu-iotests/096 +2
-2@@ -53,9 +53,9 @@ class TestLiveSnapshot(iotests.QMPTestCase): self.assertEqual(r['iops'], self.iops) self.assertEqual(r['iops_size'], self.iops_size) else: - self.assertFalse(r.has_key('group')) + self.assertFalse('group' in r) self.assertEqual(r['iops'], 0) - self.assertFalse(r.has_key('iops_size')) + self.assertFalse('iops_size' in r) def testSnapshot(self): self.checkConfig('base')tests/qemu-iotests/136 +1
-1@@ -203,7 +203,7 @@ sector = "%d" if (self.accounted_ops(read = True, write = True, flush = True) != 0): self.assertLess(0, stats['idle_time_ns']) else: - self.assertFalse(stats.has_key('idle_time_ns')) + self.assertFalse('idle_time_ns' in stats) # This test does not alter these, so they must be all 0 self.assertEqual(0, stats['rd_merged'])Signature · 1 line
2.15.1
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 7/9 iotests: replace lambda function by lambda expression for python3 compatibility
In reply to Philippe Mathieu-Daudé--- tests/qemu-iotests/065 | 4 ++-- tests/qemu-iotests/139 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
tests/qemu-iotests/065 +2 -2
@@ -59,7 +59,7 @@ class TestQemuImgInfo(TestImageInfoSpecific): :data.index('')] for field in data: self.assertTrue(re.match('^ {4}[^ ]', field) is not None) - data = map(lambda line: line.strip(), data) + data = [line.strip() for line in data] self.assertEqual(data, self.human_compare) class TestQMP(TestImageInfoSpecific):
@@ -80,7 +80,7 @@ class TestQMP(TestImageInfoSpecific): def test_qmp(self): result = self.vm.qmp('query-block')['return'] - drive = filter(lambda drive: drive['device'] == 'drive0', result)[0] + drive = [drive for drive in result if drive['device'] == 'drive0'][0] data = drive['inserted']['image']['format-specific'] self.assertEqual(data['type'], iotests.imgfmt) self.assertEqual(data['data'], self.compare)
tests/qemu-iotests/139 +1 -1
@@ -51,7 +51,7 @@ class TestBlockdevDel(iotests.QMPTestCase): # Check whether a BlockDriverState exists def checkBlockDriverState(self, node, must_exist = True): result = self.vm.qmp('query-named-block-nodes') - nodes = filter(lambda x: x['node-name'] == node, result['return']) + nodes = [x for x in result['return'] if x['node-name'] == node] self.assertLessEqual(len(nodes), 1) self.assertEqual(must_exist, len(nodes) == 1)
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 7/9] iotests: replace lambda function by lambda expression for python3 compatibility
Quoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/qemu-iotests/065 | 4 ++-- tests/qemu-iotests/139 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
Quoted 39 lines
tests/qemu-iotests/065 +2
-2@@ -59,7 +59,7 @@ class TestQemuImgInfo(TestImageInfoSpecific): :data.index('')] for field in data: self.assertTrue(re.match('^ {4}[^ ]', field) is not None) - data = map(lambda line: line.strip(), data) + data = [line.strip() for line in data] self.assertEqual(data, self.human_compare) class TestQMP(TestImageInfoSpecific):@@ -80,7 +80,7 @@ class TestQMP(TestImageInfoSpecific): def test_qmp(self): result = self.vm.qmp('query-block')['return'] - drive = filter(lambda drive: drive['device'] == 'drive0', result)[0] + drive = [drive for drive in result if drive['device'] == 'drive0'][0] data = drive['inserted']['image']['format-specific'] self.assertEqual(data['type'], iotests.imgfmt) self.assertEqual(data['data'], self.compare)tests/qemu-iotests/139 +1
-1@@ -51,7 +51,7 @@ class TestBlockdevDel(iotests.QMPTestCase): # Check whether a BlockDriverState exists def checkBlockDriverState(self, node, must_exist = True): result = self.vm.qmp('query-named-block-nodes') - nodes = filter(lambda x: x['node-name'] == node, result['return']) + nodes = [x for x in result['return'] if x['node-name'] == node] self.assertLessEqual(len(nodes), 1) self.assertEqual(must_exist, len(nodes) == 1)Signature · 1 line
2.15.1
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 8/9 iotests: replace assertEquals() by assertEqual() for python3 compatibility
In reply to Philippe Mathieu-Daudé--- tests/qemu-iotests/041 | 6 +++--- tests/qemu-iotests/118 | 4 ++-- tests/qemu-iotests/iotests.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
tests/qemu-iotests/041 +3 -3
@@ -457,7 +457,7 @@ new_state = "1" self.assert_qmp(result, 'return', {}) event = self.vm.get_qmp_event(wait=True) - self.assertEquals(event['event'], 'BLOCK_JOB_ERROR') + self.assertEqual(event['event'], 'BLOCK_JOB_ERROR') self.assert_qmp(event, 'data/device', 'drive0') self.assert_qmp(event, 'data/operation', 'read') result = self.vm.qmp('query-block-jobs')
@@ -478,7 +478,7 @@ new_state = "1" self.assert_qmp(result, 'return', {}) event = self.vm.get_qmp_event(wait=True) - self.assertEquals(event['event'], 'BLOCK_JOB_ERROR') + self.assertEqual(event['event'], 'BLOCK_JOB_ERROR') self.assert_qmp(event, 'data/device', 'drive0') self.assert_qmp(event, 'data/operation', 'read') result = self.vm.qmp('query-block-jobs')
@@ -609,7 +609,7 @@ new_state = "1" self.assert_qmp(result, 'return', {}) event = self.vm.get_qmp_event(wait=True) - self.assertEquals(event['event'], 'BLOCK_JOB_ERROR') + self.assertEqual(event['event'], 'BLOCK_JOB_ERROR') self.assert_qmp(event, 'data/device', 'drive0') self.assert_qmp(event, 'data/operation', 'write') result = self.vm.qmp('query-block-jobs')
tests/qemu-iotests/118 +2 -2
@@ -295,7 +295,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass): result = self.vm.qmp('blockdev-close-tray', device='drive0') # Should be a no-op self.assert_qmp(result, 'return', {}) - self.assertEquals(self.vm.get_qmp_events(wait=False), []) + self.assertEqual(self.vm.get_qmp_events(wait=False), []) def test_remove_on_closed(self): if not self.has_real_tray:
@@ -476,7 +476,7 @@ class TestChangeReadOnly(ChangeBaseClass): read_only_mode='retain') self.assert_qmp(result, 'error/class', 'GenericError') - self.assertEquals(self.vm.get_qmp_events(wait=False), []) + self.assertEqual(self.vm.get_qmp_events(wait=False), []) result = self.vm.qmp('query-block') self.assert_qmp(result, 'return[0]/inserted/ro', False)
tests/qemu-iotests/iotests.py +1 -1
@@ -385,7 +385,7 @@ class QMPTestCase(unittest.TestCase): def wait_ready_and_cancel(self, drive='drive0'): self.wait_ready(drive=drive) event = self.cancel_and_wait(drive=drive) - self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED') + self.assertEqual(event['event'], 'BLOCK_JOB_COMPLETED') self.assert_qmp(event, 'data/type', 'mirror') self.assert_qmp(event, 'data/offset', event['data']['len'])
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 8/9] iotests: replace assertEquals() by assertEqual() for python3 compatibility
Quoted 6 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/qemu-iotests/041 | 6 +++--- tests/qemu-iotests/118 | 4 ++-- tests/qemu-iotests/iotests.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
Quoted 70 lines
tests/qemu-iotests/041 +3
-3@@ -457,7 +457,7 @@ new_state = "1" self.assert_qmp(result, 'return', {}) event = self.vm.get_qmp_event(wait=True) - self.assertEquals(event['event'], 'BLOCK_JOB_ERROR') + self.assertEqual(event['event'], 'BLOCK_JOB_ERROR') self.assert_qmp(event, 'data/device', 'drive0') self.assert_qmp(event, 'data/operation', 'read') result = self.vm.qmp('query-block-jobs')@@ -478,7 +478,7 @@ new_state = "1" self.assert_qmp(result, 'return', {}) event = self.vm.get_qmp_event(wait=True) - self.assertEquals(event['event'], 'BLOCK_JOB_ERROR') + self.assertEqual(event['event'], 'BLOCK_JOB_ERROR') self.assert_qmp(event, 'data/device', 'drive0') self.assert_qmp(event, 'data/operation', 'read') result = self.vm.qmp('query-block-jobs')@@ -609,7 +609,7 @@ new_state = "1" self.assert_qmp(result, 'return', {}) event = self.vm.get_qmp_event(wait=True) - self.assertEquals(event['event'], 'BLOCK_JOB_ERROR') + self.assertEqual(event['event'], 'BLOCK_JOB_ERROR') self.assert_qmp(event, 'data/device', 'drive0') self.assert_qmp(event, 'data/operation', 'write') result = self.vm.qmp('query-block-jobs')tests/qemu-iotests/118 +2
-2@@ -295,7 +295,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass): result = self.vm.qmp('blockdev-close-tray', device='drive0') # Should be a no-op self.assert_qmp(result, 'return', {}) - self.assertEquals(self.vm.get_qmp_events(wait=False), []) + self.assertEqual(self.vm.get_qmp_events(wait=False), []) def test_remove_on_closed(self): if not self.has_real_tray:@@ -476,7 +476,7 @@ class TestChangeReadOnly(ChangeBaseClass): read_only_mode='retain') self.assert_qmp(result, 'error/class', 'GenericError') - self.assertEquals(self.vm.get_qmp_events(wait=False), []) + self.assertEqual(self.vm.get_qmp_events(wait=False), []) result = self.vm.qmp('query-block') self.assert_qmp(result, 'return[0]/inserted/ro', False)tests/qemu-iotests/iotests.py +1
-1@@ -385,7 +385,7 @@ class QMPTestCase(unittest.TestCase): def wait_ready_and_cancel(self, drive='drive0'): self.wait_ready(drive=drive) event = self.cancel_and_wait(drive=drive) - self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED') + self.assertEqual(event['event'], 'BLOCK_JOB_COMPLETED') self.assert_qmp(event, 'data/type', 'mirror') self.assert_qmp(event, 'data/offset', event['data']['len'])Signature · 1 line
2.15.1
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 9/9 iotests.py: use io.StringIO with python3
In reply to Philippe Mathieu-Daudé--- tests/qemu-iotests/iotests.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tests/qemu-iotests/iotests.py +5 -2
@@ -459,13 +459,16 @@ def main(supported_fmts=[], supported_oses=['linux']): # We need to filter out the time taken from the output so that qemu-iotest # can reliably diff the results against master output. - import StringIO if debug: output = sys.stdout verbosity = 2 sys.argv.remove('-d') else: - output = StringIO.StringIO() + try: + from StringIO import StringIO + except ImportError: + from io import StringIO + output = StringIO() logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN))
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 9/9] iotests.py: use io.StringIO with python3
Quoted 15 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/qemu-iotests/iotests.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)tests/qemu-iotests/iotests.py +0
-1@@ -459,13 +459,16 @@ def main(supported_fmts=[], supported_oses=['linux']): # We need to filter out the time taken from the output so that qemu-iotest # can reliably diff the results against master output. - import StringIO if debug:
tests/qemu-iotests/iotests.py def main(supported_fmts=[], supported_oses=['linux']): · line 471
Quoted 10 lines
tests/qemu-iotests/iotests.py +5
-1output = sys.stdout verbosity = 2 sys.argv.remove('-d') else: - output = StringIO.StringIO() + try: + from StringIO import StringIO + except ImportError: + from io import StringIO + output = StringIO()
*Please* make a commit message that mentions that StringIO was moved into the io package for py3. It took me way too long to make any sense of this change until I read the except statement.
Maybe also add a comment.
Re: [Qemu-devel] [PATCH 9/9] iotests.py: use io.StringIO with python3
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/qemu-iotests/iotests.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 11 lines
tests/qemu-iotests/iotests.py +0
-1@@ -459,13 +459,16 @@ def main(supported_fmts=[], supported_oses=['linux']): # We need to filter out the time taken from the output so that qemu-iotest # can reliably diff the results against master output. - import StringIO if debug:
tests/qemu-iotests/iotests.py def main(supported_fmts=[], supported_oses=['linux']): · line 471
Quoted 10 lines
tests/qemu-iotests/iotests.py +5
-1output = sys.stdout verbosity = 2 sys.argv.remove('-d') else: - output = StringIO.StringIO() + try: + from StringIO import StringIO + except ImportError: + from io import StringIO + output = StringIO()
If it was nit-picking I'd put the py3 'io' import first and the py2 'StringIO' as the fallback, but doesn't honestly matter
Quoted 6 lines
tests/qemu-iotests/iotests.py +0
-0logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN))Signature · 1 line
2.15.1
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 10 lines · Philippe Mathieu-Daudé
Hi,
This is a very boring series.
I a later series I refactor the
iotests.pyclass, however when the first version of series [1] was posted I received comments that this class should no support Python 3.I didn't tested with very old CentOS release, but this should work with Python versions >= 2.6.0a2.
Thanks, this is useful. However, it'd be much easier if the commit messages showed the actual error message that is fixed, or an example.
Paolo