111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2fd040174SJeff Cody# 3fd040174SJeff Cody# Live migration test 4fd040174SJeff Cody# 5fd040174SJeff Cody# Performs a migration from one VM to another via monitor commands 6fd040174SJeff Cody# 7fd040174SJeff Cody# Copyright (C) 2014 Red Hat, Inc. 8fd040174SJeff Cody# 9fd040174SJeff Cody# This program is free software; you can redistribute it and/or modify 10fd040174SJeff Cody# it under the terms of the GNU General Public License as published by 11fd040174SJeff Cody# the Free Software Foundation; either version 2 of the License, or 12fd040174SJeff Cody# (at your option) any later version. 13fd040174SJeff Cody# 14fd040174SJeff Cody# This program is distributed in the hope that it will be useful, 15fd040174SJeff Cody# but WITHOUT ANY WARRANTY; without even the implied warranty of 16fd040174SJeff Cody# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17fd040174SJeff Cody# GNU General Public License for more details. 18fd040174SJeff Cody# 19fd040174SJeff Cody# You should have received a copy of the GNU General Public License 20fd040174SJeff Cody# along with this program. If not, see <http://www.gnu.org/licenses/>. 21fd040174SJeff Cody# 22fd040174SJeff Cody 23fd040174SJeff Cody# creator 24fd040174SJeff Codyowner=jcody@redhat.com 25fd040174SJeff Cody 26fd040174SJeff Codyseq=`basename $0` 27fd040174SJeff Codyecho "QA output created by $seq" 28fd040174SJeff Cody 29fd040174SJeff Codystatus=1 # failure is the default! 30fd040174SJeff Cody 31fd040174SJeff CodyMIG_FIFO="${TEST_DIR}/migrate" 32fd040174SJeff Cody 33fd040174SJeff Cody_cleanup() 34fd040174SJeff Cody{ 35fd040174SJeff Cody rm -f "${MIG_FIFO}" 36fd040174SJeff Cody _cleanup_qemu 37fd040174SJeff Cody _cleanup_test_img 38fd040174SJeff Cody} 39fd040174SJeff Codytrap "_cleanup; exit \$status" 0 1 2 3 15 40fd040174SJeff Cody 41fd040174SJeff Cody# get standard environment, filters and checks 42fd040174SJeff Cody. ./common.rc 43fd040174SJeff Cody. ./common.filter 44fd040174SJeff Cody. ./common.qemu 45fd040174SJeff Cody 46fd040174SJeff Cody_supported_fmt qcow2 47fd040174SJeff Cody_supported_proto file 48fd040174SJeff Cody_supported_os Linux 49755c5fe7SNir Soffer_supported_cache_modes writethrough none writeback 50*cfdca2b9SVladimir Sementsov-Ogievskiy_default_cache_mode none writeback 51fd040174SJeff Cody 52fd040174SJeff Codysize=1G 53fd040174SJeff Cody 54fd040174SJeff Cody_make_test_img $size 55fd040174SJeff Cody 56fd040174SJeff Codymkfifo "${MIG_FIFO}" 57fd040174SJeff Cody 58fd040174SJeff Codyecho 59fd040174SJeff Codyecho === Starting QEMU VM1 === 60fd040174SJeff Codyecho 61fd040174SJeff Cody 62fd040174SJeff Codyqemu_comm_method="monitor" 638dff69b9SAarushi Mehta_launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=${AIOMODE},id=disk 64fd040174SJeff Codyh1=$QEMU_HANDLE 65fd040174SJeff Cody 66fd040174SJeff Codyecho 67fd040174SJeff Codyecho === Starting QEMU VM2 === 68fd040174SJeff Codyecho 698dff69b9SAarushi Mehta_launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=${AIOMODE},id=disk \ 70fd040174SJeff Cody -incoming "exec: cat '${MIG_FIFO}'" 71fd040174SJeff Codyh2=$QEMU_HANDLE 72fd040174SJeff Cody 73fd040174SJeff Codyecho 74fd040174SJeff Codyecho === VM 1: Migrate from VM1 to VM2 === 75fd040174SJeff Codyecho 76fd040174SJeff Cody 77fd040174SJeff Codysilent=yes 78fd040174SJeff Cody_send_qemu_cmd $h1 'qemu-io disk "write -P 0x22 0 4M"' "(qemu)" 79fd040174SJeff Codyecho "vm1: qemu-io disk write complete" 80fd040174SJeff Cody_send_qemu_cmd $h1 "migrate \"exec: cat > '${MIG_FIFO}'\"" "(qemu)" 81fd040174SJeff Codyecho "vm1: live migration started" 82fd040174SJeff Codyqemu_cmd_repeat=20 _send_qemu_cmd $h1 "info migrate" "completed" 83fd040174SJeff Codyecho "vm1: live migration completed" 84fd040174SJeff Cody 85fd040174SJeff Codyecho 86fd040174SJeff Codyecho === VM 2: Post-migration, write to disk, verify running === 87fd040174SJeff Codyecho 88fd040174SJeff Cody 89fd040174SJeff Cody_send_qemu_cmd $h2 'qemu-io disk "write 4M 1M"' "(qemu)" 90fd040174SJeff Codyecho "vm2: qemu-io disk write complete" 91fd040174SJeff Codyqemu_cmd_repeat=20 _send_qemu_cmd $h2 "info status" "running" 92fd040174SJeff Codyecho "vm2: qemu process running successfully" 93fd040174SJeff Cody 94fd040174SJeff Codyecho "vm2: flush io, and quit" 95fd040174SJeff Cody_send_qemu_cmd $h2 'qemu-io disk flush' "(qemu)" 96fd040174SJeff Cody_send_qemu_cmd $h2 'quit' "" 978b084489SFam Zheng_send_qemu_cmd $h1 'quit' "" 98fd040174SJeff Cody 998b084489SFam Zhengwait 100fd040174SJeff Codyecho "Check image pattern" 101fd040174SJeff Cody${QEMU_IO} -c "read -P 0x22 0 4M" "${TEST_IMG}" | _filter_testdir | _filter_qemu_io 102fd040174SJeff Cody 103fd040174SJeff Codyecho "Running 'qemu-img check -r all \$TEST_IMG'" 104990f9bccSMax Reitz_check_test_img -r all 105fd040174SJeff Cody 106fd040174SJeff Codyecho "*** done" 107fd040174SJeff Codyrm -f $seq.full 108fd040174SJeff Codystatus=0 109