From 5b486d96284d8c72555753bde02537224534b2f3 Mon Sep 17 00:00:00 2001 From: Ning Yao Date: Sat, 25 Mar 2017 05:54:17 +0000 Subject: [PATCH] test: add test for rbd import,import-diff,copy with sparse-size option Signed-off-by: Ning Yao --- qa/workunits/rbd/cli_generic.sh | 34 ++++++++++- qa/workunits/rbd/import_export.sh | 97 +++++++++++++++++++++++++------ 2 files changed, 111 insertions(+), 20 deletions(-) diff --git a/qa/workunits/rbd/cli_generic.sh b/qa/workunits/rbd/cli_generic.sh index 84cacd405dc9..8e2a429a76a9 100755 --- a/qa/workunits/rbd/cli_generic.sh +++ b/qa/workunits/rbd/cli_generic.sh @@ -3,7 +3,7 @@ # make sure rbd pool is EMPTY.. this is a test script!! rbd ls | wc -l | grep -v '^0$' && echo "nonempty rbd pool, aborting! run this script on an empty test cluster only." && exit 1 -IMGS="testimg1 testimg2 testimg3 foo foo2 bar bar2 test1 test2 test3 clone2" +IMGS="testimg1 testimg2 testimg3 testimg-diff1 testimg-diff2 testimg-diff3 foo foo2 bar bar2 test1 test2 test3 clone2" tiered=0 if ceph osd dump | grep ^pool | grep "'rbd'" | grep tier; then @@ -20,7 +20,7 @@ remove_images() { test_others() { echo "testing import, export, resize, and snapshots..." - TMP_FILES="/tmp/img1 /tmp/img1.new /tmp/img2 /tmp/img2.new /tmp/img3 /tmp/img3.new /tmp/img1.snap1" + TMP_FILES="/tmp/img1 /tmp/img1.new /tmp/img2 /tmp/img2.new /tmp/img3 /tmp/img3.new /tmp/img-diff1.new /tmp/img-diff2.new /tmp/img-diff3.new /tmp/img1.snap1 /tmp/img1.snap1 /tmp/img-diff1.snap1" remove_images rm -f $TMP_FILES @@ -45,26 +45,54 @@ test_others() { rbd info testimg1 | grep 'size 128 MB' rbd info --snap=snap1 testimg1 | grep 'size 256 MB' + # export-diff + rbd export-diff testimg1 --snap=snap1 /tmp/diff-testimg1-1 + rbd export-diff testimg1 --from-snap=snap1 /tmp/diff-testimg1-2 + + # import-diff + rbd create $RBD_CREATE_ARGS --size=1 testimg-diff1 + rbd import-diff --sparse-size 8K /tmp/diff-testimg1-1 testimg-diff1 + rbd import-diff --sparse-size 8K /tmp/diff-testimg1-2 testimg-diff1 + + # info + rbd info testimg1 | grep 'size 128 MB' + rbd info --snap=snap1 testimg1 | grep 'size 256 MB' + rbd info testimg-diff1 | grep 'size 128 MB' + rbd info --snap=snap1 testimg-diff1 | grep 'size 256 MB' + # make copies rbd copy testimg1 --snap=snap1 testimg2 rbd copy testimg1 testimg3 + rbd copy testimg-diff1 --sparse-size 768K --snap=snap1 testimg-diff2 + rbd copy testimg-diff1 --sparse-size 768K testimg-diff3 # verify the result rbd info testimg2 | grep 'size 256 MB' rbd info testimg3 | grep 'size 128 MB' + rbd info testimg-diff2 | grep 'size 256 MB' + rbd info testimg-diff3 | grep 'size 128 MB' rbd export testimg1 /tmp/img1.new rbd export testimg2 /tmp/img2.new rbd export testimg3 /tmp/img3.new + rbd export testimg-diff1 /tmp/img-diff1.new + rbd export testimg-diff2 /tmp/img-diff2.new + rbd export testimg-diff3 /tmp/img-diff3.new cmp /tmp/img2 /tmp/img2.new cmp /tmp/img3 /tmp/img3.new + cmp /tmp/img2 /tmp/img-diff2.new + cmp /tmp/img3 /tmp/img-diff3.new # rollback rbd snap rollback --snap=snap1 testimg1 + rbd snap rollback --snap=snap1 testimg-diff1 rbd info testimg1 | grep 'size 256 MB' + rbd info testimg-diff1 | grep 'size 256 MB' rbd export testimg1 /tmp/img1.snap1 + rbd export testimg-diif1 /tmp/img-diff1.snap1 cmp /tmp/img2 /tmp/img1.snap1 + cmp /tmp/img2 /tmp/img-diff1.snap1 # test create, copy of zero-length images rbd rm testimg2 @@ -74,7 +102,9 @@ test_others() { # remove snapshots rbd snap rm --snap=snap1 testimg1 + rbd snap rm --snap=snap1 testimg-diff1 rbd info --snap=snap1 testimg1 2>&1 | grep 'error setting snapshot context: (2) No such file or directory' + rbd info --snap=snap1 testimg-diff1 2>&1 | grep 'error setting snapshot context: (2) No such file or directory' remove_images rm -f $TMP_FILES diff --git a/qa/workunits/rbd/import_export.sh b/qa/workunits/rbd/import_export.sh index 7b56c23b90cc..a5190e1b8180 100755 --- a/qa/workunits/rbd/import_export.sh +++ b/qa/workunits/rbd/import_export.sh @@ -145,18 +145,24 @@ if ceph osd dump | grep ^pool | grep "'rbd'" | grep tier; then fi # create specifically sparse files -# 1 1M block of sparse, 1 1M block of random +# 1 1M block of sparse, 1 1M block of random, 1 1M block of zero, 1 1M block of random dd if=/dev/urandom bs=1M seek=1 count=1 of=${TMPDIR}/sparse1 +dd if=/dev/zero bs=1M seek=2 count=1 of=${TMPDIR}/sparse1 +dd if=/dev/urandom bs=1M seek=3 count=1 of=${TMPDIR}/sparse1 -# 1 1M block of random, 1 1M block of sparse -dd if=/dev/urandom bs=1M count=1 of=${TMPDIR}/sparse2; truncate ${TMPDIR}/sparse2 -s 2M +# 1 1M block of random, 1 1M block of sparse, 1 1M block of zero, 1 1M block of sparse +dd if=/dev/urandom bs=1M count=1 of=${TMPDIR}/sparse2; +dd if=/dev/zero bs=1M seek=2 count=1 of=${TMPDIR}/sparse2; truncate ${TMPDIR}/sparse2 -s 4M # 1M-block images; validate resulting blocks -# 1M sparse, 1M data -rbd import $RBD_CREATE_ARGS --order 20 ${TMPDIR}/sparse1 -rbd ls -l | grep sparse1 | grep -i '2048k' -[ $tiered -eq 1 -o "$(objects sparse1)" = '1' ] +# 1M sparse, 1M data, 1M zero, 1M data, with 4K sparse-size +rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 4K ${TMPDIR}/sparse1 +rbd ls -l | grep sparse1 | grep -i '4096k' +rbd du sparse1 | grep '4096k 4096k' +rbd diff sparse1 | grep '1048576 1048576 data' +rbd diff sparse1 | grep '3145728 1048576 data' +[ $tiered -eq 1 -o "$(objects sparse1)" = '1 3' ] # export, compare contents and on-disk size rbd export sparse1 ${TMPDIR}/sparse1.out @@ -164,9 +170,36 @@ compare_files_and_ondisk_sizes ${TMPDIR}/sparse1 ${TMPDIR}/sparse1.out rm ${TMPDIR}/sparse1.out rbd rm sparse1 -# 1M data, 1M sparse -rbd import $RBD_CREATE_ARGS --order 20 ${TMPDIR}/sparse2 -rbd ls -l | grep sparse2 | grep -i '2048k' +# 1M sparse, 1M data, 1M zero, 1M data, with 2M sparse-size +rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 2M ${TMPDIR}/sparse1 +rbd ls -l | grep sparse1 | grep -i '4096k' +rbd du sparse1 | grep '4096k 4096k' +rbd diff sparse1 | grep '0 2097152 data' +rbd diff sparse1 | grep '2097152 2097152 data' +[ $tiered -eq 1 -o "$(objects sparse1)" = '1 3' ] + +# export, compare contents and on-disk size +rbd export sparse1 ${TMPDIR}/sparse1.out +compare_files_and_ondisk_sizes ${TMPDIR}/sparse1 ${TMPDIR}/sparse1.out +rm ${TMPDIR}/sparse1.out +rbd rm sparse1 + +# 1M data, 1M sparse, 1M zero, 1M sparse, with 4K sparse-size +rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 4K ${TMPDIR}/sparse2 +rbd ls -l | grep sparse2 | grep -i '4096k' +rbd du sparse2 | grep '4096k 2048k' +rbd diff sparse2 | grep '0 1048576 data' +[ $tiered -eq 1 -o "$(objects sparse2)" = '0' ] +rbd export sparse2 ${TMPDIR}/sparse2.out +compare_files_and_ondisk_sizes ${TMPDIR}/sparse2 ${TMPDIR}/sparse2.out +rm ${TMPDIR}/sparse2.out +rbd rm sparse2 + +# 1M data, 1M sparse, 1M zero, 1M sparse, with 2M sparse-size +rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 2M ${TMPDIR}/sparse2 +rbd ls -l | grep sparse2 | grep -i '4096k' +rbd du sparse2 | grep '4096k 2048k' +rbd diff sparse2 | grep '0 2097152 data' [ $tiered -eq 1 -o "$(objects sparse2)" = '0' ] rbd export sparse2 ${TMPDIR}/sparse2.out compare_files_and_ondisk_sizes ${TMPDIR}/sparse2 ${TMPDIR}/sparse2.out @@ -176,20 +209,48 @@ rbd rm sparse2 # extend sparse1 to 10 1M blocks, sparse at the end truncate ${TMPDIR}/sparse1 -s 10M # import from stdin just for fun, verify still sparse -rbd import $RBD_CREATE_ARGS --order 20 - sparse1 < ${TMPDIR}/sparse1 +rbd import $RBD_CREATE_ARGS --order 21 - sparse1 < ${TMPDIR}/sparse1 +rbd ls -l | grep sparse1 | grep -i '10240k' +rbd du sparse1 | grep '10240k 4096k' +rbd diff sparse1 | grep '1048576 1048576 data' +rbd diff sparse1 | grep '3145728 1048576 data' +[ $tiered -eq 1 -o "$(objects sparse1)" = '1 3' ] +rbd export sparse1 ${TMPDIR}/sparse1.out +compare_files_and_ondisk_sizes ${TMPDIR}/sparse1 ${TMPDIR}/sparse1.out +rm ${TMPDIR}/sparse1.out +rbd rm sparse1 +# import from stdin just for fun, verify still sparse +rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 2M - sparse1 < ${TMPDIR}/sparse1 rbd ls -l | grep sparse1 | grep -i '10240k' -[ $tiered -eq 1 -o "$(objects sparse1)" = '1' ] +rbd du sparse1 | grep '10240k 4096k' +rbd diff sparse1 | grep '0 2097152 data' +rbd diff sparse1 | grep '2097152 2097152 data' +[ $tiered -eq 1 -o "$(objects sparse1)" = '1 3' ] rbd export sparse1 ${TMPDIR}/sparse1.out compare_files_and_ondisk_sizes ${TMPDIR}/sparse1 ${TMPDIR}/sparse1.out rm ${TMPDIR}/sparse1.out rbd rm sparse1 -# extend sparse2 to 4M total with two more nonsparse megs +# extend sparse2 to 6M total with two more nonsparse megs dd if=/dev/urandom bs=2M count=1 of=${TMPDIR}/sparse2 oflag=append conv=notrunc # again from stding -rbd import $RBD_CREATE_ARGS --order 20 - sparse2 < ${TMPDIR}/sparse2 -rbd ls -l | grep sparse2 | grep -i '4096k' -[ $tiered -eq 1 -o "$(objects sparse2)" = '0 2 3' ] +rbd import $RBD_CREATE_ARGS --order 21 - sparse2 < ${TMPDIR}/sparse2 +rbd ls -l | grep sparse2 | grep -i '6144k' +rbd du sparse2 | grep '6144k 4096k' +rbd diff sparse2 | grep '0 1048576 data' +rbd diff sparse2 | grep '4194304 2097152 data' +[ $tiered -eq 1 -o "$(objects sparse2)" = '0 4 5' ] +rbd export sparse2 ${TMPDIR}/sparse2.out +compare_files_and_ondisk_sizes ${TMPDIR}/sparse2 ${TMPDIR}/sparse2.out +rm ${TMPDIR}/sparse2.out +rbd rm sparse2 +# again from stding +rbd import $RBD_CREATE_ARGS --order 21 --sparse-size 2M - sparse2 < ${TMPDIR}/sparse2 +rbd ls -l | grep sparse2 | grep -i '6144k' +rbd du sparse2 | grep '6144k 4096k' +rbd diff sparse2 | grep '0 2097152 data' +rbd diff sparse2 | grep '4194304 2097152 data' +[ $tiered -eq 1 -o "$(objects sparse2)" = '0 4 5' ] rbd export sparse2 ${TMPDIR}/sparse2.out compare_files_and_ondisk_sizes ${TMPDIR}/sparse2 ${TMPDIR}/sparse2.out rm ${TMPDIR}/sparse2.out @@ -201,7 +262,7 @@ rbd rm sparse2 echo "partially-sparse file imports to partially-sparse image" rbd import $RBD_CREATE_ARGS --order 20 ${TMPDIR}/sparse1 sparse -[ $tiered -eq 1 -o "$(objects sparse)" = '1' ] +[ $tiered -eq 1 -o "$(objects sparse)" = '1 3' ] rbd rm sparse echo "zeros import through stdin to sparse image" @@ -221,7 +282,7 @@ dd if=/dev/zero bs=4M count=1 | rados -p $(get_image_data_pool sparse) \ # 1 object full of zeros; export should still create 0-disk-usage file rm ${TMPDIR}/sparse || true rbd export sparse ${TMPDIR}/sparse -[ $(stat ${TMPDIR}/sparse --format=%b) = '0' ] +[ $(stat ${TMPDIR}/sparse --format=%b) = '0' ] rbd rm sparse rm ${TMPDIR}/sparse ${TMPDIR}/sparse1 ${TMPDIR}/sparse2 ${TMPDIR}/sparse3 || true -- 2.47.3