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