xref: /openbmc/qemu/tests/qemu-iotests/234 (revision 330ca111)
1*330ca111SKevin Wolf#!/usr/bin/env python
2*330ca111SKevin Wolf#
3*330ca111SKevin Wolf# Copyright (C) 2018 Red Hat, Inc.
4*330ca111SKevin Wolf#
5*330ca111SKevin Wolf# This program is free software; you can redistribute it and/or modify
6*330ca111SKevin Wolf# it under the terms of the GNU General Public License as published by
7*330ca111SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
8*330ca111SKevin Wolf# (at your option) any later version.
9*330ca111SKevin Wolf#
10*330ca111SKevin Wolf# This program is distributed in the hope that it will be useful,
11*330ca111SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
12*330ca111SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*330ca111SKevin Wolf# GNU General Public License for more details.
14*330ca111SKevin Wolf#
15*330ca111SKevin Wolf# You should have received a copy of the GNU General Public License
16*330ca111SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17*330ca111SKevin Wolf#
18*330ca111SKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
19*330ca111SKevin Wolf#
20*330ca111SKevin Wolf# Check that block node activation and inactivation works with a block graph
21*330ca111SKevin Wolf# that is built with individually created nodes
22*330ca111SKevin Wolf
23*330ca111SKevin Wolfimport iotests
24*330ca111SKevin Wolfimport os
25*330ca111SKevin Wolf
26*330ca111SKevin Wolfiotests.verify_image_format(supported_fmts=['qcow2'])
27*330ca111SKevin Wolfiotests.verify_platform(['linux'])
28*330ca111SKevin Wolf
29*330ca111SKevin Wolfwith iotests.FilePath('img') as img_path, \
30*330ca111SKevin Wolf     iotests.FilePath('backing') as backing_path, \
31*330ca111SKevin Wolf     iotests.FilePath('mig_fifo_a') as fifo_a, \
32*330ca111SKevin Wolf     iotests.FilePath('mig_fifo_b') as fifo_b, \
33*330ca111SKevin Wolf     iotests.VM(path_suffix='a') as vm_a, \
34*330ca111SKevin Wolf     iotests.VM(path_suffix='b') as vm_b:
35*330ca111SKevin Wolf
36*330ca111SKevin Wolf    iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, backing_path, '64M')
37*330ca111SKevin Wolf    iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, img_path, '64M')
38*330ca111SKevin Wolf
39*330ca111SKevin Wolf    os.mkfifo(fifo_a)
40*330ca111SKevin Wolf    os.mkfifo(fifo_b)
41*330ca111SKevin Wolf
42*330ca111SKevin Wolf    iotests.log('Launching source VM...')
43*330ca111SKevin Wolf    (vm_a.add_blockdev('file,filename=%s,node-name=drive0-file' % (img_path))
44*330ca111SKevin Wolf         .add_blockdev('%s,file=drive0-file,node-name=drive0' % (iotests.imgfmt))
45*330ca111SKevin Wolf         .add_blockdev('file,filename=%s,node-name=drive0-backing-file' % (backing_path))
46*330ca111SKevin Wolf         .add_blockdev('%s,file=drive0-backing-file,node-name=drive0-backing' % (iotests.imgfmt))
47*330ca111SKevin Wolf         .launch())
48*330ca111SKevin Wolf
49*330ca111SKevin Wolf    iotests.log('Launching destination VM...')
50*330ca111SKevin Wolf    (vm_b.add_blockdev('file,filename=%s,node-name=drive0-file' % (img_path))
51*330ca111SKevin Wolf         .add_blockdev('%s,file=drive0-file,node-name=drive0' % (iotests.imgfmt))
52*330ca111SKevin Wolf         .add_blockdev('file,filename=%s,node-name=drive0-backing-file' % (backing_path))
53*330ca111SKevin Wolf         .add_blockdev('%s,file=drive0-backing-file,node-name=drive0-backing' % (iotests.imgfmt))
54*330ca111SKevin Wolf         .add_incoming("exec: cat '%s'" % (fifo_a))
55*330ca111SKevin Wolf         .launch())
56*330ca111SKevin Wolf
57*330ca111SKevin Wolf    # Add a child node that was created after the parent node. The reverse case
58*330ca111SKevin Wolf    # is covered by the -blockdev options above.
59*330ca111SKevin Wolf    iotests.log(vm_a.qmp('blockdev-snapshot', node='drive0-backing',
60*330ca111SKevin Wolf                         overlay='drive0'))
61*330ca111SKevin Wolf    iotests.log(vm_b.qmp('blockdev-snapshot', node='drive0-backing',
62*330ca111SKevin Wolf                         overlay='drive0'))
63*330ca111SKevin Wolf
64*330ca111SKevin Wolf    iotests.log('Enabling migration QMP events on A...')
65*330ca111SKevin Wolf    iotests.log(vm_a.qmp('migrate-set-capabilities', capabilities=[
66*330ca111SKevin Wolf        {
67*330ca111SKevin Wolf            'capability': 'events',
68*330ca111SKevin Wolf            'state': True
69*330ca111SKevin Wolf        }
70*330ca111SKevin Wolf    ]))
71*330ca111SKevin Wolf
72*330ca111SKevin Wolf    iotests.log('Starting migration to B...')
73*330ca111SKevin Wolf    iotests.log(vm_a.qmp('migrate', uri='exec:cat >%s' % (fifo_a)))
74*330ca111SKevin Wolf    with iotests.Timeout(3, 'Migration does not complete'):
75*330ca111SKevin Wolf        while True:
76*330ca111SKevin Wolf            event = vm_a.event_wait('MIGRATION')
77*330ca111SKevin Wolf            iotests.log(event, filters=[iotests.filter_qmp_event])
78*330ca111SKevin Wolf            if event['data']['status'] == 'completed':
79*330ca111SKevin Wolf                break
80*330ca111SKevin Wolf
81*330ca111SKevin Wolf    iotests.log(vm_a.qmp('query-migrate')['return']['status'])
82*330ca111SKevin Wolf    iotests.log(vm_b.qmp('query-migrate')['return']['status'])
83*330ca111SKevin Wolf
84*330ca111SKevin Wolf    iotests.log(vm_a.qmp('query-status'))
85*330ca111SKevin Wolf    iotests.log(vm_b.qmp('query-status'))
86*330ca111SKevin Wolf
87*330ca111SKevin Wolf    iotests.log('Add a second parent to drive0-file...')
88*330ca111SKevin Wolf    iotests.log(vm_b.qmp('blockdev-add', driver='raw', file='drive0-file',
89*330ca111SKevin Wolf                         node_name='drive0-raw'))
90*330ca111SKevin Wolf
91*330ca111SKevin Wolf    iotests.log('Restart A with -incoming and second parent...')
92*330ca111SKevin Wolf    vm_a.shutdown()
93*330ca111SKevin Wolf    (vm_a.add_blockdev('raw,file=drive0-file,node-name=drive0-raw')
94*330ca111SKevin Wolf         .add_incoming("exec: cat '%s'" % (fifo_b))
95*330ca111SKevin Wolf         .launch())
96*330ca111SKevin Wolf
97*330ca111SKevin Wolf    iotests.log(vm_a.qmp('blockdev-snapshot', node='drive0-backing',
98*330ca111SKevin Wolf                         overlay='drive0'))
99*330ca111SKevin Wolf
100*330ca111SKevin Wolf    iotests.log('Enabling migration QMP events on B...')
101*330ca111SKevin Wolf    iotests.log(vm_b.qmp('migrate-set-capabilities', capabilities=[
102*330ca111SKevin Wolf        {
103*330ca111SKevin Wolf            'capability': 'events',
104*330ca111SKevin Wolf            'state': True
105*330ca111SKevin Wolf        }
106*330ca111SKevin Wolf    ]))
107*330ca111SKevin Wolf
108*330ca111SKevin Wolf    iotests.log('Starting migration back to A...')
109*330ca111SKevin Wolf    iotests.log(vm_b.qmp('migrate', uri='exec:cat >%s' % (fifo_b)))
110*330ca111SKevin Wolf    with iotests.Timeout(3, 'Migration does not complete'):
111*330ca111SKevin Wolf        while True:
112*330ca111SKevin Wolf            event = vm_b.event_wait('MIGRATION')
113*330ca111SKevin Wolf            iotests.log(event, filters=[iotests.filter_qmp_event])
114*330ca111SKevin Wolf            if event['data']['status'] == 'completed':
115*330ca111SKevin Wolf                break
116*330ca111SKevin Wolf
117*330ca111SKevin Wolf    iotests.log(vm_a.qmp('query-migrate')['return']['status'])
118*330ca111SKevin Wolf    iotests.log(vm_b.qmp('query-migrate')['return']['status'])
119*330ca111SKevin Wolf
120*330ca111SKevin Wolf    iotests.log(vm_a.qmp('query-status'))
121*330ca111SKevin Wolf    iotests.log(vm_b.qmp('query-status'))
122