xref: /openbmc/qemu/tests/qemu-iotests/234 (revision 9dd003a9)
17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: quick migration
3330ca111SKevin Wolf#
4330ca111SKevin Wolf# Copyright (C) 2018 Red Hat, Inc.
5330ca111SKevin Wolf#
6330ca111SKevin Wolf# This program is free software; you can redistribute it and/or modify
7330ca111SKevin Wolf# it under the terms of the GNU General Public License as published by
8330ca111SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
9330ca111SKevin Wolf# (at your option) any later version.
10330ca111SKevin Wolf#
11330ca111SKevin Wolf# This program is distributed in the hope that it will be useful,
12330ca111SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
13330ca111SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14330ca111SKevin Wolf# GNU General Public License for more details.
15330ca111SKevin Wolf#
16330ca111SKevin Wolf# You should have received a copy of the GNU General Public License
17330ca111SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18330ca111SKevin Wolf#
19330ca111SKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
20330ca111SKevin Wolf#
21330ca111SKevin Wolf# Check that block node activation and inactivation works with a block graph
22330ca111SKevin Wolf# that is built with individually created nodes
23330ca111SKevin Wolf
24330ca111SKevin Wolfimport iotests
25330ca111SKevin Wolfimport os
26330ca111SKevin Wolf
277d814059SJohn Snowiotests.script_initialize(supported_fmts=['qcow2'],
287d814059SJohn Snow                          supported_platforms=['linux'])
29330ca111SKevin Wolf
30330ca111SKevin Wolfwith iotests.FilePath('img') as img_path, \
31330ca111SKevin Wolf     iotests.FilePath('backing') as backing_path, \
32330ca111SKevin Wolf     iotests.FilePath('mig_fifo_a') as fifo_a, \
33330ca111SKevin Wolf     iotests.FilePath('mig_fifo_b') as fifo_b, \
34330ca111SKevin Wolf     iotests.VM(path_suffix='a') as vm_a, \
35330ca111SKevin Wolf     iotests.VM(path_suffix='b') as vm_b:
36330ca111SKevin Wolf
37330ca111SKevin Wolf    iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, backing_path, '64M')
38330ca111SKevin Wolf    iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, img_path, '64M')
39330ca111SKevin Wolf
40330ca111SKevin Wolf    os.mkfifo(fifo_a)
41330ca111SKevin Wolf    os.mkfifo(fifo_b)
42330ca111SKevin Wolf
43330ca111SKevin Wolf    iotests.log('Launching source VM...')
44330ca111SKevin Wolf    (vm_a.add_blockdev('file,filename=%s,node-name=drive0-file' % (img_path))
45330ca111SKevin Wolf         .add_blockdev('%s,file=drive0-file,node-name=drive0' % (iotests.imgfmt))
46330ca111SKevin Wolf         .add_blockdev('file,filename=%s,node-name=drive0-backing-file' % (backing_path))
47330ca111SKevin Wolf         .add_blockdev('%s,file=drive0-backing-file,node-name=drive0-backing' % (iotests.imgfmt))
48330ca111SKevin Wolf         .launch())
49330ca111SKevin Wolf
50980448f1SKevin Wolf    vm_a.enable_migration_events('A')
519a378495SMax Reitz
52330ca111SKevin Wolf    iotests.log('Launching destination VM...')
53330ca111SKevin Wolf    (vm_b.add_blockdev('file,filename=%s,node-name=drive0-file' % (img_path))
54330ca111SKevin Wolf         .add_blockdev('%s,file=drive0-file,node-name=drive0' % (iotests.imgfmt))
55330ca111SKevin Wolf         .add_blockdev('file,filename=%s,node-name=drive0-backing-file' % (backing_path))
56330ca111SKevin Wolf         .add_blockdev('%s,file=drive0-backing-file,node-name=drive0-backing' % (iotests.imgfmt))
57330ca111SKevin Wolf         .add_incoming("exec: cat '%s'" % (fifo_a))
58330ca111SKevin Wolf         .launch())
59330ca111SKevin Wolf
60980448f1SKevin Wolf    vm_b.enable_migration_events('B')
619a378495SMax Reitz
62330ca111SKevin Wolf    # Add a child node that was created after the parent node. The reverse case
63330ca111SKevin Wolf    # is covered by the -blockdev options above.
64330ca111SKevin Wolf    iotests.log(vm_a.qmp('blockdev-snapshot', node='drive0-backing',
65330ca111SKevin Wolf                         overlay='drive0'))
66330ca111SKevin Wolf    iotests.log(vm_b.qmp('blockdev-snapshot', node='drive0-backing',
67330ca111SKevin Wolf                         overlay='drive0'))
68330ca111SKevin Wolf
69330ca111SKevin Wolf    iotests.log('Starting migration to B...')
70330ca111SKevin Wolf    iotests.log(vm_a.qmp('migrate', uri='exec:cat >%s' % (fifo_a)))
71330ca111SKevin Wolf    with iotests.Timeout(3, 'Migration does not complete'):
729a378495SMax Reitz        # Wait for the source first (which includes setup=setup)
738da7969bSMax Reitz        vm_a.wait_migration('postmigrate')
749a378495SMax Reitz        # Wait for the destination second (which does not)
758da7969bSMax Reitz        vm_b.wait_migration('running')
76330ca111SKevin Wolf
77330ca111SKevin Wolf    iotests.log(vm_a.qmp('query-migrate')['return']['status'])
78330ca111SKevin Wolf    iotests.log(vm_b.qmp('query-migrate')['return']['status'])
79330ca111SKevin Wolf
80330ca111SKevin Wolf    iotests.log(vm_a.qmp('query-status'))
81330ca111SKevin Wolf    iotests.log(vm_b.qmp('query-status'))
82330ca111SKevin Wolf
83330ca111SKevin Wolf    iotests.log('Add a second parent to drive0-file...')
84330ca111SKevin Wolf    iotests.log(vm_b.qmp('blockdev-add', driver='raw', file='drive0-file',
85330ca111SKevin Wolf                         node_name='drive0-raw'))
86330ca111SKevin Wolf
87330ca111SKevin Wolf    iotests.log('Restart A with -incoming and second parent...')
88330ca111SKevin Wolf    vm_a.shutdown()
89330ca111SKevin Wolf    (vm_a.add_blockdev('raw,file=drive0-file,node-name=drive0-raw')
90330ca111SKevin Wolf         .add_incoming("exec: cat '%s'" % (fifo_b))
91330ca111SKevin Wolf         .launch())
92330ca111SKevin Wolf
93980448f1SKevin Wolf    vm_a.enable_migration_events('A')
949a378495SMax Reitz
95330ca111SKevin Wolf    iotests.log(vm_a.qmp('blockdev-snapshot', node='drive0-backing',
96330ca111SKevin Wolf                         overlay='drive0'))
97330ca111SKevin Wolf
98330ca111SKevin Wolf    iotests.log('Starting migration back to A...')
99330ca111SKevin Wolf    iotests.log(vm_b.qmp('migrate', uri='exec:cat >%s' % (fifo_b)))
100330ca111SKevin Wolf    with iotests.Timeout(3, 'Migration does not complete'):
1019a378495SMax Reitz        # Wait for the source first (which includes setup=setup)
1028da7969bSMax Reitz        vm_b.wait_migration('postmigrate')
1039a378495SMax Reitz        # Wait for the destination second (which does not)
1048da7969bSMax Reitz        vm_a.wait_migration('running')
105330ca111SKevin Wolf
106330ca111SKevin Wolf    iotests.log(vm_a.qmp('query-migrate')['return']['status'])
107330ca111SKevin Wolf    iotests.log(vm_b.qmp('query-migrate')['return']['status'])
108330ca111SKevin Wolf
109330ca111SKevin Wolf    iotests.log(vm_a.qmp('query-status'))
110330ca111SKevin Wolf    iotests.log(vm_b.qmp('query-status'))
111