Skip to content

Commit

Permalink
qemu-iotests: extract wait_until_completed() into iotests.py
Browse files Browse the repository at this point in the history
The 'drive-mirror' tests often issue 'block-job-complete' and wait for
the QMP completion event.  Other types of block jobs also want to wait
for completion but they may not need to issue 'block-job-complete'.

Extract wait_until_completed() from 041 and put it into iotests.py.
Return the QMP event object so the caller can make additional
assertions, if necessary.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
stefanhaRH authored and kevmw committed Jun 28, 2013
1 parent 78b18b7 commit 0dbe8a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
14 changes: 2 additions & 12 deletions tests/qemu-iotests/041
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,8 @@ class ImageMirroringTestCase(iotests.QMPTestCase):
result = self.vm.qmp('block-job-complete', device=drive)
self.assert_qmp(result, 'return', {})

completed = False
while not completed:
for event in self.vm.get_qmp_events(wait=True):
if event['event'] == 'BLOCK_JOB_COMPLETED':
self.assert_qmp(event, 'data/type', 'mirror')
self.assert_qmp(event, 'data/device', drive)
self.assert_qmp_absent(event, 'data/error')
self.assert_qmp(event, 'data/offset', self.image_len)
self.assert_qmp(event, 'data/len', self.image_len)
completed = True

self.assert_no_active_block_jobs()
event = self.wait_until_completed()
self.assert_qmp(event, 'data/type', 'mirror')

class TestSingleDrive(ImageMirroringTestCase):
image_len = 1 * 1024 * 1024 # MB
Expand Down
15 changes: 15 additions & 0 deletions tests/qemu-iotests/iotests.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,21 @@ def cancel_and_wait(self, drive='drive0', force=False):
self.assert_no_active_block_jobs()
return result

def wait_until_completed(self, drive='drive0'):
'''Wait for a block job to finish, returning the event'''
completed = False
while not completed:
for event in self.vm.get_qmp_events(wait=True):
if event['event'] == 'BLOCK_JOB_COMPLETED':
self.assert_qmp(event, 'data/device', drive)
self.assert_qmp_absent(event, 'data/error')
self.assert_qmp(event, 'data/offset', self.image_len)
self.assert_qmp(event, 'data/len', self.image_len)
completed = True

self.assert_no_active_block_jobs()
return event

def notrun(reason):
'''Skip this test suite'''
# Each test in qemu-iotests has a number ("seq")
Expand Down

0 comments on commit 0dbe8a1

Please sign in to comment.