]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
4089f7c6 JC |
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 | owner=jcody@redhat.com | |
28 | ||
29 | seq=`basename $0` | |
30 | echo "QA output created by $seq" | |
31 | ||
4089f7c6 | 32 | status=1 # failure is the default! |
4089f7c6 JC |
33 | |
34 | snapshot_virt0="snapshot-v0.qcow2" | |
35 | snapshot_virt1="snapshot-v1.qcow2" | |
36 | ||
89e3a2d8 | 37 | SNAPSHOTS=10 |
4089f7c6 JC |
38 | |
39 | _cleanup() | |
40 | { | |
e86e8697 | 41 | _cleanup_qemu |
89e3a2d8 | 42 | for i in $(seq 1 ${SNAPSHOTS}) |
4089f7c6 JC |
43 | do |
44 | rm -f "${TEST_DIR}/${i}-${snapshot_virt0}" | |
45 | rm -f "${TEST_DIR}/${i}-${snapshot_virt1}" | |
46 | done | |
ecffa634 | 47 | rm -f "${TEST_IMG}" "${TEST_IMG}.1" "${TEST_IMG}.2" "${TEST_IMG}.base" |
4089f7c6 JC |
48 | |
49 | } | |
50 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
51 | ||
52 | # get standard environment, filters and checks | |
53 | . ./common.rc | |
54 | . ./common.filter | |
e86e8697 | 55 | . ./common.qemu |
4089f7c6 JC |
56 | |
57 | _supported_fmt qcow2 | |
58 | _supported_proto file | |
4089f7c6 | 59 | |
4089f7c6 JC |
60 | |
61 | # ${1}: unique identifier for the snapshot filename | |
8cedcffd | 62 | create_single_snapshot() |
4089f7c6 JC |
63 | { |
64 | cmd="{ 'execute': 'blockdev-snapshot-sync', | |
65 | 'arguments': { 'device': 'virtio0', | |
f2d7f16f | 66 | 'snapshot-file':'${TEST_DIR}/${1}-${snapshot_virt0}', |
4089f7c6 | 67 | 'format': 'qcow2' } }" |
e86e8697 | 68 | _send_qemu_cmd $h "${cmd}" "return" |
4089f7c6 JC |
69 | } |
70 | ||
71 | # ${1}: unique identifier for the snapshot filename | |
8cedcffd | 72 | create_group_snapshot() |
4089f7c6 JC |
73 | { |
74 | cmd="{ 'execute': 'transaction', 'arguments': | |
75 | {'actions': [ | |
76 | { 'type': 'blockdev-snapshot-sync', 'data' : | |
77 | { 'device': 'virtio0', | |
f2d7f16f | 78 | 'snapshot-file': '${TEST_DIR}/${1}-${snapshot_virt0}' } }, |
4089f7c6 JC |
79 | { 'type': 'blockdev-snapshot-sync', 'data' : |
80 | { 'device': 'virtio1', | |
f2d7f16f | 81 | 'snapshot-file': '${TEST_DIR}/${1}-${snapshot_virt1}' } } ] |
4089f7c6 JC |
82 | } }" |
83 | ||
e86e8697 | 84 | _send_qemu_cmd $h "${cmd}" "return" |
4089f7c6 JC |
85 | } |
86 | ||
89e3a2d8 | 87 | # ${1}: unique identifier for the snapshot filename |
ecffa634 FZ |
88 | # ${2}: extra_params to the blockdev-add command |
89 | # ${3}: filename | |
8cedcffd | 90 | do_blockdev_add() |
ecffa634 FZ |
91 | { |
92 | cmd="{ 'execute': 'blockdev-add', 'arguments': | |
93 | { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${2} | |
94 | 'file': | |
95 | { 'driver': 'file', 'filename': '${3}', | |
96 | 'node-name': 'file_${1}' } } }" | |
97 | _send_qemu_cmd $h "${cmd}" "return" | |
98 | } | |
99 | ||
100 | # ${1}: unique identifier for the snapshot filename | |
8cedcffd | 101 | add_snapshot_image() |
89e3a2d8 | 102 | { |
89e3a2d8 AG |
103 | base_image="${TEST_DIR}/$((${1}-1))-${snapshot_virt0}" |
104 | snapshot_file="${TEST_DIR}/${1}-${snapshot_virt0}" | |
6e6e55f5 | 105 | _make_test_img -u -b "${base_image}" "$size" |
89e3a2d8 | 106 | mv "${TEST_IMG}" "${snapshot_file}" |
c42e8742 | 107 | do_blockdev_add "$1" "'backing': null, " "${snapshot_file}" |
89e3a2d8 AG |
108 | } |
109 | ||
110 | # ${1}: unique identifier for the snapshot filename | |
111 | # ${2}: expected response, defaults to 'return' | |
8cedcffd | 112 | blockdev_snapshot() |
89e3a2d8 AG |
113 | { |
114 | cmd="{ 'execute': 'blockdev-snapshot', | |
115 | 'arguments': { 'node': 'virtio0', | |
f2d7f16f | 116 | 'overlay':'snap_${1}' } }" |
89e3a2d8 AG |
117 | _send_qemu_cmd $h "${cmd}" "${2:-return}" |
118 | } | |
119 | ||
4089f7c6 JC |
120 | size=128M |
121 | ||
4089f7c6 | 122 | _make_test_img $size |
89e3a2d8 | 123 | mv "${TEST_IMG}" "${TEST_IMG}.1" |
4089f7c6 | 124 | _make_test_img $size |
89e3a2d8 | 125 | mv "${TEST_IMG}" "${TEST_IMG}.2" |
4089f7c6 JC |
126 | |
127 | echo | |
128 | echo === Running QEMU === | |
129 | echo | |
130 | ||
e86e8697 | 131 | qemu_comm_method="qmp" |
89e3a2d8 | 132 | _launch_qemu -drive file="${TEST_IMG}.1",if=virtio -drive file="${TEST_IMG}.2",if=virtio |
e86e8697 | 133 | h=$QEMU_HANDLE |
4089f7c6 JC |
134 | |
135 | echo | |
136 | echo === Sending capabilities === | |
137 | echo | |
138 | ||
e86e8697 | 139 | _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" "return" |
4089f7c6 | 140 | |
89e3a2d8 AG |
141 | # Tests for the blockdev-snapshot-sync command |
142 | ||
4089f7c6 JC |
143 | echo |
144 | echo === Create a single snapshot on virtio0 === | |
145 | echo | |
146 | ||
147 | create_single_snapshot 1 | |
148 | ||
149 | ||
150 | echo | |
151 | echo === Invalid command - missing device and nodename === | |
152 | echo | |
153 | ||
e86e8697 | 154 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync', |
f2d7f16f | 155 | 'arguments': { 'snapshot-file':'${TEST_DIR}/1-${snapshot_virt0}', |
4089f7c6 JC |
156 | 'format': 'qcow2' } }" "error" |
157 | ||
158 | echo | |
159 | echo === Invalid command - missing snapshot-file === | |
160 | echo | |
161 | ||
e86e8697 JC |
162 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync', |
163 | 'arguments': { 'device': 'virtio0', | |
4089f7c6 JC |
164 | 'format': 'qcow2' } }" "error" |
165 | echo | |
166 | echo | |
167 | echo === Create several transactional group snapshots === | |
168 | echo | |
169 | ||
89e3a2d8 | 170 | for i in $(seq 2 ${SNAPSHOTS}) |
4089f7c6 JC |
171 | do |
172 | create_group_snapshot ${i} | |
173 | done | |
174 | ||
89e3a2d8 AG |
175 | # Tests for the blockdev-snapshot command |
176 | ||
177 | echo | |
178 | echo === Create a couple of snapshots using blockdev-snapshot === | |
179 | echo | |
180 | ||
181 | SNAPSHOTS=$((${SNAPSHOTS}+1)) | |
182 | add_snapshot_image ${SNAPSHOTS} | |
183 | blockdev_snapshot ${SNAPSHOTS} | |
184 | ||
185 | SNAPSHOTS=$((${SNAPSHOTS}+1)) | |
186 | add_snapshot_image ${SNAPSHOTS} | |
187 | blockdev_snapshot ${SNAPSHOTS} | |
188 | ||
3fa123d0 AG |
189 | echo |
190 | echo === Invalid command - cannot create a snapshot using a file BDS === | |
191 | echo | |
192 | ||
193 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot', | |
194 | 'arguments': { 'node':'virtio0', | |
195 | 'overlay':'file_${SNAPSHOTS}' } | |
196 | }" "error" | |
197 | ||
89e3a2d8 AG |
198 | echo |
199 | echo === Invalid command - snapshot node used as active layer === | |
200 | echo | |
201 | ||
202 | blockdev_snapshot ${SNAPSHOTS} error | |
203 | ||
204 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot', | |
205 | 'arguments': { 'node':'virtio0', | |
206 | 'overlay':'virtio0' } | |
207 | }" "error" | |
208 | ||
209 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot', | |
210 | 'arguments': { 'node':'virtio0', | |
211 | 'overlay':'virtio1' } | |
212 | }" "error" | |
213 | ||
214 | echo | |
215 | echo === Invalid command - snapshot node used as backing hd === | |
216 | echo | |
217 | ||
218 | blockdev_snapshot $((${SNAPSHOTS}-1)) error | |
219 | ||
220 | echo | |
221 | echo === Invalid command - snapshot node has a backing image === | |
222 | echo | |
223 | ||
224 | SNAPSHOTS=$((${SNAPSHOTS}+1)) | |
ecffa634 FZ |
225 | |
226 | TEST_IMG="$TEST_IMG.base" _make_test_img "$size" | |
227 | _make_test_img -b "${TEST_IMG}.base" "$size" | |
228 | do_blockdev_add ${SNAPSHOTS} "" "${TEST_IMG}" | |
89e3a2d8 AG |
229 | blockdev_snapshot ${SNAPSHOTS} error |
230 | ||
231 | echo | |
232 | echo === Invalid command - The node does not exist === | |
233 | echo | |
234 | ||
235 | blockdev_snapshot $((${SNAPSHOTS}+1)) error | |
236 | ||
237 | _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot', | |
238 | 'arguments': { 'node':'nodevice', | |
f2d7f16f | 239 | 'overlay':'snap_${SNAPSHOTS}' } |
89e3a2d8 AG |
240 | }" "error" |
241 | ||
4089f7c6 JC |
242 | # success, all done |
243 | echo "*** done" | |
244 | rm -f $seq.full | |
245 | status=0 |