From f85a291fcb70c744549e0dcb6d5c8c744480ed6a Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 14 Oct 2020 16:34:35 +0800 Subject: [PATCH] selftest: Fix qcow2 image format detect qemu-img will report "qcow2" or "qcow2 backing qcow2" for qcow2 image, cover both case. Signed-off-by: Kairui Song --- tests/scripts/image-init-lib.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/scripts/image-init-lib.sh b/tests/scripts/image-init-lib.sh index 09ad940..0a1524b 100644 --- a/tests/scripts/image-init-lib.sh +++ b/tests/scripts/image-init-lib.sh @@ -61,6 +61,10 @@ get_image_fmt() { return 1 } +fmt_is_qcow2() { + [ "$1" == "qcow2" ] || [ "$1" == "qcow2 backing qcow2" ] +} + # If it's partitioned, return the mountable partition, else return the dev get_mountable_dev() { local dev=$1 parts @@ -143,7 +147,7 @@ mount_image() { dev="$($SUDO losetup --show -f $image)" [ $? -ne 0 ] || [ -z "$dev" ] && perror_exit "failed to setup loop device" - elif [ "$fmt" == "qcow2" ]; then + elif fmt_is_qcow2 "$fmt"; then prepare_nbd dev=$(mount_nbd $image) @@ -234,11 +238,11 @@ create_image_from_base_image() { local image_fmt=$(get_image_fmt $image) if [ "$image_fmt" != "raw" ]; then - if [ "$image_fmt" == "qcow2" ]; then + if fmt_is_qcow2 "$image_fmt"; then echo "Source image is qcow2, using snapshot..." qemu-img create -f qcow2 -b $image $output else - perror_exit "Unrecognized base image format $image_mnt" + perror_exit "Unrecognized base image format '$image_mnt'" fi else echo "Source image is raw, converting to qcow2..."