2 # group: rw auto backing
4 # Tests for image mirroring.
6 # Copyright (C) 2012 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/>.
27 from iotests import qemu_img, qemu_img_pipe, qemu_io
29 backing_img = os.path.join(iotests.test_dir, 'backing.img')
30 target_backing_img = os.path.join(iotests.test_dir, 'target-backing.img')
31 test_img = os.path.join(iotests.test_dir, 'test.img')
32 target_img = os.path.join(iotests.test_dir, 'target.img')
34 quorum_img1 = os.path.join(iotests.test_dir, 'quorum1.img')
35 quorum_img2 = os.path.join(iotests.test_dir, 'quorum2.img')
36 quorum_img3 = os.path.join(iotests.test_dir, 'quorum3.img')
37 quorum_repair_img = os.path.join(iotests.test_dir, 'quorum_repair.img')
38 quorum_snapshot_file = os.path.join(iotests.test_dir, 'quorum_snapshot.img')
40 nbd_sock_path = os.path.join(iotests.sock_dir, 'nbd.sock')
42 class TestSingleDrive(iotests.QMPTestCase):
43 image_len = 1 * 1024 * 1024 # MB
44 qmp_cmd = 'drive-mirror'
45 qmp_target = target_img
48 iotests.create_image(backing_img, self.image_len)
49 qemu_img('create', '-f', iotests.imgfmt,
50 '-o', 'backing_file=%s' % backing_img, '-F', 'raw', test_img)
51 self.vm = iotests.VM().add_drive(test_img, "node-name=top,backing.node-name=base")
52 if iotests.qemu_default_machine == 'pc':
53 self.vm.add_drive(None, 'media=cdrom', 'ide')
59 os.remove(backing_img)
65 def test_complete(self):
66 self.assert_no_active_block_jobs()
68 result = self.vm.qmp(self.qmp_cmd, device='drive0', sync='full',
69 target=self.qmp_target)
70 self.assert_qmp(result, 'return', {})
72 self.complete_and_wait()
73 result = self.vm.qmp('query-block')
74 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
76 self.assertTrue(iotests.compare_images(test_img, target_img),
77 'target image does not match source after mirroring')
79 def test_cancel(self):
80 self.assert_no_active_block_jobs()
82 result = self.vm.qmp(self.qmp_cmd, device='drive0', sync='full',
83 target=self.qmp_target)
84 self.assert_qmp(result, 'return', {})
86 self.cancel_and_wait(force=True)
87 result = self.vm.qmp('query-block')
88 self.assert_qmp(result, 'return[0]/inserted/file', test_img)
90 def test_cancel_after_ready(self):
91 self.assert_no_active_block_jobs()
93 result = self.vm.qmp(self.qmp_cmd, device='drive0', sync='full',
94 target=self.qmp_target)
95 self.assert_qmp(result, 'return', {})
97 self.wait_ready_and_cancel()
98 result = self.vm.qmp('query-block')
99 self.assert_qmp(result, 'return[0]/inserted/file', test_img)
101 self.assertTrue(iotests.compare_images(test_img, target_img),
102 'target image does not match source after mirroring')
104 def test_pause(self):
105 self.assert_no_active_block_jobs()
107 result = self.vm.qmp(self.qmp_cmd, device='drive0', sync='full',
108 target=self.qmp_target)
109 self.assert_qmp(result, 'return', {})
111 self.pause_job('drive0')
113 result = self.vm.qmp('query-block-jobs')
114 offset = self.dictpath(result, 'return[0]/offset')
117 result = self.vm.qmp('query-block-jobs')
118 self.assert_qmp(result, 'return[0]/offset', offset)
120 result = self.vm.qmp('block-job-resume', device='drive0')
121 self.assert_qmp(result, 'return', {})
123 self.complete_and_wait()
125 self.assertTrue(iotests.compare_images(test_img, target_img),
126 'target image does not match source after mirroring')
128 def test_small_buffer(self):
129 self.assert_no_active_block_jobs()
131 # A small buffer is rounded up automatically
132 result = self.vm.qmp(self.qmp_cmd, device='drive0', sync='full',
133 buf_size=4096, target=self.qmp_target)
134 self.assert_qmp(result, 'return', {})
136 self.complete_and_wait()
137 result = self.vm.qmp('query-block')
138 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
140 self.assertTrue(iotests.compare_images(test_img, target_img),
141 'target image does not match source after mirroring')
143 def test_small_buffer2(self):
144 self.assert_no_active_block_jobs()
146 qemu_img('create', '-f', iotests.imgfmt, '-o', 'cluster_size=%d,size=%d'
147 % (self.image_len, self.image_len), target_img)
148 result = self.vm.qmp(self.qmp_cmd, device='drive0', sync='full',
149 buf_size=65536, mode='existing', target=self.qmp_target)
150 self.assert_qmp(result, 'return', {})
152 self.complete_and_wait()
153 result = self.vm.qmp('query-block')
154 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
156 self.assertTrue(iotests.compare_images(test_img, target_img),
157 'target image does not match source after mirroring')
159 def test_large_cluster(self):
160 self.assert_no_active_block_jobs()
162 qemu_img('create', '-f', iotests.imgfmt, '-o', 'cluster_size=%d,backing_file=%s'
163 % (self.image_len, backing_img),
164 '-F', 'raw', target_img)
165 result = self.vm.qmp(self.qmp_cmd, device='drive0', sync='full',
166 mode='existing', target=self.qmp_target)
167 self.assert_qmp(result, 'return', {})
169 self.complete_and_wait()
170 result = self.vm.qmp('query-block')
171 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
173 self.assertTrue(iotests.compare_images(test_img, target_img),
174 'target image does not match source after mirroring')
176 # Tests that the insertion of the mirror_top filter node doesn't make a
177 # difference to query-block
178 def test_implicit_node(self):
179 self.assert_no_active_block_jobs()
181 result = self.vm.qmp(self.qmp_cmd, device='drive0', sync='full',
182 target=self.qmp_target)
183 self.assert_qmp(result, 'return', {})
185 result = self.vm.qmp('query-block')
186 self.assert_qmp(result, 'return[0]/inserted/file', test_img)
187 self.assert_qmp(result, 'return[0]/inserted/drv', iotests.imgfmt)
188 self.assert_qmp(result, 'return[0]/inserted/backing_file', backing_img)
189 self.assert_qmp(result, 'return[0]/inserted/backing_file_depth', 1)
190 self.assert_qmp(result, 'return[0]/inserted/image/filename', test_img)
191 self.assert_qmp(result, 'return[0]/inserted/image/backing-image/filename', backing_img)
193 result = self.vm.qmp('query-blockstats')
194 self.assert_qmp(result, 'return[0]/node-name', 'top')
195 self.assert_qmp(result, 'return[0]/backing/node-name', 'base')
197 self.cancel_and_wait(force=True)
198 result = self.vm.qmp('query-block')
199 self.assert_qmp(result, 'return[0]/inserted/file', test_img)
200 self.assert_qmp(result, 'return[0]/inserted/drv', iotests.imgfmt)
201 self.assert_qmp(result, 'return[0]/inserted/backing_file', backing_img)
202 self.assert_qmp(result, 'return[0]/inserted/backing_file_depth', 1)
203 self.assert_qmp(result, 'return[0]/inserted/image/filename', test_img)
204 self.assert_qmp(result, 'return[0]/inserted/image/backing-image/filename', backing_img)
206 result = self.vm.qmp('query-blockstats')
207 self.assert_qmp(result, 'return[0]/node-name', 'top')
208 self.assert_qmp(result, 'return[0]/backing/node-name', 'base')
210 def test_medium_not_found(self):
211 if iotests.qemu_default_machine != 'pc':
214 result = self.vm.qmp(self.qmp_cmd, device='ide1-cd0', sync='full',
215 target=self.qmp_target)
216 self.assert_qmp(result, 'error/class', 'GenericError')
218 def test_image_not_found(self):
219 result = self.vm.qmp(self.qmp_cmd, device='drive0', sync='full',
220 mode='existing', target=self.qmp_target)
221 self.assert_qmp(result, 'error/class', 'GenericError')
223 def test_device_not_found(self):
224 result = self.vm.qmp(self.qmp_cmd, device='nonexistent', sync='full',
225 target=self.qmp_target)
226 self.assert_qmp(result, 'error/class', 'GenericError')
228 class TestSingleBlockdev(TestSingleDrive):
229 qmp_cmd = 'blockdev-mirror'
233 TestSingleDrive.setUp(self)
234 qemu_img('create', '-f', iotests.imgfmt,
235 '-o', 'backing_file=%s' % backing_img, '-F', 'raw', target_img)
236 args = {'driver': iotests.imgfmt,
237 'node-name': self.qmp_target,
238 'file': { 'filename': target_img, 'driver': 'file' } }
239 result = self.vm.qmp("blockdev-add", **args)
240 self.assert_qmp(result, 'return', {})
242 def test_mirror_to_self(self):
243 result = self.vm.qmp(self.qmp_cmd, job_id='job0',
244 device=self.qmp_target, sync='full',
245 target=self.qmp_target)
246 self.assert_qmp(result, 'error/class', 'GenericError')
248 def do_test_resize(self, device, node):
251 result = self.vm.qmp('block_resize', device=device, size=65536)
252 self.assert_qmp(result, 'error/class', 'GenericError')
254 result = self.vm.qmp('block_resize', node_name=node, size=65536)
255 self.assert_qmp(result, 'error/class', 'GenericError')
257 result = self.vm.qmp(self.qmp_cmd, job_id='job0', device='drive0',
258 sync='full', target=self.qmp_target,
259 auto_finalize=False, auto_dismiss=False)
260 self.assert_qmp(result, 'return', {})
262 result = self.vm.run_job('job0', auto_finalize=False,
263 pre_finalize=pre_finalize)
264 self.assertEqual(result, None)
266 def test_source_resize(self):
267 self.do_test_resize('drive0', 'top')
269 def test_target_resize(self):
270 self.do_test_resize(None, self.qmp_target)
272 def do_test_target_size(self, size):
273 result = self.vm.qmp('block_resize', node_name=self.qmp_target,
275 self.assert_qmp(result, 'return', {})
277 result = self.vm.qmp(self.qmp_cmd, job_id='job0',
278 device='drive0', sync='full', auto_dismiss=False,
279 target=self.qmp_target)
280 self.assert_qmp(result, 'return', {})
282 result = self.vm.run_job('job0')
283 self.assertEqual(result, 'Source and target image have different sizes')
285 # qed does not support shrinking
286 @iotests.skip_for_formats(('qed'))
287 def test_small_target(self):
288 self.do_test_target_size(self.image_len // 2)
290 def test_large_target(self):
291 self.do_test_target_size(self.image_len * 2)
293 test_large_cluster = None
294 test_image_not_found = None
295 test_small_buffer2 = None
297 class TestSingleDriveZeroLength(TestSingleDrive):
299 test_small_buffer2 = None
300 test_large_cluster = None
302 class TestSingleBlockdevZeroLength(TestSingleBlockdev):
304 test_small_target = None
305 test_large_target = None
307 class TestSingleDriveUnalignedLength(TestSingleDrive):
308 image_len = 1025 * 1024
309 test_small_buffer2 = None
310 test_large_cluster = None
312 class TestSingleBlockdevUnalignedLength(TestSingleBlockdev):
313 image_len = 1025 * 1024
315 class TestMirrorNoBacking(iotests.QMPTestCase):
316 image_len = 2 * 1024 * 1024 # MB
319 iotests.create_image(backing_img, TestMirrorNoBacking.image_len)
320 qemu_img('create', '-f', iotests.imgfmt,
321 '-o', 'backing_file=%s' % backing_img, '-F', 'raw', test_img)
322 self.vm = iotests.VM().add_drive(test_img)
328 os.remove(backing_img)
330 os.remove(target_backing_img)
333 os.remove(target_img)
335 def test_complete(self):
336 self.assert_no_active_block_jobs()
338 qemu_img('create', '-f', iotests.imgfmt,
339 '-o', 'backing_file=%s' % backing_img, '-F', 'raw', target_img)
340 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
341 mode='existing', target=target_img)
342 self.assert_qmp(result, 'return', {})
344 self.complete_and_wait()
345 result = self.vm.qmp('query-block')
346 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
348 self.assertTrue(iotests.compare_images(test_img, target_img),
349 'target image does not match source after mirroring')
351 def test_cancel(self):
352 self.assert_no_active_block_jobs()
354 qemu_img('create', '-f', iotests.imgfmt,
355 '-o', 'backing_file=%s' % backing_img, '-F', 'raw', target_img)
356 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
357 mode='existing', target=target_img)
358 self.assert_qmp(result, 'return', {})
360 self.wait_ready_and_cancel()
361 result = self.vm.qmp('query-block')
362 self.assert_qmp(result, 'return[0]/inserted/file', test_img)
364 self.assertTrue(iotests.compare_images(test_img, target_img),
365 'target image does not match source after mirroring')
367 def test_large_cluster(self):
368 self.assert_no_active_block_jobs()
370 # qemu-img create fails if the image is not there
371 qemu_img('create', '-f', iotests.imgfmt, '-o', 'size=%d'
372 %(TestMirrorNoBacking.image_len), target_backing_img)
373 qemu_img('create', '-f', iotests.imgfmt, '-o', 'cluster_size=%d,backing_file=%s'
374 % (TestMirrorNoBacking.image_len, target_backing_img),
375 '-F', iotests.imgfmt, target_img)
377 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
378 mode='existing', target=target_img)
379 self.assert_qmp(result, 'return', {})
381 self.complete_and_wait()
382 result = self.vm.qmp('query-block')
383 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
385 self.assertTrue(iotests.compare_images(test_img, target_img),
386 'target image does not match source after mirroring')
388 class TestMirrorResized(iotests.QMPTestCase):
389 backing_len = 1 * 1024 * 1024 # MB
390 image_len = 2 * 1024 * 1024 # MB
393 iotests.create_image(backing_img, TestMirrorResized.backing_len)
394 qemu_img('create', '-f', iotests.imgfmt,
395 '-o', 'backing_file=%s' % backing_img, '-F', 'raw', test_img)
396 qemu_img('resize', test_img, '2M')
397 self.vm = iotests.VM().add_drive(test_img)
403 os.remove(backing_img)
405 os.remove(target_img)
409 def test_complete_top(self):
410 self.assert_no_active_block_jobs()
412 result = self.vm.qmp('drive-mirror', device='drive0', sync='top',
414 self.assert_qmp(result, 'return', {})
416 self.complete_and_wait()
417 result = self.vm.qmp('query-block')
418 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
420 self.assertTrue(iotests.compare_images(test_img, target_img),
421 'target image does not match source after mirroring')
423 def test_complete_full(self):
424 self.assert_no_active_block_jobs()
426 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
428 self.assert_qmp(result, 'return', {})
430 self.complete_and_wait()
431 result = self.vm.qmp('query-block')
432 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
434 self.assertTrue(iotests.compare_images(test_img, target_img),
435 'target image does not match source after mirroring')
437 class TestReadErrors(iotests.QMPTestCase):
438 image_len = 2 * 1024 * 1024 # MB
440 # this should be a multiple of twice the default granularity
441 # so that we hit this offset first in state 1
442 MIRROR_GRANULARITY = 1024 * 1024
444 def create_blkdebug_file(self, name, event, errno):
445 file = open(name, 'w')
464 ''' % (event, errno, self.MIRROR_GRANULARITY // 512, event, event))
468 self.blkdebug_file = backing_img + ".blkdebug"
469 iotests.create_image(backing_img, TestReadErrors.image_len)
470 self.create_blkdebug_file(self.blkdebug_file, "read_aio", 5)
471 qemu_img('create', '-f', iotests.imgfmt,
472 '-o', 'backing_file=blkdebug:%s:%s,backing_fmt=raw'
473 % (self.blkdebug_file, backing_img),
475 # Write something for tests that use sync='top'
476 qemu_io('-c', 'write %d 512' % (self.MIRROR_GRANULARITY + 65536),
478 self.vm = iotests.VM().add_drive(test_img)
484 os.remove(target_img)
485 os.remove(backing_img)
486 os.remove(self.blkdebug_file)
488 def test_report_read(self):
489 self.assert_no_active_block_jobs()
491 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
493 self.assert_qmp(result, 'return', {})
498 for event in self.vm.get_qmp_events(wait=True):
499 if event['event'] == 'BLOCK_JOB_ERROR':
500 self.assert_qmp(event, 'data/device', 'drive0')
501 self.assert_qmp(event, 'data/operation', 'read')
503 elif event['event'] == 'BLOCK_JOB_READY':
504 self.assertTrue(False, 'job completed unexpectedly')
505 elif event['event'] == 'BLOCK_JOB_COMPLETED':
506 self.assertTrue(error, 'job completed unexpectedly')
507 self.assert_qmp(event, 'data/type', 'mirror')
508 self.assert_qmp(event, 'data/device', 'drive0')
509 self.assert_qmp(event, 'data/error', 'Input/output error')
511 elif event['event'] == 'JOB_STATUS_CHANGE':
512 self.assert_qmp(event, 'data/id', 'drive0')
514 self.assert_no_active_block_jobs()
516 def test_ignore_read(self):
517 self.assert_no_active_block_jobs()
519 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
520 target=target_img, on_source_error='ignore')
521 self.assert_qmp(result, 'return', {})
523 event = self.vm.get_qmp_event(wait=True)
524 while event['event'] == 'JOB_STATUS_CHANGE':
525 self.assert_qmp(event, 'data/id', 'drive0')
526 event = self.vm.get_qmp_event(wait=True)
528 self.assertEqual(event['event'], 'BLOCK_JOB_ERROR')
529 self.assert_qmp(event, 'data/device', 'drive0')
530 self.assert_qmp(event, 'data/operation', 'read')
531 result = self.vm.qmp('query-block-jobs')
532 self.assert_qmp(result, 'return[0]/paused', False)
533 self.complete_and_wait()
535 def test_large_cluster(self):
536 self.assert_no_active_block_jobs()
538 # Test COW into the target image. The first half of the
539 # cluster at MIRROR_GRANULARITY has to be copied from
540 # backing_img, even though sync='top'.
541 qemu_img('create', '-f', iotests.imgfmt,
542 '-ocluster_size=131072,backing_file=%s' %(backing_img),
543 '-F', 'raw', target_img)
544 result = self.vm.qmp('drive-mirror', device='drive0', sync='top',
545 on_source_error='ignore',
546 mode='existing', target=target_img)
547 self.assert_qmp(result, 'return', {})
549 event = self.vm.get_qmp_event(wait=True)
550 while event['event'] == 'JOB_STATUS_CHANGE':
551 self.assert_qmp(event, 'data/id', 'drive0')
552 event = self.vm.get_qmp_event(wait=True)
554 self.assertEqual(event['event'], 'BLOCK_JOB_ERROR')
555 self.assert_qmp(event, 'data/device', 'drive0')
556 self.assert_qmp(event, 'data/operation', 'read')
557 result = self.vm.qmp('query-block-jobs')
558 self.assert_qmp(result, 'return[0]/paused', False)
559 self.complete_and_wait()
562 # Detach blkdebug to compare images successfully
563 qemu_img('rebase', '-f', iotests.imgfmt, '-u', '-b', backing_img,
564 '-F', 'raw', test_img)
565 self.assertTrue(iotests.compare_images(test_img, target_img),
566 'target image does not match source after mirroring')
568 def test_stop_read(self):
569 self.assert_no_active_block_jobs()
571 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
572 target=target_img, on_source_error='stop')
573 self.assert_qmp(result, 'return', {})
578 for event in self.vm.get_qmp_events(wait=True):
579 if event['event'] == 'BLOCK_JOB_ERROR':
580 self.assert_qmp(event, 'data/device', 'drive0')
581 self.assert_qmp(event, 'data/operation', 'read')
583 result = self.vm.qmp('query-block-jobs')
584 self.assert_qmp(result, 'return[0]/paused', True)
585 self.assert_qmp(result, 'return[0]/io-status', 'failed')
587 result = self.vm.qmp('block-job-resume', device='drive0')
588 self.assert_qmp(result, 'return', {})
590 elif event['event'] == 'BLOCK_JOB_READY':
591 self.assertTrue(error, 'job completed unexpectedly')
592 self.assert_qmp(event, 'data/device', 'drive0')
595 result = self.vm.qmp('query-block-jobs')
596 self.assert_qmp(result, 'return[0]/paused', False)
597 self.assert_qmp(result, 'return[0]/io-status', 'ok')
599 self.complete_and_wait(wait_ready=False)
600 self.assert_no_active_block_jobs()
602 class TestWriteErrors(iotests.QMPTestCase):
603 image_len = 2 * 1024 * 1024 # MB
605 # this should be a multiple of twice the default granularity
606 # so that we hit this offset first in state 1
607 MIRROR_GRANULARITY = 1024 * 1024
609 def create_blkdebug_file(self, name, event, errno):
610 file = open(name, 'w')
629 ''' % (event, errno, self.MIRROR_GRANULARITY // 512, event, event))
633 self.blkdebug_file = target_img + ".blkdebug"
634 iotests.create_image(backing_img, TestWriteErrors.image_len)
635 self.create_blkdebug_file(self.blkdebug_file, "write_aio", 5)
636 qemu_img('create', '-f', iotests.imgfmt,
637 '-obacking_file=%s' %(backing_img), '-F', 'raw', test_img)
638 self.vm = iotests.VM().add_drive(test_img)
639 self.target_img = 'blkdebug:%s:%s' % (self.blkdebug_file, target_img)
640 qemu_img('create', '-f', iotests.imgfmt, '-osize=%d' %(TestWriteErrors.image_len), target_img)
646 os.remove(target_img)
647 os.remove(backing_img)
648 os.remove(self.blkdebug_file)
650 def test_report_write(self):
651 self.assert_no_active_block_jobs()
653 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
654 mode='existing', target=self.target_img)
655 self.assert_qmp(result, 'return', {})
660 for event in self.vm.get_qmp_events(wait=True):
661 if event['event'] == 'BLOCK_JOB_ERROR':
662 self.assert_qmp(event, 'data/device', 'drive0')
663 self.assert_qmp(event, 'data/operation', 'write')
665 elif event['event'] == 'BLOCK_JOB_READY':
666 self.assertTrue(False, 'job completed unexpectedly')
667 elif event['event'] == 'BLOCK_JOB_COMPLETED':
668 self.assertTrue(error, 'job completed unexpectedly')
669 self.assert_qmp(event, 'data/type', 'mirror')
670 self.assert_qmp(event, 'data/device', 'drive0')
671 self.assert_qmp(event, 'data/error', 'Input/output error')
674 self.assert_no_active_block_jobs()
676 def test_ignore_write(self):
677 self.assert_no_active_block_jobs()
679 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
680 mode='existing', target=self.target_img,
681 on_target_error='ignore')
682 self.assert_qmp(result, 'return', {})
684 event = self.vm.event_wait(name='BLOCK_JOB_ERROR')
685 self.assertEqual(event['event'], 'BLOCK_JOB_ERROR')
686 self.assert_qmp(event, 'data/device', 'drive0')
687 self.assert_qmp(event, 'data/operation', 'write')
688 result = self.vm.qmp('query-block-jobs')
689 self.assert_qmp(result, 'return[0]/paused', False)
690 self.complete_and_wait()
692 def test_stop_write(self):
693 self.assert_no_active_block_jobs()
695 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
696 mode='existing', target=self.target_img,
697 on_target_error='stop')
698 self.assert_qmp(result, 'return', {})
703 for event in self.vm.get_qmp_events(wait=True):
704 if event['event'] == 'BLOCK_JOB_ERROR':
705 self.assert_qmp(event, 'data/device', 'drive0')
706 self.assert_qmp(event, 'data/operation', 'write')
708 result = self.vm.qmp('query-block-jobs')
709 self.assert_qmp(result, 'return[0]/paused', True)
710 self.assert_qmp(result, 'return[0]/io-status', 'failed')
712 result = self.vm.qmp('block-job-resume', device='drive0')
713 self.assert_qmp(result, 'return', {})
715 result = self.vm.qmp('query-block-jobs')
716 self.assert_qmp(result, 'return[0]/paused', False)
717 self.assert_qmp(result, 'return[0]/io-status', 'ok')
719 elif event['event'] == 'BLOCK_JOB_READY':
720 self.assertTrue(error, 'job completed unexpectedly')
721 self.assert_qmp(event, 'data/device', 'drive0')
724 self.complete_and_wait(wait_ready=False)
725 self.assert_no_active_block_jobs()
727 class TestSetSpeed(iotests.QMPTestCase):
728 image_len = 80 * 1024 * 1024 # MB
731 qemu_img('create', backing_img, str(TestSetSpeed.image_len))
732 qemu_img('create', '-f', iotests.imgfmt,
733 '-o', 'backing_file=%s' % backing_img, '-F', 'raw', test_img)
734 self.vm = iotests.VM().add_drive(test_img)
740 os.remove(backing_img)
741 os.remove(target_img)
743 def test_set_speed(self):
744 self.assert_no_active_block_jobs()
746 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
748 self.assert_qmp(result, 'return', {})
751 result = self.vm.qmp('query-block-jobs')
752 self.assert_qmp(result, 'return[0]/device', 'drive0')
753 self.assert_qmp(result, 'return[0]/speed', 0)
755 result = self.vm.qmp('block-job-set-speed', device='drive0', speed=8 * 1024 * 1024)
756 self.assert_qmp(result, 'return', {})
758 # Ensure the speed we set was accepted
759 result = self.vm.qmp('query-block-jobs')
760 self.assert_qmp(result, 'return[0]/device', 'drive0')
761 self.assert_qmp(result, 'return[0]/speed', 8 * 1024 * 1024)
763 self.wait_ready_and_cancel()
765 # Check setting speed in drive-mirror works
766 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
767 target=target_img, speed=4*1024*1024)
768 self.assert_qmp(result, 'return', {})
770 result = self.vm.qmp('query-block-jobs')
771 self.assert_qmp(result, 'return[0]/device', 'drive0')
772 self.assert_qmp(result, 'return[0]/speed', 4 * 1024 * 1024)
774 self.wait_ready_and_cancel()
776 def test_set_speed_invalid(self):
777 self.assert_no_active_block_jobs()
779 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
780 target=target_img, speed=-1)
781 self.assert_qmp(result, 'error/class', 'GenericError')
783 self.assert_no_active_block_jobs()
785 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
787 self.assert_qmp(result, 'return', {})
789 result = self.vm.qmp('block-job-set-speed', device='drive0', speed=-1)
790 self.assert_qmp(result, 'error/class', 'GenericError')
792 self.wait_ready_and_cancel()
794 class TestUnbackedSource(iotests.QMPTestCase):
795 image_len = 2 * 1024 * 1024 # MB
798 qemu_img('create', '-f', iotests.imgfmt, test_img,
799 str(TestUnbackedSource.image_len))
800 self.vm = iotests.VM()
802 result = self.vm.qmp('blockdev-add', node_name='drive0',
803 driver=iotests.imgfmt,
806 'filename': test_img,
808 self.assert_qmp(result, 'return', {})
813 os.remove(target_img)
815 def test_absolute_paths_full(self):
816 self.assert_no_active_block_jobs()
817 result = self.vm.qmp('drive-mirror', job_id='drive0', device='drive0',
818 sync='full', target=target_img,
819 mode='absolute-paths')
820 self.assert_qmp(result, 'return', {})
821 self.complete_and_wait()
822 self.assert_no_active_block_jobs()
824 def test_absolute_paths_top(self):
825 self.assert_no_active_block_jobs()
826 result = self.vm.qmp('drive-mirror', job_id='drive0', device='drive0',
827 sync='top', target=target_img,
828 mode='absolute-paths')
829 self.assert_qmp(result, 'return', {})
830 self.complete_and_wait()
831 self.assert_no_active_block_jobs()
833 def test_absolute_paths_none(self):
834 self.assert_no_active_block_jobs()
835 result = self.vm.qmp('drive-mirror', job_id='drive0', device='drive0',
836 sync='none', target=target_img,
837 mode='absolute-paths')
838 self.assert_qmp(result, 'return', {})
839 self.complete_and_wait()
840 self.assert_no_active_block_jobs()
842 def test_existing_full(self):
843 qemu_img('create', '-f', iotests.imgfmt, target_img,
845 qemu_io('-c', 'write -P 42 0 64k', target_img)
847 self.assert_no_active_block_jobs()
848 result = self.vm.qmp('drive-mirror', job_id='drive0', device='drive0',
849 sync='full', target=target_img, mode='existing')
850 self.assert_qmp(result, 'return', {})
851 self.complete_and_wait()
852 self.assert_no_active_block_jobs()
854 result = self.vm.qmp('blockdev-del', node_name='drive0')
855 self.assert_qmp(result, 'return', {})
857 self.assertTrue(iotests.compare_images(test_img, target_img),
858 'target image does not match source after mirroring')
860 def test_blockdev_full(self):
861 qemu_img('create', '-f', iotests.imgfmt, target_img,
863 qemu_io('-c', 'write -P 42 0 64k', target_img)
865 result = self.vm.qmp('blockdev-add', node_name='target',
866 driver=iotests.imgfmt,
869 'filename': target_img,
871 self.assert_qmp(result, 'return', {})
873 self.assert_no_active_block_jobs()
874 result = self.vm.qmp('blockdev-mirror', job_id='drive0', device='drive0',
875 sync='full', target='target')
876 self.assert_qmp(result, 'return', {})
877 self.complete_and_wait()
878 self.assert_no_active_block_jobs()
880 result = self.vm.qmp('blockdev-del', node_name='drive0')
881 self.assert_qmp(result, 'return', {})
883 result = self.vm.qmp('blockdev-del', node_name='target')
884 self.assert_qmp(result, 'return', {})
886 self.assertTrue(iotests.compare_images(test_img, target_img),
887 'target image does not match source after mirroring')
889 class TestGranularity(iotests.QMPTestCase):
890 image_len = 10 * 1024 * 1024 # MB
893 qemu_img('create', '-f', iotests.imgfmt, test_img,
894 str(TestGranularity.image_len))
895 qemu_io('-c', 'write 0 %d' % (self.image_len),
897 self.vm = iotests.VM().add_drive(test_img)
902 self.assertTrue(iotests.compare_images(test_img, target_img),
903 'target image does not match source after mirroring')
905 os.remove(target_img)
907 def test_granularity(self):
908 self.assert_no_active_block_jobs()
909 result = self.vm.qmp('drive-mirror', device='drive0',
910 sync='full', target=target_img,
911 mode='absolute-paths', granularity=8192)
912 self.assert_qmp(result, 'return', {})
914 event = self.vm.get_qmp_event(wait=60.0)
915 while event['event'] == 'JOB_STATUS_CHANGE':
916 self.assert_qmp(event, 'data/id', 'drive0')
917 event = self.vm.get_qmp_event(wait=60.0)
919 # Failures will manifest as COMPLETED/ERROR.
920 self.assert_qmp(event, 'event', 'BLOCK_JOB_READY')
921 self.complete_and_wait(drive='drive0', wait_ready=False)
922 self.assert_no_active_block_jobs()
924 class TestRepairQuorum(iotests.QMPTestCase):
925 """ This class test quorum file repair using drive-mirror.
926 It's mostly a fork of TestSingleDrive """
927 image_len = 1 * 1024 * 1024 # MB
928 IMAGES = [ quorum_img1, quorum_img2, quorum_img3 ]
930 @iotests.skip_if_unsupported(['quorum'])
932 self.vm = iotests.VM()
934 if iotests.qemu_default_machine == 'pc':
935 self.vm.add_drive(None, 'media=cdrom', 'ide')
937 # Add each individual quorum images
938 for i in self.IMAGES:
939 qemu_img('create', '-f', iotests.imgfmt, i,
941 # Assign a node name to each quorum image in order to manipulate
943 opts = "node-name=img%i" % self.IMAGES.index(i)
944 opts += ',driver=%s' % iotests.imgfmt
945 opts += ',file.driver=file'
946 opts += ',file.filename=%s' % i
947 self.vm = self.vm.add_blockdev(opts)
951 #assemble the quorum block device from the individual files
952 args = { "driver": "quorum", "node-name": "quorum0",
953 "vote-threshold": 2, "children": [ "img0", "img1", "img2" ] }
954 result = self.vm.qmp("blockdev-add", **args)
955 self.assert_qmp(result, 'return', {})
960 for i in self.IMAGES + [ quorum_repair_img, quorum_snapshot_file,
962 # Do a try/except because the test may have deleted some images
968 def test_complete(self):
969 result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0',
970 sync='full', node_name="repair0", replaces="img1",
971 target=quorum_repair_img, format=iotests.imgfmt)
972 self.assert_qmp(result, 'return', {})
974 self.complete_and_wait(drive="job0")
975 self.assert_has_block_node("repair0", quorum_repair_img)
976 self.vm.assert_block_path('quorum0', '/children.1', 'repair0')
978 self.assertTrue(iotests.compare_images(quorum_img2, quorum_repair_img),
979 'target image does not match source after mirroring')
981 def test_cancel(self):
982 result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0',
983 sync='full', node_name="repair0", replaces="img1",
984 target=quorum_repair_img, format=iotests.imgfmt)
985 self.assert_qmp(result, 'return', {})
987 self.cancel_and_wait(drive="job0", force=True)
988 # here we check that the last registered quorum file has not been
989 # swapped out and unref
990 self.assert_has_block_node(None, quorum_img3)
992 def test_cancel_after_ready(self):
993 result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0',
994 sync='full', node_name="repair0", replaces="img1",
995 target=quorum_repair_img, format=iotests.imgfmt)
996 self.assert_qmp(result, 'return', {})
998 self.wait_ready_and_cancel(drive="job0")
999 # here we check that the last registered quorum file has not been
1000 # swapped out and unref
1001 self.assert_has_block_node(None, quorum_img3)
1003 self.assertTrue(iotests.compare_images(quorum_img2, quorum_repair_img),
1004 'target image does not match source after mirroring')
1006 def test_pause(self):
1007 result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0',
1008 sync='full', node_name="repair0", replaces="img1",
1009 target=quorum_repair_img, format=iotests.imgfmt)
1010 self.assert_qmp(result, 'return', {})
1012 self.pause_job('job0')
1014 result = self.vm.qmp('query-block-jobs')
1015 offset = self.dictpath(result, 'return[0]/offset')
1018 result = self.vm.qmp('query-block-jobs')
1019 self.assert_qmp(result, 'return[0]/offset', offset)
1021 result = self.vm.qmp('block-job-resume', device='job0')
1022 self.assert_qmp(result, 'return', {})
1024 self.complete_and_wait(drive="job0")
1026 self.assertTrue(iotests.compare_images(quorum_img2, quorum_repair_img),
1027 'target image does not match source after mirroring')
1029 def test_medium_not_found(self):
1030 if iotests.qemu_default_machine != 'pc':
1033 result = self.vm.qmp('drive-mirror', job_id='job0', device='drive0', # CD-ROM
1035 node_name='repair0',
1037 target=quorum_repair_img, format=iotests.imgfmt)
1038 self.assert_qmp(result, 'error/class', 'GenericError')
1040 def test_image_not_found(self):
1041 result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0',
1042 sync='full', node_name='repair0', replaces='img1',
1043 mode='existing', target=quorum_repair_img,
1044 format=iotests.imgfmt)
1045 self.assert_qmp(result, 'error/class', 'GenericError')
1047 def test_device_not_found(self):
1048 result = self.vm.qmp('drive-mirror', job_id='job0',
1049 device='nonexistent', sync='full',
1050 node_name='repair0',
1052 target=quorum_repair_img, format=iotests.imgfmt)
1053 self.assert_qmp(result, 'error/class', 'GenericError')
1055 def test_wrong_sync_mode(self):
1056 result = self.vm.qmp('drive-mirror', device='quorum0', job_id='job0',
1057 node_name='repair0',
1059 target=quorum_repair_img, format=iotests.imgfmt)
1060 self.assert_qmp(result, 'error/class', 'GenericError')
1062 def test_no_node_name(self):
1063 result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0',
1064 sync='full', replaces='img1',
1065 target=quorum_repair_img, format=iotests.imgfmt)
1066 self.assert_qmp(result, 'error/class', 'GenericError')
1068 def test_nonexistent_replaces(self):
1069 result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0',
1070 sync='full', node_name='repair0', replaces='img77',
1071 target=quorum_repair_img, format=iotests.imgfmt)
1072 self.assert_qmp(result, 'error/class', 'GenericError')
1074 def test_after_a_quorum_snapshot(self):
1075 result = self.vm.qmp('blockdev-snapshot-sync', node_name='img1',
1076 snapshot_file=quorum_snapshot_file,
1077 snapshot_node_name="snap1");
1079 result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0',
1080 sync='full', node_name='repair0', replaces="img1",
1081 target=quorum_repair_img, format=iotests.imgfmt)
1082 self.assert_qmp(result, 'error/class', 'GenericError')
1084 result = self.vm.qmp('drive-mirror', job_id='job0', device='quorum0',
1085 sync='full', node_name='repair0', replaces="snap1",
1086 target=quorum_repair_img, format=iotests.imgfmt)
1087 self.assert_qmp(result, 'return', {})
1089 self.complete_and_wait('job0')
1090 self.assert_has_block_node("repair0", quorum_repair_img)
1091 self.vm.assert_block_path('quorum0', '/children.1', 'repair0')
1093 def test_with_other_parent(self):
1095 Check that we cannot replace a Quorum child when it has other
1098 result = self.vm.qmp('nbd-server-start',
1101 'data': {'path': nbd_sock_path}
1103 self.assert_qmp(result, 'return', {})
1105 result = self.vm.qmp('nbd-server-add', device='img1')
1106 self.assert_qmp(result, 'return', {})
1108 result = self.vm.qmp('drive-mirror', job_id='mirror', device='quorum0',
1109 sync='full', node_name='repair0', replaces='img1',
1110 target=quorum_repair_img, format=iotests.imgfmt)
1111 self.assert_qmp(result, 'error/desc',
1112 "Cannot replace 'img1' by a node mirrored from "
1113 "'quorum0', because it cannot be guaranteed that doing "
1114 "so would not lead to an abrupt change of visible data")
1116 def test_with_other_parents_after_mirror_start(self):
1118 The same as test_with_other_parent(), but add the NBD server
1119 only when the mirror job is already running.
1121 result = self.vm.qmp('nbd-server-start',
1124 'data': {'path': nbd_sock_path}
1126 self.assert_qmp(result, 'return', {})
1128 result = self.vm.qmp('drive-mirror', job_id='mirror', device='quorum0',
1129 sync='full', node_name='repair0', replaces='img1',
1130 target=quorum_repair_img, format=iotests.imgfmt)
1131 self.assert_qmp(result, 'return', {})
1133 result = self.vm.qmp('nbd-server-add', device='img1')
1134 self.assert_qmp(result, 'return', {})
1136 # The full error message goes to stderr, we will check it later
1137 self.complete_and_wait('mirror',
1138 completion_error='Operation not permitted')
1140 # Should not have been replaced
1141 self.vm.assert_block_path('quorum0', '/children.1', 'img1')
1143 # Check the full error message now
1145 log = self.vm.get_log()
1146 log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log)
1147 log = re.sub(r'^Formatting.*\n', '', log)
1148 log = re.sub(r'\n\[I \+\d+\.\d+\] CLOSED\n?$', '', log)
1149 log = re.sub(r'^%s: ' % os.path.basename(iotests.qemu_prog), '', log)
1151 self.assertEqual(log,
1152 "Can no longer replace 'img1' by 'repair0', because " +
1153 "it can no longer be guaranteed that doing so would " +
1154 "not lead to an abrupt change of visible data")
1157 # Test mirroring with a source that does not have any parents (not even a
1159 class TestOrphanedSource(iotests.QMPTestCase):
1161 blk0 = { 'node-name': 'src',
1162 'driver': 'null-co' }
1164 blk1 = { 'node-name': 'dest',
1165 'driver': 'null-co' }
1167 blk2 = { 'node-name': 'dest-ro',
1168 'driver': 'null-co',
1171 self.vm = iotests.VM()
1172 self.vm.add_blockdev(self.vm.qmp_to_opts(blk0))
1173 self.vm.add_blockdev(self.vm.qmp_to_opts(blk1))
1174 self.vm.add_blockdev(self.vm.qmp_to_opts(blk2))
1180 def test_no_job_id(self):
1181 self.assert_no_active_block_jobs()
1183 result = self.vm.qmp('blockdev-mirror', device='src', sync='full',
1185 self.assert_qmp(result, 'error/class', 'GenericError')
1187 def test_success(self):
1188 self.assert_no_active_block_jobs()
1190 result = self.vm.qmp('blockdev-mirror', job_id='job', device='src',
1191 sync='full', target='dest')
1192 self.assert_qmp(result, 'return', {})
1194 self.complete_and_wait('job')
1196 def test_failing_permissions(self):
1197 self.assert_no_active_block_jobs()
1199 result = self.vm.qmp('blockdev-mirror', device='src', sync='full',
1201 self.assert_qmp(result, 'error/class', 'GenericError')
1203 def test_failing_permission_in_complete(self):
1204 self.assert_no_active_block_jobs()
1206 # Unshare consistent-read on the target
1207 # (The mirror job does not care)
1208 result = self.vm.qmp('blockdev-add',
1210 node_name='dest-perm',
1212 unshare_child_perms=['consistent-read'])
1213 self.assert_qmp(result, 'return', {})
1215 result = self.vm.qmp('blockdev-mirror', job_id='job', device='src',
1216 sync='full', target='dest',
1217 filter_node_name='mirror-filter')
1218 self.assert_qmp(result, 'return', {})
1220 # Require consistent-read on the source
1221 # (We can only add this node once the job has started, or it
1222 # will complain that it does not want to run on non-root nodes)
1223 result = self.vm.qmp('blockdev-add',
1225 node_name='src-perm',
1227 take_child_perms=['consistent-read'])
1228 self.assert_qmp(result, 'return', {})
1230 # While completing, mirror will attempt to replace src by
1231 # dest, which must fail because src-perm requires
1232 # consistent-read but dest-perm does not share it; thus
1233 # aborting the job when it is supposed to complete
1234 self.complete_and_wait('job',
1235 completion_error='Operation not permitted')
1237 # Assert that all of our nodes are still there (except for the
1238 # mirror filter, which should be gone despite the failure)
1239 nodes = self.vm.qmp('query-named-block-nodes')['return']
1240 nodes = [node['node-name'] for node in nodes]
1242 for expect in ('src', 'src-perm', 'dest', 'dest-perm'):
1243 self.assertTrue(expect in nodes, '%s disappeared' % expect)
1244 self.assertFalse('mirror-filter' in nodes,
1245 'Mirror filter node did not disappear')
1247 # Test cases for @replaces that do not necessarily involve Quorum
1248 class TestReplaces(iotests.QMPTestCase):
1249 # Each of these test cases needs their own block graph, so do not
1250 # create any nodes here
1252 self.vm = iotests.VM()
1257 for img in (test_img, target_img):
1263 @iotests.skip_if_unsupported(['copy-on-read'])
1264 def test_replace_filter(self):
1266 Check that we can replace filter nodes.
1268 result = self.vm.qmp('blockdev-add', **{
1269 'driver': 'copy-on-read',
1270 'node-name': 'filter0',
1272 'driver': 'copy-on-read',
1273 'node-name': 'filter1',
1279 self.assert_qmp(result, 'return', {})
1281 result = self.vm.qmp('blockdev-add',
1282 node_name='target', driver='null-co')
1283 self.assert_qmp(result, 'return', {})
1285 result = self.vm.qmp('blockdev-mirror', job_id='mirror', device='filter0',
1286 target='target', sync='full', replaces='filter1')
1287 self.assert_qmp(result, 'return', {})
1289 self.complete_and_wait('mirror')
1291 self.vm.assert_block_path('filter0', '/file', 'target')
1293 # Tests for mirror with filters (and how the mirror filter behaves, as
1294 # an example for an implicit filter)
1295 class TestFilters(iotests.QMPTestCase):
1297 qemu_img('create', '-f', iotests.imgfmt, backing_img, '1M')
1298 qemu_img('create', '-f', iotests.imgfmt, '-b', backing_img,
1299 '-F', iotests.imgfmt, test_img)
1300 qemu_img('create', '-f', iotests.imgfmt, '-b', backing_img,
1301 '-F', iotests.imgfmt, target_img)
1303 qemu_io('-c', 'write -P 1 0 512k', backing_img)
1304 qemu_io('-c', 'write -P 2 512k 512k', test_img)
1306 self.vm = iotests.VM().add_device('virtio-scsi,id=vio-scsi')
1309 result = self.vm.qmp('blockdev-add', **{
1310 'node-name': 'target',
1311 'driver': iotests.imgfmt,
1314 'filename': target_img
1318 self.assert_qmp(result, 'return', {})
1320 self.filterless_chain = {
1321 'node-name': 'source',
1322 'driver': iotests.imgfmt,
1325 'filename': test_img
1328 'node-name': 'backing',
1329 'driver': iotests.imgfmt,
1332 'filename': backing_img
1341 os.remove(target_img)
1342 os.remove(backing_img)
1345 result = self.vm.qmp('blockdev-add', **{
1346 'node-name': 'filter',
1347 'driver': 'copy-on-read',
1348 'file': self.filterless_chain
1350 self.assert_qmp(result, 'return', {})
1352 result = self.vm.qmp('blockdev-mirror',
1357 self.assert_qmp(result, 'return', {})
1359 self.complete_and_wait('mirror')
1361 self.vm.qmp('blockdev-del', node_name='target')
1363 target_map = qemu_img_pipe('map', '--output=json', target_img)
1364 target_map = json.loads(target_map)
1366 assert target_map[0]['start'] == 0
1367 assert target_map[0]['length'] == 512 * 1024
1368 assert target_map[0]['depth'] == 1
1370 assert target_map[1]['start'] == 512 * 1024
1371 assert target_map[1]['length'] == 512 * 1024
1372 assert target_map[1]['depth'] == 0
1374 def test_implicit_mirror_filter(self):
1375 result = self.vm.qmp('blockdev-add', **self.filterless_chain)
1376 self.assert_qmp(result, 'return', {})
1378 # We need this so we can query from above the mirror node
1379 result = self.vm.qmp('device_add',
1384 self.assert_qmp(result, 'return', {})
1386 result = self.vm.qmp('blockdev-mirror',
1391 self.assert_qmp(result, 'return', {})
1393 # The mirror filter is now an implicit node, so it should be
1394 # invisible when querying the backing chain
1395 blockdevs = self.vm.qmp('query-block')['return']
1396 device_info = next(dev for dev in blockdevs if dev['qdev'] == 'virtio')
1398 assert device_info['inserted']['node-name'] == 'source'
1400 image_info = device_info['inserted']['image']
1401 assert image_info['filename'] == test_img
1402 assert image_info['backing-image']['filename'] == backing_img
1404 self.complete_and_wait('mirror')
1406 def test_explicit_mirror_filter(self):
1407 # Same test as above, but this time we give the mirror filter
1408 # a node-name so it will not be invisible
1409 result = self.vm.qmp('blockdev-add', **self.filterless_chain)
1410 self.assert_qmp(result, 'return', {})
1412 # We need this so we can query from above the mirror node
1413 result = self.vm.qmp('device_add',
1418 self.assert_qmp(result, 'return', {})
1420 result = self.vm.qmp('blockdev-mirror',
1425 filter_node_name='mirror-filter')
1426 self.assert_qmp(result, 'return', {})
1428 # With a node-name given to it, the mirror filter should now
1430 blockdevs = self.vm.qmp('query-block')['return']
1431 device_info = next(dev for dev in blockdevs if dev['qdev'] == 'virtio')
1433 assert device_info['inserted']['node-name'] == 'mirror-filter'
1435 self.complete_and_wait('mirror')
1438 if __name__ == '__main__':
1439 iotests.main(supported_fmts=['qcow2', 'qed'],
1440 supported_protocols=['file'],
1441 supported_platforms=['linux', 'freebsd', 'netbsd', 'openbsd'])