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