Blame SOURCES/kvm-qemu-iotests-Add-basic-ability-to-use-binary-sample-.patch

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