1fd040174SJeff Cody#!/bin/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 Codyhere=`pwd` 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 48fd040174SJeff Cody_supported_proto file 49fd040174SJeff Cody_supported_os Linux 50*7cf6376aSFam Zheng_default_cache_mode "none" 51*7cf6376aSFam Zheng_supported_cache_modes "writethrough" "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" 64*7cf6376aSFam Zheng_launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},id=disk 65fd040174SJeff Codyh1=$QEMU_HANDLE 66fd040174SJeff Cody 67fd040174SJeff Codyecho 68fd040174SJeff Codyecho === Starting QEMU VM2 === 69fd040174SJeff Codyecho 70*7cf6376aSFam Zheng_launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},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' "" 98fd040174SJeff Cody 99fd040174SJeff Codyecho "Check image pattern" 100fd040174SJeff Cody${QEMU_IO} -c "read -P 0x22 0 4M" "${TEST_IMG}" | _filter_testdir | _filter_qemu_io 101fd040174SJeff Cody 102fd040174SJeff Codyecho "Running 'qemu-img check -r all \$TEST_IMG'" 103fd040174SJeff Cody"${QEMU_IMG}" check -r all "${TEST_IMG}" 2>&1 | _filter_testdir | _filter_qemu 104fd040174SJeff Cody 105fd040174SJeff Codyecho "*** done" 106fd040174SJeff Codyrm -f $seq.full 107fd040174SJeff Codystatus=0 108