xref: /openbmc/qemu/tests/qemu-iotests/262 (revision 5b96e6a002d8791d24ef69ed67ee6d264239622d)
1*5b96e6a0SKevin Wolf#!/usr/bin/env python
2*5b96e6a0SKevin Wolf#
3*5b96e6a0SKevin Wolf# Copyright (C) 2019 Red Hat, Inc.
4*5b96e6a0SKevin Wolf#
5*5b96e6a0SKevin Wolf# This program is free software; you can redistribute it and/or modify
6*5b96e6a0SKevin Wolf# it under the terms of the GNU General Public License as published by
7*5b96e6a0SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
8*5b96e6a0SKevin Wolf# (at your option) any later version.
9*5b96e6a0SKevin Wolf#
10*5b96e6a0SKevin Wolf# This program is distributed in the hope that it will be useful,
11*5b96e6a0SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
12*5b96e6a0SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*5b96e6a0SKevin Wolf# GNU General Public License for more details.
14*5b96e6a0SKevin Wolf#
15*5b96e6a0SKevin Wolf# You should have received a copy of the GNU General Public License
16*5b96e6a0SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17*5b96e6a0SKevin Wolf#
18*5b96e6a0SKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
19*5b96e6a0SKevin Wolf#
20*5b96e6a0SKevin Wolf# Test migration with filter drivers present. Keep everything in an
21*5b96e6a0SKevin Wolf# iothread just for fun.
22*5b96e6a0SKevin Wolf
23*5b96e6a0SKevin Wolfimport iotests
24*5b96e6a0SKevin Wolfimport os
25*5b96e6a0SKevin Wolf
26*5b96e6a0SKevin Wolfiotests.verify_image_format(supported_fmts=['qcow2'])
27*5b96e6a0SKevin Wolfiotests.verify_platform(['linux'])
28*5b96e6a0SKevin Wolf
29*5b96e6a0SKevin Wolfwith iotests.FilePath('img') as img_path, \
30*5b96e6a0SKevin Wolf     iotests.FilePath('mig_fifo') as fifo, \
31*5b96e6a0SKevin Wolf     iotests.VM(path_suffix='a') as vm_a, \
32*5b96e6a0SKevin Wolf     iotests.VM(path_suffix='b') as vm_b:
33*5b96e6a0SKevin Wolf
34*5b96e6a0SKevin Wolf    def add_opts(vm):
35*5b96e6a0SKevin Wolf        vm.add_object('iothread,id=iothread0')
36*5b96e6a0SKevin Wolf        vm.add_object('throttle-group,id=tg0,x-bps-total=65536')
37*5b96e6a0SKevin Wolf        vm.add_blockdev('file,filename=%s,node-name=drive0-file' % (img_path))
38*5b96e6a0SKevin Wolf        vm.add_blockdev('%s,file=drive0-file,node-name=drive0-fmt' % (iotests.imgfmt))
39*5b96e6a0SKevin Wolf        vm.add_blockdev('copy-on-read,file=drive0-fmt,node-name=drive0-cor')
40*5b96e6a0SKevin Wolf        vm.add_blockdev('throttle,file=drive0-cor,node-name=drive0-throttle,throttle-group=tg0')
41*5b96e6a0SKevin Wolf        vm.add_blockdev('blkdebug,image=drive0-throttle,node-name=drive0-dbg')
42*5b96e6a0SKevin Wolf        vm.add_blockdev('null-co,node-name=null,read-zeroes=on')
43*5b96e6a0SKevin Wolf        vm.add_blockdev('blkverify,test=drive0-dbg,raw=null,node-name=drive0-verify')
44*5b96e6a0SKevin Wolf
45*5b96e6a0SKevin Wolf        if iotests.supports_quorum():
46*5b96e6a0SKevin Wolf            vm.add_blockdev('quorum,children.0=drive0-verify,vote-threshold=1,node-name=drive0-quorum')
47*5b96e6a0SKevin Wolf            root = "drive0-quorum"
48*5b96e6a0SKevin Wolf        else:
49*5b96e6a0SKevin Wolf            root = "drive0-verify"
50*5b96e6a0SKevin Wolf
51*5b96e6a0SKevin Wolf        vm.add_device('virtio-blk,drive=%s,iothread=iothread0' % root)
52*5b96e6a0SKevin Wolf
53*5b96e6a0SKevin Wolf    iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, img_path, '64M')
54*5b96e6a0SKevin Wolf
55*5b96e6a0SKevin Wolf    os.mkfifo(fifo)
56*5b96e6a0SKevin Wolf
57*5b96e6a0SKevin Wolf    iotests.log('Launching source VM...')
58*5b96e6a0SKevin Wolf    add_opts(vm_a)
59*5b96e6a0SKevin Wolf    vm_a.launch()
60*5b96e6a0SKevin Wolf
61*5b96e6a0SKevin Wolf    vm_a.enable_migration_events('A')
62*5b96e6a0SKevin Wolf
63*5b96e6a0SKevin Wolf    iotests.log('Launching destination VM...')
64*5b96e6a0SKevin Wolf    add_opts(vm_b)
65*5b96e6a0SKevin Wolf    vm_b.add_incoming("exec: cat '%s'" % (fifo))
66*5b96e6a0SKevin Wolf    vm_b.launch()
67*5b96e6a0SKevin Wolf
68*5b96e6a0SKevin Wolf    vm_b.enable_migration_events('B')
69*5b96e6a0SKevin Wolf
70*5b96e6a0SKevin Wolf    iotests.log('Starting migration to B...')
71*5b96e6a0SKevin Wolf    iotests.log(vm_a.qmp('migrate', uri='exec:cat >%s' % (fifo)))
72*5b96e6a0SKevin Wolf    with iotests.Timeout(3, 'Migration does not complete'):
73*5b96e6a0SKevin Wolf        # Wait for the source first (which includes setup=setup)
74*5b96e6a0SKevin Wolf        vm_a.wait_migration()
75*5b96e6a0SKevin Wolf        # Wait for the destination second (which does not)
76*5b96e6a0SKevin Wolf        vm_b.wait_migration()
77*5b96e6a0SKevin Wolf
78*5b96e6a0SKevin Wolf    iotests.log(vm_a.qmp('query-migrate')['return']['status'])
79*5b96e6a0SKevin Wolf    iotests.log(vm_b.qmp('query-migrate')['return']['status'])
80*5b96e6a0SKevin Wolf
81*5b96e6a0SKevin Wolf    iotests.log(vm_a.qmp('query-status'))
82*5b96e6a0SKevin Wolf    iotests.log(vm_b.qmp('query-status'))
83