From d92e8116819aaa56a13b3ee397c798b78d179f5b Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Wed, 21 Aug 2024 21:16:30 +0200 Subject: [PATCH] qa/workunits/rbd: exercise snap_{name,id} parsing in test_import_native_format() Signed-off-by: Ilya Dryomov (cherry picked from commit 4a6800f1468df5a33802e15c9ea5d7c3ce8ddf2a) --- qa/workunits/rbd/cli_migration.sh | 54 ++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/qa/workunits/rbd/cli_migration.sh b/qa/workunits/rbd/cli_migration.sh index 3d598de5af73d..c6acc8a38ab2a 100755 --- a/qa/workunits/rbd/cli_migration.sh +++ b/qa/workunits/rbd/cli_migration.sh @@ -22,6 +22,10 @@ cleanup_tempdir() { rm -rf ${TEMPDIR} } +expect_false() { + if "$@"; then return 1; else return 0; fi +} + create_base_image() { local image=$1 @@ -127,8 +131,56 @@ EOF rbd migration abort ${dest_image} + # no snap name or snap id + expect_false rbd migration prepare --import-only \ + --source-spec "{\"type\": \"native\", \"pool_id\": ${pool_id}, \"image_name\": \"${base_image}\"}" \ + ${dest_image} + + # invalid source spec JSON + expect_false rbd migration prepare --import-only \ + --source-spec "{\"type\": \"native\", \"pool_id\": ${pool_id}, \"image_name\": \"${base_image}\", \"snap_name\": non-existing}" \ + ${dest_image} + + # non-existing snap name + expect_false rbd migration prepare --import-only \ + --source-spec "{\"type\": \"native\", \"pool_id\": ${pool_id}, \"image_name\": \"${base_image}\", \"snap_name\": \"non-existing\"}" \ + ${dest_image} + + # invalid snap name + expect_false rbd migration prepare --import-only \ + --source-spec "{\"type\": \"native\", \"pool_id\": ${pool_id}, \"image_name\": \"${base_image}\", \"snap_name\": 123456}" \ + ${dest_image} + + # non-existing snap id passed as int + expect_false rbd migration prepare --import-only \ + --source-spec "{\"type\": \"native\", \"pool_id\": ${pool_id}, \"image_name\": \"${base_image}\", \"snap_id\": 123456}" \ + ${dest_image} + + # non-existing snap id passed as string + expect_false rbd migration prepare --import-only \ + --source-spec "{\"type\": \"native\", \"pool_id\": ${pool_id}, \"image_name\": \"${base_image}\", \"snap_id\": \"123456\"}" \ + ${dest_image} + + # invalid snap id + expect_false rbd migration prepare --import-only \ + --source-spec "{\"type\": \"native\", \"pool_id\": ${pool_id}, \"image_name\": \"${base_image}\", \"snap_id\": \"foobar\"}" \ + ${dest_image} + + # snap id passed as int + local snap_id=$(rbd snap ls ${base_image} --format xml | xmlstarlet sel -t -v "//snapshots/snapshot[name='2']/id") + rbd migration prepare --import-only \ + --source-spec "{\"type\": \"native\", \"pool_id\": ${pool_id}, \"image_name\": \"${base_image}\", \"snap_id\": ${snap_id}}" \ + ${dest_image} + rbd migration abort ${dest_image} + + # snap id passed as string + rbd migration prepare --import-only \ + --source-spec "{\"type\": \"native\", \"pool_id\": ${pool_id}, \"image_name\": \"${base_image}\", \"snap_id\": \"${snap_id}\"}" \ + ${dest_image} + rbd migration abort ${dest_image} + rbd migration prepare --import-only \ - --source-spec "{\"type\": \"native\", \"pool_id\": "${pool_id}", \"image_name\": \"${base_image}\", \"snap_name\": \"2\"}" \ + --source-spec "{\"type\": \"native\", \"pool_id\": ${pool_id}, \"image_name\": \"${base_image}\", \"snap_name\": \"2\"}" \ ${dest_image} rbd migration abort ${dest_image} -- 2.39.5