aboutsummaryrefslogtreecommitdiff
path: root/tests/qemu-iotests/iotests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qemu-iotests/iotests.py')
-rw-r--r--tests/qemu-iotests/iotests.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 0e7862cee5..bc9c71b979 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -174,6 +174,24 @@ class QMPTestCase(unittest.TestCase):
result = self.vm.qmp('query-block-jobs')
self.assert_qmp(result, 'return', [])
+ def cancel_and_wait(self, drive='drive0', force=False):
+ '''Cancel a block job and wait for it to finish, returning the event'''
+ result = self.vm.qmp('block-job-cancel', device=drive, force=force)
+ self.assert_qmp(result, 'return', {})
+
+ cancelled = False
+ result = None
+ while not cancelled:
+ for event in self.vm.get_qmp_events(wait=True):
+ if event['event'] == 'BLOCK_JOB_COMPLETED' or \
+ event['event'] == 'BLOCK_JOB_CANCELLED':
+ self.assert_qmp(event, 'data/device', drive)
+ result = event
+ cancelled = True
+
+ self.assert_no_active_block_jobs()
+ return result
+
def notrun(reason):
'''Skip this test suite'''
# Each test in qemu-iotests has a number ("seq")