Skip to content

Commit

Permalink
iotests: Remove explicit checks for qemu_img() == 0
Browse files Browse the repository at this point in the history
qemu_img() returning zero ought to be the rule, not the
exception. Remove all explicit checks against the condition in
preparation for making non-zero returns an Exception.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20220321201618.903471-4-jsnow@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
  • Loading branch information
jnsnow authored and XanClic committed Mar 22, 2022
1 parent 062fd1d commit fc272d3
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 56 deletions.
9 changes: 3 additions & 6 deletions tests/qemu-iotests/163
Expand Up @@ -107,8 +107,7 @@ class ShrinkBaseClass(iotests.QMPTestCase):

if iotests.imgfmt == 'raw':
return
self.assertEqual(qemu_img('check', test_img), 0,
"Verifying image corruption")
qemu_img('check', test_img)

def test_empty_image(self):
qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img,
Expand All @@ -130,8 +129,7 @@ class ShrinkBaseClass(iotests.QMPTestCase):
qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img,
self.shrink_size)

self.assertEqual(qemu_img("compare", test_img, check_img), 0,
"Verifying image content")
qemu_img("compare", test_img, check_img)

self.image_verify()

Expand All @@ -146,8 +144,7 @@ class ShrinkBaseClass(iotests.QMPTestCase):
qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img,
self.shrink_size)

self.assertEqual(qemu_img("compare", test_img, check_img), 0,
"Verifying image content")
qemu_img("compare", test_img, check_img)

self.image_verify()

Expand Down
6 changes: 3 additions & 3 deletions tests/qemu-iotests/216
Expand Up @@ -51,10 +51,10 @@ with iotests.FilePath('base.img') as base_img_path, \
log('--- Setting up images ---')
log('')

assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0
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_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
'-F', iotests.imgfmt, top_img_path) == 0
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

log('Done')
Expand Down
2 changes: 1 addition & 1 deletion tests/qemu-iotests/218
Expand Up @@ -145,7 +145,7 @@ log('')
with iotests.VM() as vm, \
iotests.FilePath('src.img') as src_img_path:

assert qemu_img('create', '-f', iotests.imgfmt, src_img_path, '64M') == 0
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

Expand Down
11 changes: 5 additions & 6 deletions tests/qemu-iotests/224
Expand Up @@ -47,12 +47,11 @@ for filter_node_name in False, True:
iotests.FilePath('top.img') as top_img_path, \
iotests.VM() as vm:

assert qemu_img('create', '-f', iotests.imgfmt,
base_img_path, '64M') == 0
assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
'-F', iotests.imgfmt, mid_img_path) == 0
assert qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path,
'-F', iotests.imgfmt, top_img_path) == 0
qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M')
qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
'-F', iotests.imgfmt, mid_img_path)
qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path,
'-F', iotests.imgfmt, top_img_path)

# Something to commit
assert qemu_io_silent(mid_img_path, '-c', 'write -P 1 0 1M') == 0
Expand Down
12 changes: 6 additions & 6 deletions tests/qemu-iotests/228
Expand Up @@ -54,11 +54,11 @@ with iotests.FilePath('base.img') as base_img_path, \
iotests.FilePath('top.img') as top_img_path, \
iotests.VM() as vm:

assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0
qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M')
# Choose a funny way to describe the backing filename
assert qemu_img('create', '-f', iotests.imgfmt, '-b',
'file:' + base_img_path, '-F', iotests.imgfmt,
top_img_path) == 0
qemu_img('create', '-f', iotests.imgfmt, '-b',
'file:' + base_img_path, '-F', iotests.imgfmt,
top_img_path)

vm.launch()

Expand Down Expand Up @@ -172,8 +172,8 @@ with iotests.FilePath('base.img') as base_img_path, \
# (because qemu cannot "canonicalize"/"resolve" the backing
# filename unless the backing file is opened implicitly with the
# overlay)
assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
'-F', iotests.imgfmt, top_img_path) == 0
qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
'-F', iotests.imgfmt, top_img_path)

# You can only reliably override backing options by using a node
# reference (or by specifying file.filename, but, well...)
Expand Down
3 changes: 1 addition & 2 deletions tests/qemu-iotests/257
Expand Up @@ -240,8 +240,7 @@ def compare_images(image, reference, baseimg=None, expected_match=True):
"""
expected_ret = 0 if expected_match else 1
if baseimg:
assert qemu_img("rebase", "-u", "-b", baseimg, '-F', iotests.imgfmt,
image) == 0
qemu_img("rebase", "-u", "-b", baseimg, '-F', iotests.imgfmt, image)
ret = qemu_img("compare", image, reference)
log('qemu_img compare "{:s}" "{:s}" ==> {:s}, {:s}'.format(
image, reference,
Expand Down
4 changes: 2 additions & 2 deletions tests/qemu-iotests/258
Expand Up @@ -75,13 +75,13 @@ def test_concurrent_finish(write_to_stream_node):

# It is important to use raw for the base layer (so that
# permissions are just handed through to the protocol layer)
assert qemu_img('create', '-f', 'raw', node0_path, '64M') == 0
qemu_img('create', '-f', 'raw', node0_path, '64M')

stream_throttle=None
commit_throttle=None

for path in [node1_path, node2_path, node3_path, node4_path]:
assert qemu_img('create', '-f', iotests.imgfmt, path, '64M') == 0
qemu_img('create', '-f', iotests.imgfmt, path, '64M')

if write_to_stream_node:
# This is what (most of the time) makes commit finish
Expand Down
13 changes: 6 additions & 7 deletions tests/qemu-iotests/310
Expand Up @@ -43,15 +43,15 @@ with iotests.FilePath('base.img') as base_img_path, \
log('--- Setting up images ---')
log('')

assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0
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
assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
'-F', iotests.imgfmt, mid_img_path) == 0
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
assert qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path,
'-F', iotests.imgfmt, top_img_path) == 0
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

# 0 1 2 3 4
Expand Down Expand Up @@ -105,8 +105,7 @@ with iotests.FilePath('base.img') as base_img_path, \
log('')

# Detach backing to check that we can read the data from the top level now
assert qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt,
top_img_path) == 0
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
Expand Down
3 changes: 1 addition & 2 deletions tests/qemu-iotests/tests/block-status-cache
Expand Up @@ -35,8 +35,7 @@ nbd_sock = os.path.join(iotests.sock_dir, 'nbd.sock')
class TestBscWithNbd(iotests.QMPTestCase):
def setUp(self) -> None:
"""Just create an empty image with a read-only NBD server on it"""
assert qemu_img_create('-f', iotests.imgfmt, test_img,
str(image_size)) == 0
qemu_img_create('-f', iotests.imgfmt, test_img, str(image_size))

# Pass --allocation-depth to enable the qemu:allocation-depth context,
# which we are going to query to provoke a block-status inquiry with
Expand Down
7 changes: 3 additions & 4 deletions tests/qemu-iotests/tests/graph-changes-while-io
Expand Up @@ -34,16 +34,15 @@ def do_qemu_img_bench() -> None:
"""
Do some I/O requests on `nbd_sock`.
"""
assert qemu_img('bench', '-f', 'raw', '-c', '2000000',
f'nbd+unix:///node0?socket={nbd_sock}') == 0
qemu_img('bench', '-f', 'raw', '-c', '2000000',
f'nbd+unix:///node0?socket={nbd_sock}')


class TestGraphChangesWhileIO(QMPTestCase):
def setUp(self) -> None:
# Create an overlay that can be added at runtime on top of the
# null-co block node that will receive I/O
assert qemu_img_create('-f', imgfmt, '-F', 'raw', '-b', 'null-co://',
top) == 0
qemu_img_create('-f', imgfmt, '-F', 'raw', '-b', 'null-co://', top)

# QSD instance with a null-co block node in an I/O thread,
# exported over NBD (on `nbd_sock`, export name "node0")
Expand Down
10 changes: 5 additions & 5 deletions tests/qemu-iotests/tests/image-fleecing
Expand Up @@ -63,18 +63,18 @@ def do_test(vm, use_cbw, use_snapshot_access_filter, base_img_path,
log('--- Setting up images ---')
log('')

assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0
qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M')
if bitmap:
assert qemu_img('bitmap', '--add', base_img_path, 'bitmap0') == 0
qemu_img('bitmap', '--add', base_img_path, 'bitmap0')

if use_snapshot_access_filter:
assert use_cbw
assert qemu_img('create', '-f', 'raw', fleece_img_path, '64M') == 0
qemu_img('create', '-f', 'raw', fleece_img_path, '64M')
else:
assert qemu_img('create', '-f', 'qcow2', fleece_img_path, '64M') == 0
qemu_img('create', '-f', 'qcow2', fleece_img_path, '64M')

if push_backup:
assert qemu_img('create', '-f', 'qcow2', target_img_path, '64M') == 0
qemu_img('create', '-f', 'qcow2', target_img_path, '64M')

for p in patterns:
qemu_io('-f', iotests.imgfmt,
Expand Down
6 changes: 2 additions & 4 deletions tests/qemu-iotests/tests/mirror-ready-cancel-error
Expand Up @@ -31,10 +31,8 @@ target = os.path.join(iotests.test_dir, 'target.img')

class TestMirrorReadyCancelError(iotests.QMPTestCase):
def setUp(self) -> None:
assert iotests.qemu_img_create('-f', iotests.imgfmt, source,
str(image_size)) == 0
assert iotests.qemu_img_create('-f', iotests.imgfmt, target,
str(image_size)) == 0
iotests.qemu_img_create('-f', iotests.imgfmt, source, str(image_size))
iotests.qemu_img_create('-f', iotests.imgfmt, target, str(image_size))

# Ensure that mirror will copy something before READY so the
# target format layer will forward the pre-READY flush to its
Expand Down
3 changes: 1 addition & 2 deletions tests/qemu-iotests/tests/mirror-top-perms
Expand Up @@ -34,8 +34,7 @@ source = os.path.join(iotests.test_dir, 'source.img')

class TestMirrorTopPerms(iotests.QMPTestCase):
def setUp(self):
assert qemu_img('create', '-f', iotests.imgfmt, source,
str(image_size)) == 0
qemu_img('create', '-f', iotests.imgfmt, source, str(image_size))
self.vm = iotests.VM()
self.vm.add_drive(source)
self.vm.add_blockdev(f'null-co,node-name=null,size={image_size}')
Expand Down
8 changes: 4 additions & 4 deletions tests/qemu-iotests/tests/remove-bitmap-from-backing
Expand Up @@ -27,11 +27,11 @@ iotests.script_initialize(supported_fmts=['qcow2'],
top, base = iotests.file_path('top', 'base')
size = '1M'

assert qemu_img_create('-f', iotests.imgfmt, base, size) == 0
assert qemu_img_create('-f', iotests.imgfmt, '-b', base,
'-F', iotests.imgfmt, top, size) == 0
qemu_img_create('-f', iotests.imgfmt, base, size)
qemu_img_create('-f', iotests.imgfmt, '-b', base,
'-F', iotests.imgfmt, top, size)

assert qemu_img('bitmap', '--add', base, 'bitmap0') == 0
qemu_img('bitmap', '--add', base, 'bitmap0')
# Just assert that our method of checking bitmaps in the image works.
assert 'bitmaps' in qemu_img_pipe('info', base)

Expand Down
4 changes: 2 additions & 2 deletions tests/qemu-iotests/tests/stream-error-on-reset
Expand Up @@ -54,9 +54,9 @@ class TestStreamErrorOnReset(QMPTestCase):
to it will result in an error
- top image is attached to a virtio-scsi device
"""
assert qemu_img_create('-f', imgfmt, base, str(image_size)) == 0
qemu_img_create('-f', imgfmt, base, str(image_size))
assert qemu_io_silent('-c', f'write 0 {data_size}', base) == 0
assert qemu_img_create('-f', imgfmt, top, str(image_size)) == 0
qemu_img_create('-f', imgfmt, top, str(image_size))

self.vm = iotests.VM()
self.vm.add_args('-accel', 'tcg') # Make throttling work properly
Expand Down

0 comments on commit fc272d3

Please sign in to comment.