xref: /openbmc/qemu/tests/qemu-iotests/091 (revision cbc95538)
1#!/bin/bash
2#
3# Live migration test
4#
5# Performs a migration from one VM to another via monitor commands
6#
7# Copyright (C) 2014 Red Hat, Inc.
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21#
22
23# creator
24owner=jcody@redhat.com
25
26seq=`basename $0`
27echo "QA output created by $seq"
28
29here=`pwd`
30status=1    # failure is the default!
31
32MIG_FIFO="${TEST_DIR}/migrate"
33
34_cleanup()
35{
36    rm -f "${MIG_FIFO}"
37    _cleanup_qemu
38    _cleanup_test_img
39}
40trap "_cleanup; exit \$status" 0 1 2 3 15
41
42# get standard environment, filters and checks
43. ./common.rc
44. ./common.filter
45. ./common.qemu
46
47_supported_fmt qcow2
48_supported_proto file
49_supported_os Linux
50
51size=1G
52
53_make_test_img $size
54
55mkfifo "${MIG_FIFO}"
56
57echo
58echo === Starting QEMU VM1 ===
59echo
60
61qemu_comm_method="monitor"
62_launch_qemu -drive file="${TEST_IMG}",cache=none,id=disk
63h1=$QEMU_HANDLE
64
65echo
66echo === Starting QEMU VM2 ===
67echo
68_launch_qemu -drive file="${TEST_IMG}",cache=none,id=disk \
69             -incoming "exec: cat '${MIG_FIFO}'"
70h2=$QEMU_HANDLE
71
72echo
73echo === VM 1: Migrate from VM1 to VM2  ===
74echo
75
76silent=yes
77_send_qemu_cmd $h1 'qemu-io disk "write -P 0x22 0 4M"' "(qemu)"
78echo "vm1: qemu-io disk write complete"
79_send_qemu_cmd $h1 "migrate \"exec: cat > '${MIG_FIFO}'\"" "(qemu)"
80echo "vm1: live migration started"
81qemu_cmd_repeat=20 _send_qemu_cmd $h1 "info migrate" "completed"
82echo "vm1: live migration completed"
83
84echo
85echo === VM 2: Post-migration, write to disk, verify running ===
86echo
87
88_send_qemu_cmd $h2 'qemu-io disk "write 4M 1M"' "(qemu)"
89echo "vm2: qemu-io disk write complete"
90qemu_cmd_repeat=20 _send_qemu_cmd $h2 "info status" "running"
91echo "vm2: qemu process running successfully"
92
93echo "vm2: flush io, and quit"
94_send_qemu_cmd $h2 'qemu-io disk flush' "(qemu)"
95_send_qemu_cmd $h2 'quit' ""
96
97echo "Check image pattern"
98${QEMU_IO} -c "read -P 0x22 0 4M" "${TEST_IMG}" | _filter_testdir | _filter_qemu_io
99
100echo "Running 'qemu-img check -r all \$TEST_IMG'"
101"${QEMU_IMG}" check -r all "${TEST_IMG}" 2>&1 | _filter_testdir | _filter_qemu
102
103echo "*** done"
104rm -f $seq.full
105status=0
106