Skip to content

Commit d445e0a

Browse files
kevmwmdroth
authored andcommitted
qemu-iotests: Test automatic commit job cancel on hot unplug
Signed-off-by: Kevin Wolf <[email protected]> Reviewed-by: John Snow <[email protected]> (cherry picked from commit c3971b8) *prereq for d3c8c67 Signed-off-by: Michael Roth <[email protected]>
1 parent ad480ab commit d445e0a

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

tests/qemu-iotests/040

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class ImageCommitTestCase(iotests.QMPTestCase):
7070
self.wait_for_complete()
7171

7272
class TestSingleDrive(ImageCommitTestCase):
73-
image_len = 1 * 1024 * 1024
73+
# Need some space after the copied data so that throttling is effective in
74+
# tests that use it rather than just completing the job immediately
75+
image_len = 2 * 1024 * 1024
7476
test_len = 1 * 1024 * 256
7577

7678
def setUp(self):
@@ -79,7 +81,9 @@ class TestSingleDrive(ImageCommitTestCase):
7981
qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img)
8082
qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img)
8183
qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img)
82-
self.vm = iotests.VM().add_drive(test_img)
84+
self.vm = iotests.VM().add_drive(test_img, interface="none")
85+
self.vm.add_device("virtio-scsi-pci")
86+
self.vm.add_device("scsi-hd,id=scsi0,drive=drive0")
8387
self.vm.launch()
8488

8589
def tearDown(self):
@@ -131,6 +135,33 @@ class TestSingleDrive(ImageCommitTestCase):
131135
self.assert_qmp(result, 'error/class', 'GenericError')
132136
self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % mid_img)
133137

138+
# When the job is running on a BB that is automatically deleted on hot
139+
# unplug, the job is cancelled when the device disappears
140+
def test_hot_unplug(self):
141+
if self.image_len == 0:
142+
return
143+
144+
self.assert_no_active_block_jobs()
145+
result = self.vm.qmp('block-commit', device='drive0', top=mid_img,
146+
base=backing_img, speed=(self.image_len / 4))
147+
self.assert_qmp(result, 'return', {})
148+
result = self.vm.qmp('device_del', id='scsi0')
149+
self.assert_qmp(result, 'return', {})
150+
151+
cancelled = False
152+
deleted = False
153+
while not cancelled or not deleted:
154+
for event in self.vm.get_qmp_events(wait=True):
155+
if event['event'] == 'DEVICE_DELETED':
156+
self.assert_qmp(event, 'data/device', 'scsi0')
157+
deleted = True
158+
elif event['event'] == 'BLOCK_JOB_CANCELLED':
159+
self.assert_qmp(event, 'data/device', 'drive0')
160+
cancelled = True
161+
else:
162+
self.fail("Unexpected event %s" % (event['event']))
163+
164+
self.assert_no_active_block_jobs()
134165

135166
class TestRelativePaths(ImageCommitTestCase):
136167
image_len = 1 * 1024 * 1024

tests/qemu-iotests/040.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
.........................
1+
...........................
22
----------------------------------------------------------------------
3-
Ran 25 tests
3+
Ran 27 tests
44

55
OK

0 commit comments

Comments
 (0)