596596 kill_nbd_server
597597}
598598
599+ test_import_nbd_stream_disconnected () {
600+ local dest_image=$1
601+ local migration_execute_pid
602+
603+ dd if=/dev/urandom of=${TEMPDIR} /large.raw bs=1M count=20480
604+ qemu-nbd -f raw --read-only --shared 10 --persistent --fork \
605+ ${TEMPDIR} /large.raw
606+
607+ cat > ${TEMPDIR} /spec.json << EOF
608+ {
609+ "type": "raw",
610+ "stream": {
611+ "type": "nbd",
612+ "uri": "nbd://localhost"
613+ }
614+ }
615+ EOF
616+ cat ${TEMPDIR} /spec.json
617+
618+ # server disappears while importing - abort
619+ rbd migration prepare --import-only \
620+ --source-spec-path ${TEMPDIR} /spec.json ${dest_image}
621+ rbd status ${dest_image} | grep ' state: prepared'
622+ qemu-img compare ${TEMPDIR} /large.raw rbd:rbd/${dest_image}
623+ rbd migration execute ${dest_image} &
624+ migration_execute_pid=$!
625+ sleep $(( 5 + RANDOM % 35 ))
626+ kill_nbd_server
627+ expect_false wait $migration_execute_pid
628+ expect_false rbd status ${dest_image}
629+ rbd migration abort ${dest_image}
630+
631+ qemu-nbd -f raw --read-only --shared 10 --persistent --fork \
632+ ${TEMPDIR} /large.raw
633+
634+ # server disappears while importing - resume
635+ rbd migration prepare --import-only \
636+ --source-spec-path ${TEMPDIR} /spec.json ${dest_image}
637+ rbd status ${dest_image} | grep ' state: prepared'
638+ qemu-img compare ${TEMPDIR} /large.raw rbd:rbd/${dest_image}
639+ rbd migration execute ${dest_image} &
640+ migration_execute_pid=$!
641+ sleep $(( 5 + RANDOM % 35 ))
642+ kill_nbd_server
643+ expect_false wait $migration_execute_pid
644+ expect_false rbd status ${dest_image}
645+ qemu-nbd -f raw --read-only --shared 10 --persistent --fork \
646+ ${TEMPDIR} /large.raw
647+ rbd status ${dest_image} | grep ' state: executing'
648+ qemu-img compare ${TEMPDIR} /large.raw rbd:rbd/${dest_image}
649+ rbd migration execute ${dest_image}
650+ rbd status ${dest_image} | grep ' state: executed'
651+ qemu-img compare ${TEMPDIR} /large.raw rbd:rbd/${dest_image}
652+ rbd migration commit ${dest_image}
653+ rbd status ${dest_image} | expect_false grep ' Migration:'
654+ qemu-img compare ${TEMPDIR} /large.raw rbd:rbd/${dest_image}
655+
656+ remove_image " ${dest_image} "
657+
658+ kill_nbd_server
659+ }
660+
599661# make sure rbd pool is EMPTY.. this is a test script!!
600662rbd ls 2>&1 | wc -l | grep -v ' ^0$' && echo " nonempty rbd pool, aborting! run this script on an empty test cluster only." && exit 1
601663
@@ -614,6 +676,8 @@ test_import_nbd_stream_qcow2 ${IMAGE2} ${IMAGE3}
614676test_import_raw_format ${IMAGE1} ${IMAGE2}
615677test_import_nbd_stream_raw ${IMAGE1} ${IMAGE2}
616678
679+ test_import_nbd_stream_disconnected ${IMAGE2}
680+
617681rbd namespace create rbd/${NAMESPACE1}
618682rbd namespace create rbd/${NAMESPACE2}
619683create_base_image rbd/${NAMESPACE1} /${IMAGE1}
0 commit comments