aboutsummaryrefslogtreecommitdiff
path: root/tests/qemu-iotests/040
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>2023-10-06 18:41:25 +0300
committerJohn Snow <jsnow@redhat.com>2023-10-12 14:21:44 -0400
commitb6aed193e5ecca32bb07e062f58f0daca06e7009 (patch)
tree869a1bf90b35f8bff095472c3c9f9ccd5631fe26 /tests/qemu-iotests/040
parent25ad2cf6500db3b7f2d88de448791183d7614097 (diff)
python: use vm.cmd() instead of vm.qmp() where appropriate
In many cases we just want an effect of qmp command and want to raise on failure. Use vm.cmd() method which does exactly this. The commit is generated by command git grep -l '\.qmp(' | xargs ./scripts/python_qmp_updater.py And then, fix self.assertRaises to expect ExecuteError exception in tests/qemu-iotests/124 Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20231006154125.1068348-16-vsementsov@yandex-team.ru Signed-off-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'tests/qemu-iotests/040')
-rwxr-xr-xtests/qemu-iotests/040172
1 files changed, 71 insertions, 101 deletions
diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040
index 4b8bf09a5d..5c18e413ec 100755
--- a/tests/qemu-iotests/040
+++ b/tests/qemu-iotests/040
@@ -61,17 +61,14 @@ class ImageCommitTestCase(iotests.QMPTestCase):
def run_commit_test(self, top, base, need_ready=False, node_names=False):
self.assert_no_active_block_jobs()
if node_names:
- result = self.vm.qmp('block-commit', device='drive0', top_node=top, base_node=base)
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit', device='drive0', top_node=top, base_node=base)
else:
- result = self.vm.qmp('block-commit', device='drive0', top=top, base=base)
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit', device='drive0', top=top, base=base)
self.wait_for_complete(need_ready)
def run_default_commit_test(self):
self.assert_no_active_block_jobs()
- result = self.vm.qmp('block-commit', device='drive0')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit', device='drive0')
self.wait_for_complete()
class TestSingleDrive(ImageCommitTestCase):
@@ -118,38 +115,30 @@ class TestSingleDrive(ImageCommitTestCase):
@iotests.skip_if_unsupported(['throttle'])
def test_commit_with_filter_and_quit(self):
- result = self.vm.qmp('object-add', qom_type='throttle-group', id='tg')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('object-add', qom_type='throttle-group', id='tg')
# Add a filter outside of the backing chain
- result = self.vm.qmp('blockdev-add', driver='throttle', node_name='filter', throttle_group='tg', file='mid')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('blockdev-add', driver='throttle', node_name='filter', throttle_group='tg', file='mid')
- result = self.vm.qmp('block-commit', device='drive0')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit', device='drive0')
# Quit immediately, thus forcing a simultaneous cancel of the
# block job and a bdrv_drain_all()
- result = self.vm.qmp('quit')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('quit')
# Same as above, but this time we add the filter after starting the job
@iotests.skip_if_unsupported(['throttle'])
def test_commit_plus_filter_and_quit(self):
- result = self.vm.qmp('object-add', qom_type='throttle-group', id='tg')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('object-add', qom_type='throttle-group', id='tg')
- result = self.vm.qmp('block-commit', device='drive0')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit', device='drive0')
# Add a filter outside of the backing chain
- result = self.vm.qmp('blockdev-add', driver='throttle', node_name='filter', throttle_group='tg', file='mid')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('blockdev-add', driver='throttle', node_name='filter', throttle_group='tg', file='mid')
# Quit immediately, thus forcing a simultaneous cancel of the
# block job and a bdrv_drain_all()
- result = self.vm.qmp('quit')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('quit')
def test_device_not_found(self):
result = self.vm.qmp('block-commit', device='nonexistent', top='%s' % mid_img)
@@ -226,8 +215,7 @@ class TestSingleDrive(ImageCommitTestCase):
def test_top_node_in_wrong_chain(self):
self.assert_no_active_block_jobs()
- result = self.vm.qmp('blockdev-add', driver='null-co', node_name='null')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('blockdev-add', driver='null-co', node_name='null')
result = self.vm.qmp('block-commit', device='drive0', top_node='null', base_node='base')
self.assert_qmp(result, 'error/class', 'GenericError')
@@ -240,11 +228,9 @@ class TestSingleDrive(ImageCommitTestCase):
return
self.assert_no_active_block_jobs()
- result = self.vm.qmp('block-commit', device='drive0', top=mid_img,
- base=backing_img, speed=(self.image_len // 4))
- self.assert_qmp(result, 'return', {})
- result = self.vm.qmp('device_del', id='scsi0')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit', device='drive0', top=mid_img,
+ base=backing_img, speed=(self.image_len // 4))
+ self.vm.cmd('device_del', id='scsi0')
cancelled = False
deleted = False
@@ -270,9 +256,8 @@ class TestSingleDrive(ImageCommitTestCase):
return
self.assert_no_active_block_jobs()
- result = self.vm.qmp('block-commit', device='drive0', top=mid_img,
- base=backing_img, speed=(self.image_len // 4))
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit', device='drive0', top=mid_img,
+ base=backing_img, speed=(self.image_len // 4))
result = self.vm.qmp('query-block')
self.assert_qmp(result, 'return[0]/inserted/file', test_img)
@@ -407,8 +392,7 @@ class TestSetSpeed(ImageCommitTestCase):
self.assert_no_active_block_jobs()
self.vm.pause_drive('drive0')
- result = self.vm.qmp('block-commit', device='drive0', top=mid_img, speed=1024 * 1024)
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit', device='drive0', top=mid_img, speed=1024 * 1024)
# Ensure the speed we set was accepted
result = self.vm.qmp('query-block-jobs')
@@ -481,8 +465,7 @@ class TestErrorHandling(iotests.QMPTestCase):
os.remove(backing_img)
def blockdev_add(self, **kwargs):
- result = self.vm.qmp('blockdev-add', **kwargs)
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('blockdev-add', **kwargs)
def add_block_nodes(self, base_debug=None, mid_debug=None, top_debug=None):
self.blockdev_add(node_name='base-file', driver='file',
@@ -528,11 +511,9 @@ class TestErrorHandling(iotests.QMPTestCase):
completed = True
elif ev['event'] == 'BLOCK_JOB_ERROR':
if error_pauses_job:
- result = self.vm.qmp('block-job-resume', device='job0')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-job-resume', device='job0')
elif ev['event'] == 'BLOCK_JOB_READY':
- result = self.vm.qmp('block-job-complete', device='job0')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-job-complete', device='job0')
else:
self.fail("Unexpected event: %s" % ev)
log.append(iotests.filter_qmp_event(ev))
@@ -595,11 +576,10 @@ class TestErrorHandling(iotests.QMPTestCase):
self.add_block_nodes(top_debug=top_debug, mid_debug=mid_debug,
base_debug=base_debug)
- result = self.vm.qmp('block-commit', job_id='job0', device='top-fmt',
- top_node='top-fmt' if active else 'mid-fmt',
- base_node='mid-fmt' if active else 'base-fmt',
- on_error=on_error)
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit', job_id='job0', device='top-fmt',
+ top_node='top-fmt' if active else 'mid-fmt',
+ base_node='mid-fmt' if active else 'base-fmt',
+ on_error=on_error)
def testActiveReadErrorReport(self):
self.prepare_and_start_job('report', top_event='read_aio')
@@ -771,10 +751,9 @@ class TestCommitWithFilters(iotests.QMPTestCase):
self.vm = iotests.VM().add_device('virtio-scsi,id=vio-scsi')
self.vm.launch()
- result = self.vm.qmp('object-add', qom_type='throttle-group', id='tg')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('object-add', qom_type='throttle-group', id='tg')
- result = self.vm.qmp('blockdev-add', {
+ self.vm.cmd('blockdev-add', {
'node-name': 'top-filter',
'driver': 'throttle',
'throttle-group': 'tg',
@@ -816,7 +795,6 @@ class TestCommitWithFilters(iotests.QMPTestCase):
}
}
})
- self.assert_qmp(result, 'return', {})
def tearDown(self):
self.vm.shutdown()
@@ -833,13 +811,12 @@ class TestCommitWithFilters(iotests.QMPTestCase):
return self.vm.node_info(node)['image']['filename']
def test_filterless_commit(self):
- result = self.vm.qmp('block-commit',
- job_id='commit',
- device='top-filter',
- top_node='cow-2',
- base_node='cow-1',
- backing_file=self.img1)
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit',
+ job_id='commit',
+ device='top-filter',
+ top_node='cow-2',
+ base_node='cow-1',
+ backing_file=self.img1)
self.wait_until_completed(drive='commit')
self.assertIsNotNone(self.vm.node_info('cow-3'))
@@ -850,13 +827,12 @@ class TestCommitWithFilters(iotests.QMPTestCase):
self.pattern_files[2] = self.img1
def test_commit_through_filter(self):
- result = self.vm.qmp('block-commit',
- job_id='commit',
- device='top-filter',
- top_node='cow-1',
- base_node='cow-0',
- backing_file=self.img0)
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit',
+ job_id='commit',
+ device='top-filter',
+ top_node='cow-1',
+ base_node='cow-0',
+ backing_file=self.img0)
self.wait_until_completed(drive='commit')
self.assertIsNotNone(self.vm.node_info('cow-2'))
@@ -871,9 +847,8 @@ class TestCommitWithFilters(iotests.QMPTestCase):
# Add a device, so the commit job finds a parent it can change
# to point to the base node (so we can test that top-filter is
# dropped from the graph)
- result = self.vm.qmp('device_add', id='drv0', driver='scsi-hd',
- bus='vio-scsi.0', drive='top-filter')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('device_add', id='drv0', driver='scsi-hd',
+ bus='vio-scsi.0', drive='top-filter')
# Try to release our reference to top-filter; that should not
# work because drv0 uses it
@@ -881,16 +856,14 @@ class TestCommitWithFilters(iotests.QMPTestCase):
self.assert_qmp(result, 'error/class', 'GenericError')
self.assert_qmp(result, 'error/desc', 'Node top-filter is in use')
- result = self.vm.qmp('block-commit',
- job_id='commit',
- device='top-filter',
- base_node='cow-2')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit',
+ job_id='commit',
+ device='top-filter',
+ base_node='cow-2')
self.complete_and_wait(drive='commit')
# Try to release our reference to top-filter again
- result = self.vm.qmp('blockdev-del', node_name='top-filter')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('blockdev-del', node_name='top-filter')
self.assertIsNone(self.vm.node_info('top-filter'))
self.assertIsNone(self.vm.node_info('cow-3'))
@@ -905,12 +878,11 @@ class TestCommitWithFilters(iotests.QMPTestCase):
self.pattern_files[3] = self.img2
def test_filtered_active_commit_without_filter(self):
- result = self.vm.qmp('block-commit',
- job_id='commit',
- device='top-filter',
- top_node='cow-3',
- base_node='cow-2')
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit',
+ job_id='commit',
+ device='top-filter',
+ top_node='cow-3',
+ base_node='cow-2')
self.complete_and_wait(drive='commit')
self.assertIsNotNone(self.vm.node_info('top-filter'))
@@ -935,23 +907,22 @@ class TestCommitWithOverriddenBacking(iotests.QMPTestCase):
self.vm.launch()
# Use base_b instead of base_a as the backing of top
- result = self.vm.qmp('blockdev-add', {
- 'node-name': 'top',
- 'driver': iotests.imgfmt,
- 'file': {
- 'driver': 'file',
- 'filename': self.img_top
- },
- 'backing': {
- 'node-name': 'base',
- 'driver': iotests.imgfmt,
- 'file': {
- 'driver': 'file',
- 'filename': self.img_base_b
- }
- }
- })
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('blockdev-add', {
+ 'node-name': 'top',
+ 'driver': iotests.imgfmt,
+ 'file': {
+ 'driver': 'file',
+ 'filename': self.img_top
+ },
+ 'backing': {
+ 'node-name': 'base',
+ 'driver': iotests.imgfmt,
+ 'file': {
+ 'driver': 'file',
+ 'filename': self.img_base_b
+ }
+ }
+ })
def tearDown(self):
self.vm.shutdown()
@@ -971,11 +942,10 @@ class TestCommitWithOverriddenBacking(iotests.QMPTestCase):
def test_commit_to_b(self):
# Try committing to base_b (which should work, since that is
# actually top's backing image)
- result = self.vm.qmp('block-commit',
- job_id='commit',
- device='top',
- base=self.img_base_b)
- self.assert_qmp(result, 'return', {})
+ self.vm.cmd('block-commit',
+ job_id='commit',
+ device='top',
+ base=self.img_base_b)
self.vm.event_wait('BLOCK_JOB_READY')
self.vm.qmp('block-job-complete', device='commit')