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