4 . $
(dirname $0)/..
/..
/standalone
/ceph-helpers.sh
10 IMAGES
="${IMAGE1} ${IMAGE2} ${IMAGE3}"
28 rbd create
--size 1G
${image}
29 rbd bench
--io-type write --io-pattern rand
--io-size=4K
--io-total 256M
${image}
30 rbd snap create
${image}@
1
31 rbd bench
--io-type write --io-pattern rand
--io-size=4K
--io-total 64M
${image}
32 rbd snap create
${image}@
2
33 rbd bench
--io-type write --io-pattern rand
--io-size=4K
--io-total 128M
${image}
39 rm -rf "${TEMPDIR}/${image}"
40 rbd
export ${image} "${TEMPDIR}/${image}"
46 export_raw_image "${image}"
47 export_raw_image "${image}@
1"
48 export_raw_image "${image}@
2"
54 (rbd migration abort $image || true) >/dev/null 2>&1
55 (rbd snap purge $image || true) >/dev/null 2>&1
56 (rbd rm $image || true) >/dev/null 2>&1
60 for image in ${IMAGES}
71 xxd "${file1}" > "${file1}.xxd
"
72 xxd "${file2}" > "${file2}.xxd
"
73 sdiff -s "${file1}.xxd
" "${file2}.xxd
" | head -n 64
74 rm -f "${file1}.xxd
" "${file2}.xxd
"
82 export_raw_image ${dst_image}
83 if ! cmp "${TEMPDIR}/${src_image}" "${TEMPDIR}/${dst_image}"
85 show_diff "${TEMPDIR}/${src_image}" "${TEMPDIR}/${dst_image}"
91 test_import_native_format() {
95 rbd migration prepare --import-only "rbd
/${base_image}@
2" ${dest_image}
96 rbd migration abort ${dest_image}
98 local pool_id=$(ceph osd pool ls detail --format xml | xmlstarlet sel -t -v "//pools
/pool
[pool_name
='rbd']/pool_id
")
99 cat > ${TEMPDIR}/spec.json <<EOF
102 "pool_id
": ${pool_id},
103 "pool_namespace
": "",
104 "image_name
": "${base_image}",
108 cat ${TEMPDIR}/spec.json
110 rbd migration prepare --import-only \
111 --source-spec-path ${TEMPDIR}/spec.json ${dest_image}
113 compare_images "${base_image}@
1" "${dest_image}@
1"
114 compare_images "${base_image}@
2" "${dest_image}@
2"
116 rbd migration abort ${dest_image}
118 rbd migration prepare --import-only \
119 --source-spec-path ${TEMPDIR}/spec.json ${dest_image}
120 rbd migration execute ${dest_image}
122 compare_images "${base_image}@
1" "${dest_image}@
1"
123 compare_images "${base_image}@
2" "${dest_image}@
2"
125 rbd migration abort ${dest_image}
127 rbd migration prepare --import-only \
128 --source-spec "{\"type\": \"native
\", \"pool_id
\": "${pool_id}", \"image_name\": \"${base_image}\", \"snap_name\": \"2\"}" \
130 rbd migration abort
${dest_image}
132 rbd migration prepare
--import-only \
133 --source-spec "{\"type\": \"native\", \"pool_name\": \"rbd\", \"image_name\": \"${base_image}\", \"snap_name\": \"2\"}" \
135 rbd migration execute
${dest_image}
136 rbd migration commit
${dest_image}
138 compare_images
"${base_image}@1" "${dest_image}@1"
139 compare_images
"${base_image}@2" "${dest_image}@2"
141 remove_image
"${dest_image}"
144 test_import_qcow_format
() {
148 if ! qemu-img convert
-f raw
-O qcow rbd
:rbd
/${base_image} ${TEMPDIR}/${base_image}.qcow
; then
149 echo "skipping QCOW test"
152 qemu-img info
-f qcow
${TEMPDIR}/${base_image}.qcow
154 cat > ${TEMPDIR}/spec.json
<<EOF
159 "file_path": "${TEMPDIR}/${base_image}.qcow"
163 cat ${TEMPDIR}/spec.json
166 rbd migration prepare
--import-only \
167 --source-spec-path ${TEMPDIR}/spec.json
${dest_image}
171 if [ $error_code -eq 95 ]; then
172 echo "skipping QCOW test (librbd support disabled)"
175 test $error_code -eq 0
177 compare_images
"${base_image}" "${dest_image}"
179 rbd migration abort
${dest_image}
181 rbd migration prepare
--import-only \
182 --source-spec-path ${TEMPDIR}/spec.json
${dest_image}
184 compare_images
"${base_image}" "${dest_image}"
186 rbd migration execute
${dest_image}
188 compare_images
"${base_image}" "${dest_image}"
190 rbd migration commit
${dest_image}
192 compare_images
"${base_image}" "${dest_image}"
194 remove_image
"${dest_image}"
197 test_import_qcow2_format
() {
201 # create new image via qemu-img and its bench tool since we cannot
202 # import snapshot deltas into QCOW2
203 qemu-img create
-f qcow2
${TEMPDIR}/${base_image}.qcow2
1G
205 qemu-img bench
-f qcow2
-w -c 65536 -d 16 --pattern 65 -s 4096 \
206 -S $
((($RANDOM % 262144) * 4096)) ${TEMPDIR}/${base_image}.qcow2
207 qemu-img convert
-f qcow2
-O raw
${TEMPDIR}/${base_image}.qcow2 \
208 "${TEMPDIR}/${base_image}@snap1"
209 qemu-img snapshot
-c "snap1" ${TEMPDIR}/${base_image}.qcow2
211 qemu-img bench
-f qcow2
-w -c 16384 -d 16 --pattern 66 -s 4096 \
212 -S $
((($RANDOM % 262144) * 4096)) ${TEMPDIR}/${base_image}.qcow2
213 qemu-img convert
-f qcow2
-O raw
${TEMPDIR}/${base_image}.qcow2 \
214 "${TEMPDIR}/${base_image}@snap2"
215 qemu-img snapshot
-c "snap2" ${TEMPDIR}/${base_image}.qcow2
217 qemu-img bench
-f qcow2
-w -c 32768 -d 16 --pattern 67 -s 4096 \
218 -S $
((($RANDOM % 262144) * 4096)) ${TEMPDIR}/${base_image}.qcow2
219 qemu-img convert
-f qcow2
-O raw
${TEMPDIR}/${base_image}.qcow2 \
220 ${TEMPDIR}/${base_image}
222 qemu-img info
-f qcow2
${TEMPDIR}/${base_image}.qcow2
224 cat > ${TEMPDIR}/spec.json
<<EOF
229 "file_path": "${TEMPDIR}/${base_image}.qcow2"
233 cat ${TEMPDIR}/spec.json
235 rbd migration prepare
--import-only \
236 --source-spec-path ${TEMPDIR}/spec.json
${dest_image}
238 compare_images
"${base_image}@snap1" "${dest_image}@snap1"
239 compare_images
"${base_image}@snap2" "${dest_image}@snap2"
240 compare_images
"${base_image}" "${dest_image}"
242 rbd migration abort
${dest_image}
244 rbd migration prepare
--import-only \
245 --source-spec-path ${TEMPDIR}/spec.json
${dest_image}
247 compare_images
"${base_image}@snap1" "${dest_image}@snap1"
248 compare_images
"${base_image}@snap2" "${dest_image}@snap2"
249 compare_images
"${base_image}" "${dest_image}"
251 rbd migration execute
${dest_image}
253 compare_images
"${base_image}@snap1" "${dest_image}@snap1"
254 compare_images
"${base_image}@snap2" "${dest_image}@snap2"
255 compare_images
"${base_image}" "${dest_image}"
257 rbd migration commit
${dest_image}
259 compare_images
"${base_image}@snap1" "${dest_image}@snap1"
260 compare_images
"${base_image}@snap2" "${dest_image}@snap2"
261 compare_images
"${base_image}" "${dest_image}"
263 remove_image
"${dest_image}"
266 test_import_raw_format
() {
270 cat > ${TEMPDIR}/spec.json
<<EOF
275 "file_path": "${TEMPDIR}/${base_image}"
279 cat ${TEMPDIR}/spec.json
281 cat ${TEMPDIR}/spec.json | rbd migration prepare
--import-only \
282 --source-spec-path - ${dest_image}
283 compare_images
${base_image} ${dest_image}
284 rbd migration abort
${dest_image}
286 rbd migration prepare
--import-only \
287 --source-spec-path ${TEMPDIR}/spec.json
${dest_image}
288 rbd migration execute
${dest_image}
289 rbd migration commit
${dest_image}
291 compare_images
${base_image} ${dest_image}
293 remove_image
"${dest_image}"
295 cat > ${TEMPDIR}/spec.json
<<EOF
300 "file_path": "${TEMPDIR}/${base_image}"
307 "file_path": "${TEMPDIR}/${base_image}@1"
314 "file_path": "${TEMPDIR}/${base_image}@2"
319 cat ${TEMPDIR}/spec.json
321 rbd migration prepare
--import-only \
322 --source-spec-path ${TEMPDIR}/spec.json
${dest_image}
324 rbd snap create
${dest_image}@
head
325 rbd bench
--io-type write --io-pattern rand
--io-size=32K
--io-total=32M
${dest_image}
327 compare_images
"${base_image}" "${dest_image}@head"
328 compare_images
"${base_image}@1" "${dest_image}@snap1"
329 compare_images
"${base_image}@2" "${dest_image}@snap2"
330 compare_images
"${base_image}" "${dest_image}@head"
332 rbd migration execute
${dest_image}
334 compare_images
"${base_image}@1" "${dest_image}@snap1"
335 compare_images
"${base_image}@2" "${dest_image}@snap2"
336 compare_images
"${base_image}" "${dest_image}@head"
338 rbd migration commit
${dest_image}
340 remove_image
"${dest_image}"
343 # make sure rbd pool is EMPTY.. this is a test script!!
344 rbd
ls 2>&1 |
wc -l |
grep -v '^0$' && echo "nonempty rbd pool, aborting! run this script on an empty test cluster only." && exit 1
347 trap 'cleanup $?' INT TERM EXIT
349 create_base_image
${IMAGE1}
350 export_base_image
${IMAGE1}
352 test_import_native_format
${IMAGE1} ${IMAGE2}
353 test_import_qcow_format
${IMAGE1} ${IMAGE2}
354 test_import_qcow2_format
${IMAGE2} ${IMAGE3}
355 test_import_raw_format
${IMAGE1} ${IMAGE2}