Skip to content

Commit

Permalink
iotests: remove qemu_io_silent() and qemu_io_silent_check().
Browse files Browse the repository at this point in the history
Like qemu-img, qemu-io returning 0 should be the norm and not the
exception. Remove all calls to qemu_io_silent that just assert the
return code is zero (That's every last call, as it turns out), and
replace them with a normal qemu_io() call.

qemu_io_silent_check() appeared to have been unused already.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20220418211504.943969-12-jsnow@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
  • Loading branch information
jnsnow authored and XanClic committed Apr 25, 2022
1 parent 23d44dc commit 72cfb93
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 59 deletions.
12 changes: 6 additions & 6 deletions tests/qemu-iotests/216
Expand Up @@ -21,7 +21,7 @@
# Creator/Owner: Hanna Reitz <hreitz@redhat.com>

import iotests
from iotests import log, qemu_img, qemu_io_silent
from iotests import log, qemu_img, qemu_io

# Need backing file support
iotests.script_initialize(supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk'],
Expand Down Expand Up @@ -52,10 +52,10 @@ with iotests.FilePath('base.img') as base_img_path, \
log('')

qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M')
assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') == 0
qemu_io(base_img_path, '-c', 'write -P 1 0M 1M')
qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
'-F', iotests.imgfmt, top_img_path)
assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') == 0
qemu_io(top_img_path, '-c', 'write -P 2 1M 1M')

log('Done')

Expand Down Expand Up @@ -110,8 +110,8 @@ with iotests.FilePath('base.img') as base_img_path, \
log('--- Checking COR result ---')
log('')

assert qemu_io_silent(base_img_path, '-c', 'discard 0 64M') == 0
assert qemu_io_silent(top_img_path, '-c', 'read -P 1 0M 1M') == 0
assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') == 0
qemu_io(base_img_path, '-c', 'discard 0 64M')
qemu_io(top_img_path, '-c', 'read -P 1 0M 1M')
qemu_io(top_img_path, '-c', 'read -P 2 1M 1M')

log('Done')
5 changes: 2 additions & 3 deletions tests/qemu-iotests/218
Expand Up @@ -28,7 +28,7 @@
# Creator/Owner: Hanna Reitz <hreitz@redhat.com>

import iotests
from iotests import log, qemu_img, qemu_io_silent
from iotests import log, qemu_img, qemu_io

iotests.script_initialize(supported_fmts=['qcow2', 'raw'])

Expand Down Expand Up @@ -146,8 +146,7 @@ with iotests.VM() as vm, \
iotests.FilePath('src.img') as src_img_path:

qemu_img('create', '-f', iotests.imgfmt, src_img_path, '64M')
assert qemu_io_silent('-f', iotests.imgfmt, src_img_path,
'-c', 'write -P 42 0M 64M') == 0
qemu_io('-f', iotests.imgfmt, src_img_path, '-c', 'write -P 42 0M 64M')

vm.launch()

Expand Down
4 changes: 2 additions & 2 deletions tests/qemu-iotests/224
Expand Up @@ -22,7 +22,7 @@
# Creator/Owner: Hanna Reitz <hreitz@redhat.com>

import iotests
from iotests import log, qemu_img, qemu_io_silent, filter_qmp_testfiles, \
from iotests import log, qemu_img, qemu_io, filter_qmp_testfiles, \
filter_qmp_imgfmt
import json

Expand Down Expand Up @@ -54,7 +54,7 @@ for filter_node_name in False, True:
'-F', iotests.imgfmt, top_img_path)

# Something to commit
assert qemu_io_silent(mid_img_path, '-c', 'write -P 1 0 1M') == 0
qemu_io(mid_img_path, '-c', 'write -P 1 0 1M')

vm.launch()

Expand Down
11 changes: 5 additions & 6 deletions tests/qemu-iotests/258
Expand Up @@ -21,7 +21,7 @@
# Creator/Owner: Hanna Reitz <hreitz@redhat.com>

import iotests
from iotests import log, qemu_img, qemu_io_silent, \
from iotests import log, qemu_img, qemu_io, \
filter_qmp_testfiles, filter_qmp_imgfmt

# Returns a node for blockdev-add
Expand Down Expand Up @@ -86,15 +86,14 @@ def test_concurrent_finish(write_to_stream_node):
if write_to_stream_node:
# This is what (most of the time) makes commit finish
# earlier and then pull in stream
assert qemu_io_silent(node2_path,
'-c', 'write %iK 64K' % (65536 - 192),
'-c', 'write %iK 64K' % (65536 - 64)) == 0
qemu_io(node2_path,
'-c', 'write %iK 64K' % (65536 - 192),
'-c', 'write %iK 64K' % (65536 - 64))

stream_throttle='tg'
else:
# And this makes stream finish earlier
assert qemu_io_silent(node1_path,
'-c', 'write %iK 64K' % (65536 - 64)) == 0
qemu_io(node1_path, '-c', 'write %iK 64K' % (65536 - 64))

commit_throttle='tg'

Expand Down
17 changes: 7 additions & 10 deletions tests/qemu-iotests/298
Expand Up @@ -129,16 +129,13 @@ class TestTruncate(iotests.QMPTestCase):
os.remove(refdisk)

def do_test(self, prealloc_mode, new_size):
ret = iotests.qemu_io_silent('--image-opts', '-c', 'write 0 10M', '-c',
f'truncate -m {prealloc_mode} {new_size}',
drive_opts)
self.assertEqual(ret, 0)

ret = iotests.qemu_io_silent('-f', iotests.imgfmt, '-c', 'write 0 10M',
'-c',
f'truncate -m {prealloc_mode} {new_size}',
refdisk)
self.assertEqual(ret, 0)
iotests.qemu_io('--image-opts', '-c', 'write 0 10M', '-c',
f'truncate -m {prealloc_mode} {new_size}',
drive_opts)

iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write 0 10M',
'-c', f'truncate -m {prealloc_mode} {new_size}',
refdisk)

stat = os.stat(disk)
refstat = os.stat(refdisk)
Expand Down
22 changes: 11 additions & 11 deletions tests/qemu-iotests/310
Expand Up @@ -21,7 +21,7 @@
#

import iotests
from iotests import log, qemu_img, qemu_io_silent
from iotests import log, qemu_img, qemu_io

# Need backing file support
iotests.script_initialize(supported_fmts=['qcow2'],
Expand All @@ -44,15 +44,15 @@ with iotests.FilePath('base.img') as base_img_path, \
log('')

qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M')
assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') == 0
assert qemu_io_silent(base_img_path, '-c', 'write -P 1 3M 1M') == 0
qemu_io(base_img_path, '-c', 'write -P 1 0M 1M')
qemu_io(base_img_path, '-c', 'write -P 1 3M 1M')
qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
'-F', iotests.imgfmt, mid_img_path)
assert qemu_io_silent(mid_img_path, '-c', 'write -P 3 2M 1M') == 0
assert qemu_io_silent(mid_img_path, '-c', 'write -P 3 4M 1M') == 0
qemu_io(mid_img_path, '-c', 'write -P 3 2M 1M')
qemu_io(mid_img_path, '-c', 'write -P 3 4M 1M')
qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path,
'-F', iotests.imgfmt, top_img_path)
assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') == 0
qemu_io(top_img_path, '-c', 'write -P 2 1M 1M')

# 0 1 2 3 4
# top 2
Expand Down Expand Up @@ -107,10 +107,10 @@ with iotests.FilePath('base.img') as base_img_path, \
# Detach backing to check that we can read the data from the top level now
qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt, top_img_path)

assert qemu_io_silent(top_img_path, '-c', 'read -P 0 0 1M') == 0
assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') == 0
assert qemu_io_silent(top_img_path, '-c', 'read -P 3 2M 1M') == 0
assert qemu_io_silent(top_img_path, '-c', 'read -P 0 3M 1M') == 0
assert qemu_io_silent(top_img_path, '-c', 'read -P 3 4M 1M') == 0
qemu_io(top_img_path, '-c', 'read -P 0 0 1M')
qemu_io(top_img_path, '-c', 'read -P 2 1M 1M')
qemu_io(top_img_path, '-c', 'read -P 3 2M 1M')
qemu_io(top_img_path, '-c', 'read -P 0 3M 1M')
qemu_io(top_img_path, '-c', 'read -P 3 4M 1M')

log('Done')
16 changes: 0 additions & 16 deletions tests/qemu-iotests/iotests.py
Expand Up @@ -369,22 +369,6 @@ def qemu_io_log(*args: str) -> 'subprocess.CompletedProcess[str]':
log(result.stdout, filters=[filter_testfiles, filter_qemu_io])
return result

def qemu_io_silent(*args):
'''Run qemu-io and return the exit code, suppressing stdout'''
args = qemu_io_wrap_args(args)
result = subprocess.run(args, stdout=subprocess.DEVNULL, check=False)
if result.returncode < 0:
sys.stderr.write('qemu-io received signal %i: %s\n' %
(-result.returncode, ' '.join(args)))
return result.returncode

def qemu_io_silent_check(*args):
'''Run qemu-io and return the true if subprocess returned 0'''
args = qemu_io_wrap_args(args)
result = subprocess.run(args, stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT, check=False)
return result.returncode == 0

class QemuIoInteractive:
def __init__(self, *args):
self.args = qemu_io_wrap_args(args)
Expand Down
4 changes: 2 additions & 2 deletions tests/qemu-iotests/tests/image-fleecing
Expand Up @@ -25,7 +25,7 @@
from subprocess import CalledProcessError

import iotests
from iotests import log, qemu_img, qemu_io, qemu_io_silent
from iotests import log, qemu_img, qemu_io

iotests.script_initialize(
supported_fmts=['qcow2'],
Expand Down Expand Up @@ -270,7 +270,7 @@ def do_test(vm, use_cbw, use_snapshot_access_filter, base_img_path,
for p in overwrite + remainder:
cmd = 'read -P%s %s %s' % p
log(cmd)
assert qemu_io_silent(base_img_path, '-c', cmd) == 0
qemu_io(base_img_path, '-c', cmd)

log('')
log('Done')
Expand Down
2 changes: 1 addition & 1 deletion tests/qemu-iotests/tests/mirror-ready-cancel-error
Expand Up @@ -37,7 +37,7 @@ class TestMirrorReadyCancelError(iotests.QMPTestCase):
# Ensure that mirror will copy something before READY so the
# target format layer will forward the pre-READY flush to its
# file child
assert iotests.qemu_io_silent('-c', 'write -P 1 0 64k', source) == 0
iotests.qemu_io('-c', 'write -P 1 0 64k', source)

self.vm = iotests.VM()
self.vm.launch()
Expand Down
4 changes: 2 additions & 2 deletions tests/qemu-iotests/tests/stream-error-on-reset
Expand Up @@ -21,7 +21,7 @@

import os
import iotests
from iotests import imgfmt, qemu_img_create, qemu_io_silent, QMPTestCase
from iotests import imgfmt, qemu_img_create, qemu_io, QMPTestCase


image_size = 1 * 1024 * 1024
Expand Down Expand Up @@ -55,7 +55,7 @@ class TestStreamErrorOnReset(QMPTestCase):
- top image is attached to a virtio-scsi device
"""
qemu_img_create('-f', imgfmt, base, str(image_size))
assert qemu_io_silent('-c', f'write 0 {data_size}', base) == 0
qemu_io('-c', f'write 0 {data_size}', base)
qemu_img_create('-f', imgfmt, top, str(image_size))

self.vm = iotests.VM()
Expand Down

0 comments on commit 72cfb93

Please sign in to comment.