xref: /qemu/tests/qemu-iotests/262 (revision 95988739)
17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick migration
35b96e6a0SKevin Wolf#
45b96e6a0SKevin Wolf# Copyright (C) 2019 Red Hat, Inc.
55b96e6a0SKevin Wolf#
65b96e6a0SKevin Wolf# This program is free software; you can redistribute it and/or modify
75b96e6a0SKevin Wolf# it under the terms of the GNU General Public License as published by
85b96e6a0SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
95b96e6a0SKevin Wolf# (at your option) any later version.
105b96e6a0SKevin Wolf#
115b96e6a0SKevin Wolf# This program is distributed in the hope that it will be useful,
125b96e6a0SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
135b96e6a0SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
145b96e6a0SKevin Wolf# GNU General Public License for more details.
155b96e6a0SKevin Wolf#
165b96e6a0SKevin Wolf# You should have received a copy of the GNU General Public License
175b96e6a0SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
185b96e6a0SKevin Wolf#
195b96e6a0SKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
205b96e6a0SKevin Wolf#
215b96e6a0SKevin Wolf# Test migration with filter drivers present. Keep everything in an
225b96e6a0SKevin Wolf# iothread just for fun.
235b96e6a0SKevin Wolf
245b96e6a0SKevin Wolfimport iotests
255b96e6a0SKevin Wolfimport os
265b96e6a0SKevin Wolf
277d814059SJohn Snowiotests.script_initialize(supported_fmts=['qcow2'],
2895988739SThomas Huth                          supported_platforms=['linux'],
2995988739SThomas Huth                          required_fmts=['blkverify'])
305b96e6a0SKevin Wolf
315b96e6a0SKevin Wolfwith iotests.FilePath('img') as img_path, \
325b96e6a0SKevin Wolf     iotests.FilePath('mig_fifo') as fifo, \
335b96e6a0SKevin Wolf     iotests.VM(path_suffix='a') as vm_a, \
345b96e6a0SKevin Wolf     iotests.VM(path_suffix='b') as vm_b:
355b96e6a0SKevin Wolf
365b96e6a0SKevin Wolf    def add_opts(vm):
375b96e6a0SKevin Wolf        vm.add_object('iothread,id=iothread0')
385b96e6a0SKevin Wolf        vm.add_object('throttle-group,id=tg0,x-bps-total=65536')
395b96e6a0SKevin Wolf        vm.add_blockdev('file,filename=%s,node-name=drive0-file' % (img_path))
405b96e6a0SKevin Wolf        vm.add_blockdev('%s,file=drive0-file,node-name=drive0-fmt' % (iotests.imgfmt))
415b96e6a0SKevin Wolf        vm.add_blockdev('copy-on-read,file=drive0-fmt,node-name=drive0-cor')
425b96e6a0SKevin Wolf        vm.add_blockdev('throttle,file=drive0-cor,node-name=drive0-throttle,throttle-group=tg0')
435b96e6a0SKevin Wolf        vm.add_blockdev('blkdebug,image=drive0-throttle,node-name=drive0-dbg')
445b96e6a0SKevin Wolf        vm.add_blockdev('null-co,node-name=null,read-zeroes=on')
455b96e6a0SKevin Wolf        vm.add_blockdev('blkverify,test=drive0-dbg,raw=null,node-name=drive0-verify')
465b96e6a0SKevin Wolf
475b96e6a0SKevin Wolf        if iotests.supports_quorum():
485b96e6a0SKevin Wolf            vm.add_blockdev('quorum,children.0=drive0-verify,vote-threshold=1,node-name=drive0-quorum')
495b96e6a0SKevin Wolf            root = "drive0-quorum"
505b96e6a0SKevin Wolf        else:
515b96e6a0SKevin Wolf            root = "drive0-verify"
525b96e6a0SKevin Wolf
535b96e6a0SKevin Wolf        vm.add_device('virtio-blk,drive=%s,iothread=iothread0' % root)
545b96e6a0SKevin Wolf
553d53818fSJohn Snow    iotests.qemu_img_create('-f', iotests.imgfmt, img_path, '64M')
565b96e6a0SKevin Wolf
575b96e6a0SKevin Wolf    os.mkfifo(fifo)
585b96e6a0SKevin Wolf
595b96e6a0SKevin Wolf    iotests.log('Launching destination VM...')
605b96e6a0SKevin Wolf    add_opts(vm_b)
615b96e6a0SKevin Wolf    vm_b.add_incoming("exec: cat '%s'" % (fifo))
625b96e6a0SKevin Wolf    vm_b.launch()
635b96e6a0SKevin Wolf
645b96e6a0SKevin Wolf    vm_b.enable_migration_events('B')
655b96e6a0SKevin Wolf
664d804b53SMax Reitz    iotests.log('Launching source VM...')
674d804b53SMax Reitz    add_opts(vm_a)
684d804b53SMax Reitz    vm_a.launch()
694d804b53SMax Reitz
704d804b53SMax Reitz    vm_a.enable_migration_events('A')
714d804b53SMax Reitz
725b96e6a0SKevin Wolf    iotests.log('Starting migration to B...')
735b96e6a0SKevin Wolf    iotests.log(vm_a.qmp('migrate', uri='exec:cat >%s' % (fifo)))
745b96e6a0SKevin Wolf    with iotests.Timeout(3, 'Migration does not complete'):
755b96e6a0SKevin Wolf        # Wait for the source first (which includes setup=setup)
768da7969bSMax Reitz        vm_a.wait_migration('postmigrate')
775b96e6a0SKevin Wolf        # Wait for the destination second (which does not)
788da7969bSMax Reitz        vm_b.wait_migration('running')
795b96e6a0SKevin Wolf
805b96e6a0SKevin Wolf    iotests.log(vm_a.qmp('query-migrate')['return']['status'])
815b96e6a0SKevin Wolf    iotests.log(vm_b.qmp('query-migrate')['return']['status'])
825b96e6a0SKevin Wolf
835b96e6a0SKevin Wolf    iotests.log(vm_a.qmp('query-status'))
845b96e6a0SKevin Wolf    iotests.log(vm_b.qmp('query-status'))
85