3 # Copyright (C) 2018 Red Hat, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
20 # Check that block node activation and inactivation works with a block graph
21 # that is built with individually created nodes
26 iotests
.verify_image_format(supported_fmts
=['qcow2'])
27 iotests
.verify_platform(['linux'])
29 def enable_migration_events(vm
, name
):
30 iotests
.log('Enabling migration QMP events on %s...' % name
)
31 iotests
.log(vm
.qmp('migrate-set-capabilities', capabilities
=[
33 'capability': 'events',
38 def wait_migration(vm
):
40 event
= vm
.event_wait('MIGRATION')
41 iotests
.log(event
, filters
=[iotests
.filter_qmp_event
])
42 if event
['data']['status'] == 'completed':
45 with iotests
.FilePath('img') as img_path
, \
46 iotests
.FilePath('backing') as backing_path
, \
47 iotests
.FilePath('mig_fifo_a') as fifo_a
, \
48 iotests
.FilePath('mig_fifo_b') as fifo_b
, \
49 iotests
.VM(path_suffix
='a') as vm_a
, \
50 iotests
.VM(path_suffix
='b') as vm_b
:
52 iotests
.qemu_img_pipe('create', '-f', iotests
.imgfmt
, backing_path
, '64M')
53 iotests
.qemu_img_pipe('create', '-f', iotests
.imgfmt
, img_path
, '64M')
58 iotests
.log('Launching source VM...')
59 (vm_a
.add_blockdev('file,filename=%s,node-name=drive0-file' % (img_path
))
60 .add_blockdev('%s,file=drive0-file,node-name=drive0' % (iotests
.imgfmt
))
61 .add_blockdev('file,filename=%s,node-name=drive0-backing-file' % (backing_path
))
62 .add_blockdev('%s,file=drive0-backing-file,node-name=drive0-backing' % (iotests
.imgfmt
))
65 enable_migration_events(vm_a
, 'A')
67 iotests
.log('Launching destination VM...')
68 (vm_b
.add_blockdev('file,filename=%s,node-name=drive0-file' % (img_path
))
69 .add_blockdev('%s,file=drive0-file,node-name=drive0' % (iotests
.imgfmt
))
70 .add_blockdev('file,filename=%s,node-name=drive0-backing-file' % (backing_path
))
71 .add_blockdev('%s,file=drive0-backing-file,node-name=drive0-backing' % (iotests
.imgfmt
))
72 .add_incoming("exec: cat '%s'" % (fifo_a
))
75 enable_migration_events(vm_b
, 'B')
77 # Add a child node that was created after the parent node. The reverse case
78 # is covered by the -blockdev options above.
79 iotests
.log(vm_a
.qmp('blockdev-snapshot', node
='drive0-backing',
81 iotests
.log(vm_b
.qmp('blockdev-snapshot', node
='drive0-backing',
84 iotests
.log('Starting migration to B...')
85 iotests
.log(vm_a
.qmp('migrate', uri
='exec:cat >%s' % (fifo_a
)))
86 with iotests
.Timeout(3, 'Migration does not complete'):
87 # Wait for the source first (which includes setup=setup)
89 # Wait for the destination second (which does not)
92 iotests
.log(vm_a
.qmp('query-migrate')['return']['status'])
93 iotests
.log(vm_b
.qmp('query-migrate')['return']['status'])
95 iotests
.log(vm_a
.qmp('query-status'))
96 iotests
.log(vm_b
.qmp('query-status'))
98 iotests
.log('Add a second parent to drive0-file...')
99 iotests
.log(vm_b
.qmp('blockdev-add', driver
='raw', file='drive0-file',
100 node_name
='drive0-raw'))
102 iotests
.log('Restart A with -incoming and second parent...')
104 (vm_a
.add_blockdev('raw,file=drive0-file,node-name=drive0-raw')
105 .add_incoming("exec: cat '%s'" % (fifo_b
))
108 enable_migration_events(vm_a
, 'A')
110 iotests
.log(vm_a
.qmp('blockdev-snapshot', node
='drive0-backing',
113 iotests
.log('Starting migration back to A...')
114 iotests
.log(vm_b
.qmp('migrate', uri
='exec:cat >%s' % (fifo_b
)))
115 with iotests
.Timeout(3, 'Migration does not complete'):
116 # Wait for the source first (which includes setup=setup)
118 # Wait for the destination second (which does not)
121 iotests
.log(vm_a
.qmp('query-migrate')['return']['status'])
122 iotests
.log(vm_b
.qmp('query-migrate')['return']['status'])
124 iotests
.log(vm_a
.qmp('query-status'))
125 iotests
.log(vm_b
.qmp('query-status'))