3 # Test case for the QMP 'change' command and all other associated
6 # Copyright (C) 2015 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 from iotests
import qemu_img
28 old_img
= os
.path
.join(iotests
.test_dir
, 'test0.img')
29 new_img
= os
.path
.join(iotests
.test_dir
, 'test1.img')
31 class ChangeBaseClass(iotests
.QMPTestCase
):
35 def process_events(self
):
36 for event
in self
.vm
.get_qmp_events(wait
=False):
37 if (event
['event'] == 'DEVICE_TRAY_MOVED' and
38 event
['data']['device'] == 'drive0'):
39 if event
['data']['tray-open'] == False:
40 self
.has_closed
= True
42 self
.has_opened
= True
44 def wait_for_open(self
):
45 if not self
.has_real_tray
:
48 timeout
= time
.clock() + 3
49 while not self
.has_opened
and time
.clock() < timeout
:
51 if not self
.has_opened
:
52 self
.fail('Timeout while waiting for the tray to open')
54 def wait_for_close(self
):
55 if not self
.has_real_tray
:
58 timeout
= time
.clock() + 3
59 while not self
.has_closed
and time
.clock() < timeout
:
61 if not self
.has_opened
:
62 self
.fail('Timeout while waiting for the tray to close')
64 class GeneralChangeTestsBaseClass(ChangeBaseClass
):
68 def test_change(self
):
69 result
= self
.vm
.qmp('change', device
='drive0', target
=new_img
,
71 self
.assert_qmp(result
, 'return', {})
76 result
= self
.vm
.qmp('query-block')
77 if self
.has_real_tray
:
78 self
.assert_qmp(result
, 'return[0]/tray_open', False)
79 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
81 def test_blockdev_change_medium(self
):
82 if self
.device_name
is not None:
83 result
= self
.vm
.qmp('blockdev-change-medium',
84 id=self
.device_name
, filename
=new_img
,
85 format
=iotests
.imgfmt
)
87 result
= self
.vm
.qmp('blockdev-change-medium',
88 device
='drive0', filename
=new_img
,
89 format
=iotests
.imgfmt
)
91 self
.assert_qmp(result
, 'return', {})
96 result
= self
.vm
.qmp('query-block')
97 if self
.has_real_tray
:
98 self
.assert_qmp(result
, 'return[0]/tray_open', False)
99 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
101 def test_eject(self
):
102 if self
.device_name
is not None:
103 result
= self
.vm
.qmp('eject', id=self
.device_name
, force
=True)
105 result
= self
.vm
.qmp('eject', device
='drive0', force
=True)
106 self
.assert_qmp(result
, 'return', {})
110 result
= self
.vm
.qmp('query-block')
111 if self
.has_real_tray
:
112 self
.assert_qmp(result
, 'return[0]/tray_open', True)
113 self
.assert_qmp_absent(result
, 'return[0]/inserted')
115 def test_tray_eject_change(self
):
116 if self
.device_name
is not None:
117 result
= self
.vm
.qmp('eject', id=self
.device_name
, force
=True)
119 result
= self
.vm
.qmp('eject', device
='drive0', force
=True)
120 self
.assert_qmp(result
, 'return', {})
124 result
= self
.vm
.qmp('query-block')
125 if self
.has_real_tray
:
126 self
.assert_qmp(result
, 'return[0]/tray_open', True)
127 self
.assert_qmp_absent(result
, 'return[0]/inserted')
129 if self
.device_name
is not None:
130 result
= self
.vm
.qmp('blockdev-change-medium', id=self
.device_name
,
131 filename
=new_img
, format
=iotests
.imgfmt
)
133 result
= self
.vm
.qmp('blockdev-change-medium', device
='drive0',
134 filename
=new_img
, format
=iotests
.imgfmt
)
135 self
.assert_qmp(result
, 'return', {})
137 self
.wait_for_close()
139 result
= self
.vm
.qmp('query-block')
140 if self
.has_real_tray
:
141 self
.assert_qmp(result
, 'return[0]/tray_open', False)
142 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
144 def test_tray_open_close(self
):
145 if self
.device_name
is not None:
146 result
= self
.vm
.qmp('blockdev-open-tray',
147 id=self
.device_name
, force
=True)
149 result
= self
.vm
.qmp('blockdev-open-tray',
150 device
='drive0', force
=True)
151 self
.assert_qmp(result
, 'return', {})
155 result
= self
.vm
.qmp('query-block')
156 if self
.has_real_tray
:
157 self
.assert_qmp(result
, 'return[0]/tray_open', True)
158 if self
.was_empty
== True:
159 self
.assert_qmp_absent(result
, 'return[0]/inserted')
161 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
163 if self
.device_name
is not None:
164 result
= self
.vm
.qmp('blockdev-close-tray', id=self
.device_name
)
166 result
= self
.vm
.qmp('blockdev-close-tray', device
='drive0')
167 self
.assert_qmp(result
, 'return', {})
169 if self
.has_real_tray
or not self
.was_empty
:
170 self
.wait_for_close()
172 result
= self
.vm
.qmp('query-block')
173 if self
.has_real_tray
:
174 self
.assert_qmp(result
, 'return[0]/tray_open', False)
175 if self
.was_empty
== True:
176 self
.assert_qmp_absent(result
, 'return[0]/inserted')
178 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
180 def test_tray_eject_close(self
):
181 result
= self
.vm
.qmp('eject', device
='drive0', force
=True)
182 self
.assert_qmp(result
, 'return', {})
186 result
= self
.vm
.qmp('query-block')
187 if self
.has_real_tray
:
188 self
.assert_qmp(result
, 'return[0]/tray_open', True)
189 self
.assert_qmp_absent(result
, 'return[0]/inserted')
191 if self
.device_name
is not None:
192 result
= self
.vm
.qmp('blockdev-close-tray', id=self
.device_name
)
194 result
= self
.vm
.qmp('blockdev-close-tray', device
='drive0')
195 self
.assert_qmp(result
, 'return', {})
197 self
.wait_for_close()
199 result
= self
.vm
.qmp('query-block')
200 if self
.has_real_tray
:
201 self
.assert_qmp(result
, 'return[0]/tray_open', False)
202 self
.assert_qmp_absent(result
, 'return[0]/inserted')
204 def test_tray_open_change(self
):
205 result
= self
.vm
.qmp('blockdev-open-tray', device
='drive0', force
=True)
206 self
.assert_qmp(result
, 'return', {})
210 result
= self
.vm
.qmp('query-block')
211 if self
.has_real_tray
:
212 self
.assert_qmp(result
, 'return[0]/tray_open', True)
213 if self
.was_empty
== True:
214 self
.assert_qmp_absent(result
, 'return[0]/inserted')
216 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
218 result
= self
.vm
.qmp('blockdev-change-medium', device
='drive0',
220 format
=iotests
.imgfmt
)
221 self
.assert_qmp(result
, 'return', {})
223 self
.wait_for_close()
225 result
= self
.vm
.qmp('query-block')
226 if self
.has_real_tray
:
227 self
.assert_qmp(result
, 'return[0]/tray_open', False)
228 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
230 def test_cycle(self
):
231 result
= self
.vm
.qmp('blockdev-add',
233 driver
=iotests
.imgfmt
,
234 file={'filename': new_img
,
236 self
.assert_qmp(result
, 'return', {})
238 if self
.device_name
is not None:
239 result
= self
.vm
.qmp('blockdev-open-tray',
240 id=self
.device_name
, force
=True)
242 result
= self
.vm
.qmp('blockdev-open-tray',
243 device
='drive0', force
=True)
244 self
.assert_qmp(result
, 'return', {})
248 result
= self
.vm
.qmp('query-block')
249 if self
.has_real_tray
:
250 self
.assert_qmp(result
, 'return[0]/tray_open', True)
251 if self
.was_empty
== True:
252 self
.assert_qmp_absent(result
, 'return[0]/inserted')
254 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
256 if self
.device_name
is not None:
257 result
= self
.vm
.qmp('x-blockdev-remove-medium',
260 result
= self
.vm
.qmp('x-blockdev-remove-medium', device
='drive0')
261 self
.assert_qmp(result
, 'return', {})
263 result
= self
.vm
.qmp('query-block')
264 if self
.has_real_tray
:
265 self
.assert_qmp(result
, 'return[0]/tray_open', True)
266 self
.assert_qmp_absent(result
, 'return[0]/inserted')
268 if self
.device_name
is not None:
269 result
= self
.vm
.qmp('x-blockdev-insert-medium',
270 id=self
.device_name
, node_name
='new')
272 result
= self
.vm
.qmp('x-blockdev-insert-medium',
273 device
='drive0', node_name
='new')
274 self
.assert_qmp(result
, 'return', {})
276 result
= self
.vm
.qmp('query-block')
277 if self
.has_real_tray
:
278 self
.assert_qmp(result
, 'return[0]/tray_open', True)
279 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
281 if self
.device_name
is not None:
282 result
= self
.vm
.qmp('blockdev-close-tray', id=self
.device_name
)
284 result
= self
.vm
.qmp('blockdev-close-tray', device
='drive0')
285 self
.assert_qmp(result
, 'return', {})
287 self
.wait_for_close()
289 result
= self
.vm
.qmp('query-block')
290 if self
.has_real_tray
:
291 self
.assert_qmp(result
, 'return[0]/tray_open', False)
292 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
294 def test_close_on_closed(self
):
295 result
= self
.vm
.qmp('blockdev-close-tray', device
='drive0')
297 self
.assert_qmp(result
, 'return', {})
298 self
.assertEquals(self
.vm
.get_qmp_events(wait
=False), [])
300 def test_remove_on_closed(self
):
301 if not self
.has_real_tray
:
304 result
= self
.vm
.qmp('x-blockdev-remove-medium', device
='drive0')
305 self
.assert_qmp(result
, 'error/class', 'GenericError')
307 def test_insert_on_closed(self
):
308 if not self
.has_real_tray
:
311 result
= self
.vm
.qmp('blockdev-add',
313 driver
=iotests
.imgfmt
,
314 file={'filename': new_img
,
316 self
.assert_qmp(result
, 'return', {})
318 result
= self
.vm
.qmp('x-blockdev-insert-medium', device
='drive0',
320 self
.assert_qmp(result
, 'error/class', 'GenericError')
322 class TestInitiallyFilled(GeneralChangeTestsBaseClass
):
325 def setUp(self
, media
, interface
):
326 qemu_img('create', '-f', iotests
.imgfmt
, old_img
, '1440k')
327 qemu_img('create', '-f', iotests
.imgfmt
, new_img
, '1440k')
328 self
.vm
= iotests
.VM()
329 if interface
== 'ide':
330 self
.device_name
= 'qdev0'
331 self
.vm
.add_drive(old_img
, 'media=%s' % media
, 'none')
332 self
.vm
.add_device('ide-cd,drive=drive0,id=%s' % self
.device_name
)
334 self
.vm
.add_drive(old_img
, 'media=%s' % media
, interface
)
342 def test_insert_on_filled(self
):
343 result
= self
.vm
.qmp('blockdev-add',
345 driver
=iotests
.imgfmt
,
346 file={'filename': new_img
,
348 self
.assert_qmp(result
, 'return', {})
350 result
= self
.vm
.qmp('blockdev-open-tray', device
='drive0')
351 self
.assert_qmp(result
, 'return', {})
355 result
= self
.vm
.qmp('x-blockdev-insert-medium', device
='drive0',
357 self
.assert_qmp(result
, 'error/class', 'GenericError')
359 class TestInitiallyEmpty(GeneralChangeTestsBaseClass
):
362 def setUp(self
, media
, interface
):
363 qemu_img('create', '-f', iotests
.imgfmt
, new_img
, '1440k')
364 self
.vm
= iotests
.VM().add_drive(None, 'media=%s' % media
, interface
)
371 def test_remove_on_empty(self
):
372 result
= self
.vm
.qmp('blockdev-open-tray', device
='drive0')
373 self
.assert_qmp(result
, 'return', {})
377 result
= self
.vm
.qmp('x-blockdev-remove-medium', device
='drive0')
379 self
.assert_qmp(result
, 'return', {})
381 class TestCDInitiallyFilled(TestInitiallyFilled
):
382 TestInitiallyFilled
= TestInitiallyFilled
386 self
.TestInitiallyFilled
.setUp(self
, 'cdrom', 'ide')
388 class TestCDInitiallyEmpty(TestInitiallyEmpty
):
389 TestInitiallyEmpty
= TestInitiallyEmpty
393 self
.TestInitiallyEmpty
.setUp(self
, 'cdrom', 'ide')
395 class TestFloppyInitiallyFilled(TestInitiallyFilled
):
396 TestInitiallyFilled
= TestInitiallyFilled
397 has_real_tray
= False
400 self
.TestInitiallyFilled
.setUp(self
, 'disk', 'floppy')
402 class TestFloppyInitiallyEmpty(TestInitiallyEmpty
):
403 TestInitiallyEmpty
= TestInitiallyEmpty
404 has_real_tray
= False
407 self
.TestInitiallyEmpty
.setUp(self
, 'disk', 'floppy')
408 # FDDs not having a real tray and there not being a medium inside the
409 # tray at startup means the tray will be considered open
410 self
.has_opened
= True
412 class TestChangeReadOnly(ChangeBaseClass
):
414 qemu_img('create', '-f', iotests
.imgfmt
, old_img
, '1440k')
415 qemu_img('create', '-f', iotests
.imgfmt
, new_img
, '1440k')
416 self
.vm
= iotests
.VM()
420 os
.chmod(old_img
, 0666)
421 os
.chmod(new_img
, 0666)
425 def test_ro_ro_retain(self
):
426 os
.chmod(old_img
, 0444)
427 os
.chmod(new_img
, 0444)
428 self
.vm
.add_drive(old_img
, 'media=disk,read-only=on', 'floppy')
431 result
= self
.vm
.qmp('query-block')
432 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
433 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
435 result
= self
.vm
.qmp('blockdev-change-medium', device
='drive0',
437 format
=iotests
.imgfmt
,
438 read_only_mode
='retain')
439 self
.assert_qmp(result
, 'return', {})
441 result
= self
.vm
.qmp('query-block')
442 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
443 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
445 def test_ro_rw_retain(self
):
446 os
.chmod(old_img
, 0444)
447 self
.vm
.add_drive(old_img
, 'media=disk,read-only=on', 'floppy')
450 result
= self
.vm
.qmp('query-block')
451 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
452 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
454 result
= self
.vm
.qmp('blockdev-change-medium', device
='drive0',
456 format
=iotests
.imgfmt
,
457 read_only_mode
='retain')
458 self
.assert_qmp(result
, 'return', {})
460 result
= self
.vm
.qmp('query-block')
461 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
462 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
464 def test_rw_ro_retain(self
):
465 os
.chmod(new_img
, 0444)
466 self
.vm
.add_drive(old_img
, 'media=disk', 'floppy')
469 result
= self
.vm
.qmp('query-block')
470 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
471 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
473 result
= self
.vm
.qmp('blockdev-change-medium', device
='drive0',
475 format
=iotests
.imgfmt
,
476 read_only_mode
='retain')
477 self
.assert_qmp(result
, 'error/class', 'GenericError')
479 self
.assertEquals(self
.vm
.get_qmp_events(wait
=False), [])
481 result
= self
.vm
.qmp('query-block')
482 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
483 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
485 def test_ro_rw(self
):
486 os
.chmod(old_img
, 0444)
487 self
.vm
.add_drive(old_img
, 'media=disk,read-only=on', 'floppy')
490 result
= self
.vm
.qmp('query-block')
491 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
492 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
494 result
= self
.vm
.qmp('blockdev-change-medium',
497 format
=iotests
.imgfmt
,
498 read_only_mode
='read-write')
499 self
.assert_qmp(result
, 'return', {})
501 result
= self
.vm
.qmp('query-block')
502 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
503 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
505 def test_rw_ro(self
):
506 os
.chmod(new_img
, 0444)
507 self
.vm
.add_drive(old_img
, 'media=disk', 'floppy')
510 result
= self
.vm
.qmp('query-block')
511 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
512 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
514 result
= self
.vm
.qmp('blockdev-change-medium',
517 format
=iotests
.imgfmt
,
518 read_only_mode
='read-only')
519 self
.assert_qmp(result
, 'return', {})
521 result
= self
.vm
.qmp('query-block')
522 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
523 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
525 def test_make_rw_ro(self
):
526 self
.vm
.add_drive(old_img
, 'media=disk', 'floppy')
529 result
= self
.vm
.qmp('query-block')
530 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
531 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
533 result
= self
.vm
.qmp('blockdev-change-medium',
536 format
=iotests
.imgfmt
,
537 read_only_mode
='read-only')
538 self
.assert_qmp(result
, 'return', {})
540 result
= self
.vm
.qmp('query-block')
541 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
542 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
544 def test_make_ro_rw(self
):
545 os
.chmod(new_img
, 0444)
546 self
.vm
.add_drive(old_img
, 'media=disk', 'floppy')
549 result
= self
.vm
.qmp('query-block')
550 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
551 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
553 result
= self
.vm
.qmp('blockdev-change-medium',
556 format
=iotests
.imgfmt
,
557 read_only_mode
='read-write')
558 self
.assert_qmp(result
, 'error/class', 'GenericError')
560 result
= self
.vm
.qmp('query-block')
561 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
562 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
564 def test_make_rw_ro_by_retain(self
):
565 os
.chmod(old_img
, 0444)
566 self
.vm
.add_drive(old_img
, 'media=disk,read-only=on', 'floppy')
569 result
= self
.vm
.qmp('query-block')
570 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
571 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
573 result
= self
.vm
.qmp('blockdev-change-medium', device
='drive0',
575 format
=iotests
.imgfmt
,
576 read_only_mode
='retain')
577 self
.assert_qmp(result
, 'return', {})
579 result
= self
.vm
.qmp('query-block')
580 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
581 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
583 def test_make_ro_rw_by_retain(self
):
584 os
.chmod(new_img
, 0444)
585 self
.vm
.add_drive(old_img
, 'media=disk', 'floppy')
588 result
= self
.vm
.qmp('query-block')
589 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
590 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
592 result
= self
.vm
.qmp('blockdev-change-medium', device
='drive0',
594 format
=iotests
.imgfmt
,
595 read_only_mode
='retain')
596 self
.assert_qmp(result
, 'error/class', 'GenericError')
598 result
= self
.vm
.qmp('query-block')
599 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
600 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
602 def test_rw_ro_cycle(self
):
603 os
.chmod(new_img
, 0444)
604 self
.vm
.add_drive(old_img
, 'media=disk', 'floppy')
607 result
= self
.vm
.qmp('query-block')
608 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
609 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
611 result
= self
.vm
.qmp('blockdev-add',
613 driver
=iotests
.imgfmt
,
615 file={'filename': new_img
,
617 self
.assert_qmp(result
, 'return', {})
619 result
= self
.vm
.qmp('query-block')
620 self
.assert_qmp(result
, 'return[0]/inserted/ro', False)
621 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
623 result
= self
.vm
.qmp('x-blockdev-remove-medium', device
='drive0')
624 self
.assert_qmp(result
, 'return', {})
626 result
= self
.vm
.qmp('query-block')
627 self
.assert_qmp_absent(result
, 'return[0]/inserted')
629 result
= self
.vm
.qmp('x-blockdev-insert-medium', device
='drive0',
631 self
.assert_qmp(result
, 'return', {})
633 result
= self
.vm
.qmp('query-block')
634 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
635 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
637 result
= self
.vm
.qmp('query-block')
638 self
.assert_qmp(result
, 'return[0]/inserted/ro', True)
639 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
641 GeneralChangeTestsBaseClass
= None
642 TestInitiallyFilled
= None
643 TestInitiallyEmpty
= None
646 class TestBlockJobsAfterCycle(ChangeBaseClass
):
648 qemu_img('create', '-f', iotests
.imgfmt
, old_img
, '1M')
650 self
.vm
= iotests
.VM()
651 self
.vm
.add_drive_raw("id=drive0,driver=null-co,if=none")
654 result
= self
.vm
.qmp('query-block')
655 self
.assert_qmp(result
, 'return[0]/inserted/image/format', 'null-co')
657 # For device-less BBs, calling blockdev-open-tray or blockdev-close-tray
659 result
= self
.vm
.qmp('x-blockdev-remove-medium', device
='drive0')
660 self
.assert_qmp(result
, 'return', {})
662 result
= self
.vm
.qmp('query-block')
663 self
.assert_qmp_absent(result
, 'return[0]/inserted')
665 result
= self
.vm
.qmp('blockdev-add',
667 driver
=iotests
.imgfmt
,
668 file={'filename': old_img
,
670 self
.assert_qmp(result
, 'return', {})
672 result
= self
.vm
.qmp('x-blockdev-insert-medium', device
='drive0',
674 self
.assert_qmp(result
, 'return', {})
676 result
= self
.vm
.qmp('query-block')
677 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', old_img
)
687 def test_snapshot_and_commit(self
):
688 # We need backing file support
689 if iotests
.imgfmt
!= 'qcow2' and iotests
.imgfmt
!= 'qed':
692 result
= self
.vm
.qmp('blockdev-snapshot-sync', device
='drive0',
693 snapshot_file
=new_img
,
694 format
=iotests
.imgfmt
)
695 self
.assert_qmp(result
, 'return', {})
697 result
= self
.vm
.qmp('query-block')
698 self
.assert_qmp(result
, 'return[0]/inserted/image/filename', new_img
)
699 self
.assert_qmp(result
,
700 'return[0]/inserted/image/backing-image/filename',
703 result
= self
.vm
.qmp('block-commit', device
='drive0')
704 self
.assert_qmp(result
, 'return', {})
706 self
.vm
.event_wait(name
='BLOCK_JOB_READY')
708 result
= self
.vm
.qmp('query-block-jobs')
709 self
.assert_qmp(result
, 'return[0]/device', 'drive0')
711 result
= self
.vm
.qmp('block-job-complete', device
='drive0')
712 self
.assert_qmp(result
, 'return', {})
714 self
.vm
.event_wait(name
='BLOCK_JOB_COMPLETED')
717 if __name__
== '__main__':
718 if iotests
.qemu_default_machine
!= 'pc':
719 # We need floppy and IDE CD-ROM
720 iotests
.notrun('not suitable for this machine type: %s' %
721 iotests
.qemu_default_machine
)
722 # Need to support image creation
723 iotests
.main(supported_fmts
=['vpc', 'parallels', 'qcow', 'vdi', 'qcow2',
724 'vmdk', 'raw', 'vhdx', 'qed'])