@@ -22,6 +22,10 @@ cleanup_tempdir() {
2222 rm -rf ${TEMPDIR}
2323}
2424
25+ expect_false () {
26+ if " $@ " ; then return 1; else return 0; fi
27+ }
28+
2529create_base_image () {
2630 local image=$1
2731
124128
125129 rbd migration abort ${dest_image}
126130
131+ # no snap name or snap id
132+ expect_false rbd migration prepare --import-only \
133+ --source-spec " {\" type\" : \" native\" , \" pool_id\" : ${pool_id} , \" image_name\" : \" ${base_image} \" }" \
134+ ${dest_image}
135+
136+ # invalid source spec JSON
137+ expect_false rbd migration prepare --import-only \
138+ --source-spec " {\" type\" : \" native\" , \" pool_id\" : ${pool_id} , \" image_name\" : \" ${base_image} \" , \" snap_name\" : non-existing}" \
139+ ${dest_image}
140+
141+ # non-existing snap name
142+ expect_false rbd migration prepare --import-only \
143+ --source-spec " {\" type\" : \" native\" , \" pool_id\" : ${pool_id} , \" image_name\" : \" ${base_image} \" , \" snap_name\" : \" non-existing\" }" \
144+ ${dest_image}
145+
146+ # invalid snap name
147+ expect_false rbd migration prepare --import-only \
148+ --source-spec " {\" type\" : \" native\" , \" pool_id\" : ${pool_id} , \" image_name\" : \" ${base_image} \" , \" snap_name\" : 123456}" \
149+ ${dest_image}
150+
151+ # non-existing snap id passed as int
152+ expect_false rbd migration prepare --import-only \
153+ --source-spec " {\" type\" : \" native\" , \" pool_id\" : ${pool_id} , \" image_name\" : \" ${base_image} \" , \" snap_id\" : 123456}" \
154+ ${dest_image}
155+
156+ # non-existing snap id passed as string
157+ expect_false rbd migration prepare --import-only \
158+ --source-spec " {\" type\" : \" native\" , \" pool_id\" : ${pool_id} , \" image_name\" : \" ${base_image} \" , \" snap_id\" : \" 123456\" }" \
159+ ${dest_image}
160+
161+ # invalid snap id
162+ expect_false rbd migration prepare --import-only \
163+ --source-spec " {\" type\" : \" native\" , \" pool_id\" : ${pool_id} , \" image_name\" : \" ${base_image} \" , \" snap_id\" : \" foobar\" }" \
164+ ${dest_image}
165+
166+ # snap id passed as int
167+ local snap_id=$( rbd snap ls ${base_image} --format xml | xmlstarlet sel -t -v " //snapshots/snapshot[name='2']/id" )
168+ rbd migration prepare --import-only \
169+ --source-spec " {\" type\" : \" native\" , \" pool_id\" : ${pool_id} , \" image_name\" : \" ${base_image} \" , \" snap_id\" : ${snap_id} }" \
170+ ${dest_image}
171+ rbd migration abort ${dest_image}
172+
173+ # snap id passed as string
174+ rbd migration prepare --import-only \
175+ --source-spec " {\" type\" : \" native\" , \" pool_id\" : ${pool_id} , \" image_name\" : \" ${base_image} \" , \" snap_id\" : \" ${snap_id} \" }" \
176+ ${dest_image}
177+ rbd migration abort ${dest_image}
178+
127179 rbd migration prepare --import-only \
128- --source-spec " {\" type\" : \" native\" , \" pool_id\" : " ${pool_id} " , \" image_name\" : \" ${base_image} \" , \" snap_name\" : \" 2\" }" \
180+ --source-spec " {\" type\" : \" native\" , \" pool_id\" : ${pool_id} , \" image_name\" : \" ${base_image} \" , \" snap_name\" : \" 2\" }" \
129181 ${dest_image}
130182 rbd migration abort ${dest_image}
131183
0 commit comments