cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From 05d14f4ff759eed41146cc17688db92656388552 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Wed, 6 Nov 2013 16:53:31 +0100
9ae3a8
Subject: [PATCH 74/87] qemu-iotests: Add basic ability to use binary sample images
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383756824-6921-9-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55563
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 08/21] qemu-iotests: Add basic ability to use binary sample images
9ae3a8
Bugzilla: 980771
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
9ae3a8
From: Jeff Cody <jcody@redhat.com>
9ae3a8
9ae3a8
BZ: 980771
9ae3a8
9ae3a8
For image formats that are not "QEMU native", but supported for
9ae3a8
compatibility, it is useful to verify that an image created with
9ae3a8
the 'gold standard' native tool can be read / written to successfully
9ae3a8
by QEMU.
9ae3a8
9ae3a8
In addition to testing non-native images, this could also be useful to
9ae3a8
test against image files created by older versions of QEMU.
9ae3a8
9ae3a8
This provides a directory to store small sample images, for use by
9ae3a8
scripts in tests/qemu-iotests.
9ae3a8
9ae3a8
Image files should be compressed with bzip2.
9ae3a8
9ae3a8
To use a sample image from a bash script, the _use_sample_img function
9ae3a8
will copy and decompress the image into $TEST_DIR, and set $TEST_IMG to
9ae3a8
be the decompressed sample image copy.  To cleanup, call
9ae3a8
_cleanup_test_img as normal.
9ae3a8
9ae3a8
Signed-off-by: Jeff Cody <jcody@redhat.com>
9ae3a8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 85edbd375b9ab451c6769011cb6b3e0287dc71e4)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 tests/qemu-iotests/common.config        | 11 +++++++++++
9ae3a8
 tests/qemu-iotests/common.rc            | 16 ++++++++++++++++
9ae3a8
 tests/qemu-iotests/sample_images/README |  8 ++++++++
9ae3a8
 3 files changed, 35 insertions(+)
9ae3a8
 create mode 100644 tests/qemu-iotests/sample_images/README
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 tests/qemu-iotests/common.config        |   11 +++++++++++
9ae3a8
 tests/qemu-iotests/common.rc            |   16 ++++++++++++++++
9ae3a8
 tests/qemu-iotests/sample_images/README |    8 ++++++++
9ae3a8
 3 files changed, 35 insertions(+), 0 deletions(-)
9ae3a8
 create mode 100644 tests/qemu-iotests/sample_images/README
9ae3a8
9ae3a8
diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config
9ae3a8
index d794e62..d90a8bc 100644
9ae3a8
--- a/tests/qemu-iotests/common.config
9ae3a8
+++ b/tests/qemu-iotests/common.config
9ae3a8
@@ -125,6 +125,17 @@ fi
9ae3a8
 
9ae3a8
 export TEST_DIR
9ae3a8
 
9ae3a8
+if [ -z "$SAMPLE_IMG_DIR" ]; then
9ae3a8
+        SAMPLE_IMG_DIR=`pwd`/sample_images
9ae3a8
+fi
9ae3a8
+
9ae3a8
+if [ ! -d "$SAMPLE_IMG_DIR" ]; then
9ae3a8
+    echo "common.config: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory"
9ae3a8
+    exit 1
9ae3a8
+fi
9ae3a8
+
9ae3a8
+export SAMPLE_IMG_DIR
9ae3a8
+
9ae3a8
 _readlink()
9ae3a8
 {
9ae3a8
     if [ $# -ne 1 ]; then
9ae3a8
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
9ae3a8
index 28b39e4..6730955 100644
9ae3a8
--- a/tests/qemu-iotests/common.rc
9ae3a8
+++ b/tests/qemu-iotests/common.rc
9ae3a8
@@ -91,6 +91,18 @@ _set_default_imgopts()
9ae3a8
     fi
9ae3a8
 }
9ae3a8
 
9ae3a8
+_use_sample_img()
9ae3a8
+{
9ae3a8
+    SAMPLE_IMG_FILE="${1%\.bz2}"
9ae3a8
+    TEST_IMG="$TEST_DIR/$SAMPLE_IMG_FILE"
9ae3a8
+    bzcat "$SAMPLE_IMG_DIR/$1" > "$TEST_IMG"
9ae3a8
+    if [ $? -ne 0 ]
9ae3a8
+    then
9ae3a8
+        echo "_use_sample_img error, cannot extract '$SAMPLE_IMG_DIR/$1'"
9ae3a8
+        exit 1
9ae3a8
+    fi
9ae3a8
+}
9ae3a8
+
9ae3a8
 _make_test_img()
9ae3a8
 {
9ae3a8
     # extra qemu-img options can be added by tests
9ae3a8
@@ -158,6 +170,10 @@ _cleanup_test_img()
9ae3a8
             rm -f $TEST_DIR/t.$IMGFMT
9ae3a8
             rm -f $TEST_DIR/t.$IMGFMT.orig
9ae3a8
             rm -f $TEST_DIR/t.$IMGFMT.base
9ae3a8
+            if [ -n "$SAMPLE_IMG_FILE" ]
9ae3a8
+            then
9ae3a8
+                rm -f "$TEST_DIR/$SAMPLE_IMG_FILE"
9ae3a8
+            fi
9ae3a8
             ;;
9ae3a8
 
9ae3a8
         rbd)
9ae3a8
diff --git a/tests/qemu-iotests/sample_images/README b/tests/qemu-iotests/sample_images/README
9ae3a8
new file mode 100644
9ae3a8
index 0000000..507af5f
9ae3a8
--- /dev/null
9ae3a8
+++ b/tests/qemu-iotests/sample_images/README
9ae3a8
@@ -0,0 +1,8 @@
9ae3a8
+This is for small sample images to be used with qemu-iotests, intended for
9ae3a8
+non-native formats that QEMU supports for compatibility.  The idea is to use
9ae3a8
+the native tool to create the sample image.
9ae3a8
+
9ae3a8
+For instance, a VHDX image in this directory would be an image created not by
9ae3a8
+QEMU itself, but rather created by Hyper-V.
9ae3a8
+
9ae3a8
+Sample images added here must be compressed with bzip2.
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8