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 with iotests
.FilePath('img') as img_path
, \
30 iotests
.FilePath('backing') as backing_path
, \
31 iotests
.FilePath('mig_fifo_a') as fifo_a
, \
32 iotests
.FilePath('mig_fifo_b') as fifo_b
, \
33 iotests
.VM(path_suffix
='a') as vm_a
, \
34 iotests
.VM(path_suffix
='b') as vm_b
:
36 iotests
.qemu_img_pipe('create', '-f', iotests
.imgfmt
, backing_path
, '64M')
37 iotests
.qemu_img_pipe('create', '-f', iotests
.imgfmt
, img_path
, '64M')
42 iotests
.log('Launching source VM...')
43 (vm_a
.add_blockdev('file,filename=%s,node-name=drive0-file' % (img_path
))
44 .add_blockdev('%s,file=drive0-file,node-name=drive0' % (iotests
.imgfmt
))
45 .add_blockdev('file,filename=%s,node-name=drive0-backing-file' % (backing_path
))
46 .add_blockdev('%s,file=drive0-backing-file,node-name=drive0-backing' % (iotests
.imgfmt
))
49 iotests
.log('Launching destination VM...')
50 (vm_b
.add_blockdev('file,filename=%s,node-name=drive0-file' % (img_path
))
51 .add_blockdev('%s,file=drive0-file,node-name=drive0' % (iotests
.imgfmt
))
52 .add_blockdev('file,filename=%s,node-name=drive0-backing-file' % (backing_path
))
53 .add_blockdev('%s,file=drive0-backing-file,node-name=drive0-backing' % (iotests
.imgfmt
))
54 .add_incoming("exec: cat '%s'" % (fifo_a
))
57 # Add a child node that was created after the parent node. The reverse case
58 # is covered by the -blockdev options above.
59 iotests
.log(vm_a
.qmp('blockdev-snapshot', node
='drive0-backing',
61 iotests
.log(vm_b
.qmp('blockdev-snapshot', node
='drive0-backing',
64 iotests
.log('Enabling migration QMP events on A...')
65 iotests
.log(vm_a
.qmp('migrate-set-capabilities', capabilities
=[
67 'capability': 'events',
72 iotests
.log('Starting migration to B...')
73 iotests
.log(vm_a
.qmp('migrate', uri
='exec:cat >%s' % (fifo_a
)))
74 with iotests
.Timeout(3, 'Migration does not complete'):
76 event
= vm_a
.event_wait('MIGRATION')
77 iotests
.log(event
, filters
=[iotests
.filter_qmp_event
])
78 if event
['data']['status'] == 'completed':
81 iotests
.log(vm_a
.qmp('query-migrate')['return']['status'])
82 iotests
.log(vm_b
.qmp('query-migrate')['return']['status'])
84 iotests
.log(vm_a
.qmp('query-status'))
85 iotests
.log(vm_b
.qmp('query-status'))
87 iotests
.log('Add a second parent to drive0-file...')
88 iotests
.log(vm_b
.qmp('blockdev-add', driver
='raw', file='drive0-file',
89 node_name
='drive0-raw'))
91 iotests
.log('Restart A with -incoming and second parent...')
93 (vm_a
.add_blockdev('raw,file=drive0-file,node-name=drive0-raw')
94 .add_incoming("exec: cat '%s'" % (fifo_b
))
97 iotests
.log(vm_a
.qmp('blockdev-snapshot', node
='drive0-backing',
100 iotests
.log('Enabling migration QMP events on B...')
101 iotests
.log(vm_b
.qmp('migrate-set-capabilities', capabilities
=[
103 'capability': 'events',
108 iotests
.log('Starting migration back to A...')
109 iotests
.log(vm_b
.qmp('migrate', uri
='exec:cat >%s' % (fifo_b
)))
110 with iotests
.Timeout(3, 'Migration does not complete'):
112 event
= vm_b
.event_wait('MIGRATION')
113 iotests
.log(event
, filters
=[iotests
.filter_qmp_event
])
114 if event
['data']['status'] == 'completed':
117 iotests
.log(vm_a
.qmp('query-migrate')['return']['status'])
118 iotests
.log(vm_b
.qmp('query-migrate')['return']['status'])
120 iotests
.log(vm_a
.qmp('query-status'))
121 iotests
.log(vm_b
.qmp('query-status'))