]>
Commit | Line | Data |
---|---|---|
4089f7c6 JC |
1 | #!/bin/bash |
2 | # | |
3 | # Live snapshot tests | |
4 | # | |
5 | # This tests live snapshots of images on a running QEMU instance, using | |
6 | # QMP commands. Both single disk snapshots, and transactional group | |
7 | # snapshots are performed. | |
8 | # | |
9 | # Copyright (C) 2014 Red Hat, Inc. | |
89e3a2d8 | 10 | # Copyright (C) 2015 Igalia, S.L. |
4089f7c6 JC |
11 | # |
12 | # This program is free software; you can redistribute it and/or modify | |
13 | # it under the terms of the GNU General Public License as published by | |
14 | # the Free Software Foundation; either version 2 of the License, or | |
15 | # (at your option) any later version. | |
16 | # | |
17 | # This program is distributed in the hope that it will be useful, | |
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | # GNU General Public License for more details. | |
21 | # | |
22 | # You should have received a copy of the GNU General Public License | |
23 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
24 | # | |
25 | ||
26 | # creator | |
27 | [email protected] | |
28 | ||
29 | seq=`basename $0` | |
30 | echo "QA output created by $seq" | |
31 | ||
32 | here=`pwd` | |
33 | status=1 # failure is the default! | |
4089f7c6 JC |
34 | |
35 | snapshot_virt0="snapshot-v0.qcow2" | |
36 | snapshot_virt1="snapshot-v1.qcow2" | |
37 | ||
89e3a2d8 | 38 | SNAPSHOTS=10 |
4089f7c6 JC |
39 | |
40 | _cleanup() | |
41 | { | |
e86e8697 | 42 | _cleanup_qemu |
89e3a2d8 | 43 | for i in $(seq 1 ${SNAPSHOTS}) |
4089f7c6 JC |
44 | do |
45 | rm -f "${TEST_DIR}/${i}-${snapshot_virt0}" | |
46 | rm -f "${TEST_DIR}/${i}-${snapshot_virt1}" | |
47 | done | |
ecffa634 | 48 | rm -f "${TEST_IMG}" "${TEST_IMG}.1" "${TEST_IMG}.2" "${TEST_IMG}.base" |
4089f7c6 JC |
49 | |
50 | } | |
51 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
52 | ||
53 | # get standard environment, filters and checks | |
54 | . ./common.rc | |
55 | . ./common.filter | |
e86e8697 | 56 | . ./common.qemu |
4089f7c6 JC |
57 | |
58 | _supported_fmt qcow2 | |
59 | _supported_proto file | |
60 | _supported_os Linux | |
61 | ||
4089f7c6 JC |
62 | |
63 | # ${1}: unique identifier for the snapshot filename | |
64 | function create_single_snapshot() | |
65 | { | |
66 | cmd="{ 'execute': 'blockdev-snapshot-sync', | |
67 | 'arguments': { 'device': 'virtio0', | |
f2d7f16f | 68 | 'snapshot-file':'${TEST_DIR}/${1}-${snapshot_virt0}', |
4089f7c6 | 69 | 'format': 'qcow2' } }" |
e86e8697 | 70 | _send_qemu_cmd $h "${cmd}" "return" |
4089f7c6 JC |
71 | } |
72 | ||
73 | # ${1}: unique identifier for the snapshot filename | |
74 | function create_group_snapshot() | |
75 | { | |
76 | cmd="{ 'execute': 'transaction', 'arguments': | |
77 | {'actions': [ | |
78 | { 'type': 'blockdev-snapshot-sync', 'data' : | |
79 | { 'device': 'virtio0', | |
f2d7f16f | 80 | 'snapshot-file': '${TEST_DIR}/${1}-${snapshot_virt0}' } }, |
4089f7c6 JC |
81 | { 'type': 'blockdev-snapshot-sync', 'data' : |
82 | { 'device': 'virtio1', | |
f2d7f16f | 83 | 'snapshot-file': '${TEST_DIR}/${1}-${snapshot_virt1}' } } ] |
4089f7c6 JC |
84 | } }" |
85 | ||
e86e8697 | 86 | _send_qemu_cmd $h "${cmd}" "return" |
4089f7c6 JC |
87 | } |
88 | ||
89e3a2d8 | 89 | # ${1}: unique identifier for the snapshot filename |
ecffa634 FZ |
90 | # ${2}: extra_params to the blockdev-add command |
91 | # ${3}: filename | |
92 | function do_blockdev_add() | |
93 | { | |
94 | cmd="{ 'execute': 'blockdev-add', 'arguments': | |
95 | { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${2} | |
96 | 'file': | |
97 | { 'driver': 'file', 'filename': '${3}', | |
98 | 'node-name': 'file_${1}' } } }" | |
99 | _send_qemu_cmd $h "${cmd}" "return" | |
100 | } | |
101 | ||
102 | # ${1}: unique identifier for the snapshot filename | |
89e3a2d8 AG |
103 | function add_snapshot_image() |
104 | { | |
89e3a2d8 AG |
105 | base_image="${TEST_DIR}/$((${1}-1))-${snapshot_virt0}" |
106 | snapshot_file="${TEST_DIR}/${1}-${snapshot_virt0}" | |
6e6e55f5 | 107 | _make_test_img -u -b "${base_image}" "$size" |
89e3a2d8 | 108 | mv "${TEST_IMG}" "${snapshot_file}" |
c42e8742 | 109 | do_blockdev_add "$1" "'backing': null, " "${snapshot_file}" |
89e3a2d8 AG |
110 | } |
111 | ||
112 | # ${1}: unique identifier for the snapshot filename | |
113 | # ${2}: expected response, defaults to 'return' | |
114 | function blockdev_snapshot() | |
115 | { | |
116 | cmd="{ 'execute': 'blockdev-snapshot', | |
117 | 'arguments': { 'node': 'virtio0', | |
f2d7f16f | 118 | 'overlay':'snap_${1}' } }" |
89e3a2d8 AG |
119 | _send_qemu_cmd $h "${cmd}" "${2:-return}" |
120 | } | |
121 | ||
4089f7c6 JC |
122 | size=128M |
123 | ||
4089f7c6 | 124 | _make_test_img $size |
89e3a2d8 | 125 | mv "${TEST_IMG}" "${TEST_IMG}.1" |
4089f7c6 | 126 | _make_test_img $size |
89e3a2d8 | 127 | mv "${TEST_IMG}" "${TEST_IMG}.2" |
4089f7c6 JC |
128 | |
129 | echo | |
130 | echo === Running QEMU === | |
131 | echo | |
132 | ||
e86e8697 | 133 | qemu_comm_method="qmp" |
89e3a2d8 | 134 | _launch_qemu -drive file="${TEST_IMG}.1",if=virtio -drive file="${TEST_IMG}.2",if=virtio |
e86e8697 | 135 | h=$QEMU_HANDLE |
4089f7c6 JC |
136 | |
137 | echo | |
138 | echo === Sending capabilities === | |
139 | echo | |
140 | ||
e86e8697 | 141 | _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" "return" |
4089f7c6 | 142 | |
89e3a2d8 AG |
143 | # Tests for the blockdev-snapshot-sync command |
144 | ||
4089f7c6 JC |
145 | echo |
146 | echo === Create a single snapshot on virtio0 === | |
147 | echo | |
148 | ||
149 | create_single_snapshot 1 | |
150 | ||
151 | ||
152 | echo | |
153 | echo === Invalid command - missing device and nodename === | |
154 | echo | |
155 | ||
e86e8697 | 156 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync', |
f2d7f16f | 157 | 'arguments': { 'snapshot-file':'${TEST_DIR}/1-${snapshot_virt0}', |
4089f7c6 JC |
158 | 'format': 'qcow2' } }" "error" |
159 | ||
160 | echo | |
161 | echo === Invalid command - missing snapshot-file === | |
162 | echo | |
163 | ||
e86e8697 JC |
164 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync', |
165 | 'arguments': { 'device': 'virtio0', | |
4089f7c6 JC |
166 | 'format': 'qcow2' } }" "error" |
167 | echo | |
168 | echo | |
169 | echo === Create several transactional group snapshots === | |
170 | echo | |
171 | ||
89e3a2d8 | 172 | for i in $(seq 2 ${SNAPSHOTS}) |
4089f7c6 JC |
173 | do |
174 | create_group_snapshot ${i} | |
175 | done | |
176 | ||
89e3a2d8 AG |
177 | # Tests for the blockdev-snapshot command |
178 | ||
179 | echo | |
180 | echo === Create a couple of snapshots using blockdev-snapshot === | |
181 | echo | |
182 | ||
183 | SNAPSHOTS=$((${SNAPSHOTS}+1)) | |
184 | add_snapshot_image ${SNAPSHOTS} | |
185 | blockdev_snapshot ${SNAPSHOTS} | |
186 | ||
187 | SNAPSHOTS=$((${SNAPSHOTS}+1)) | |
188 | add_snapshot_image ${SNAPSHOTS} | |
189 | blockdev_snapshot ${SNAPSHOTS} | |
190 | ||
3fa123d0 AG |
191 | echo |
192 | echo === Invalid command - cannot create a snapshot using a file BDS === | |
193 | echo | |
194 | ||
195 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot', | |
196 | 'arguments': { 'node':'virtio0', | |
197 | 'overlay':'file_${SNAPSHOTS}' } | |
198 | }" "error" | |
199 | ||
89e3a2d8 AG |
200 | echo |
201 | echo === Invalid command - snapshot node used as active layer === | |
202 | echo | |
203 | ||
204 | blockdev_snapshot ${SNAPSHOTS} error | |
205 | ||
206 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot', | |
207 | 'arguments': { 'node':'virtio0', | |
208 | 'overlay':'virtio0' } | |
209 | }" "error" | |
210 | ||
211 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot', | |
212 | 'arguments': { 'node':'virtio0', | |
213 | 'overlay':'virtio1' } | |
214 | }" "error" | |
215 | ||
216 | echo | |
217 | echo === Invalid command - snapshot node used as backing hd === | |
218 | echo | |
219 | ||
220 | blockdev_snapshot $((${SNAPSHOTS}-1)) error | |
221 | ||
222 | echo | |
223 | echo === Invalid command - snapshot node has a backing image === | |
224 | echo | |
225 | ||
226 | SNAPSHOTS=$((${SNAPSHOTS}+1)) | |
ecffa634 FZ |
227 | |
228 | TEST_IMG="$TEST_IMG.base" _make_test_img "$size" | |
229 | _make_test_img -b "${TEST_IMG}.base" "$size" | |
230 | do_blockdev_add ${SNAPSHOTS} "" "${TEST_IMG}" | |
89e3a2d8 AG |
231 | blockdev_snapshot ${SNAPSHOTS} error |
232 | ||
233 | echo | |
234 | echo === Invalid command - The node does not exist === | |
235 | echo | |
236 | ||
237 | blockdev_snapshot $((${SNAPSHOTS}+1)) error | |
238 | ||
239 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot', | |
240 | 'arguments': { 'node':'nodevice', | |
f2d7f16f | 241 | 'overlay':'snap_${SNAPSHOTS}' } |
89e3a2d8 AG |
242 | }" "error" |
243 | ||
4089f7c6 JC |
244 | # success, all done |
245 | echo "*** done" | |
246 | rm -f $seq.full | |
247 | status=0 |