thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From 9fe83d3e480a74024150774c38373122084dfe10 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Wed, 6 Nov 2013 16:53:38 +0100
9ae3a8
Subject: [PATCH 81/87] qemu-iotests: Discard specific info in _img_info
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383756824-6921-16-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55570
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 15/21] qemu-iotests: Discard specific info in _img_info
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
BZ: 980771
9ae3a8
9ae3a8
In _img_info, filter out additional information specific to the image
9ae3a8
format provided by qemu-img info, since tests designed for multiple
9ae3a8
image formats would produce different outputs for every image format
9ae3a8
otherwise.
9ae3a8
9ae3a8
In a human-readable dump, that new information will always be last for
9ae3a8
each "image information block" (multiple blocks are emitted when
9ae3a8
inspecting the backing file chain). Every block is separated by an empty
9ae3a8
line. Therefore, in this case, everything starting with the line "Format
9ae3a8
specific information:" up to that empty line (or EOF, if it is the last
9ae3a8
block) has to be stripped.
9ae3a8
9ae3a8
The JSON dump will always emit pretty JSON data. Therefore, the opening
9ae3a8
and closing braces of every object will be on lines which are indented
9ae3a8
by exactly the same amount, and all lines in between will have more
9ae3a8
indentation. Thus, in this case, everything starting with a line
9ae3a8
matching the regular expression /^ *"format-specific": {/ until /^ *},?/
9ae3a8
has to be stripped, where the number of spaces at the beginning of the
9ae3a8
respective lines is equal.
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 4c2e946500c45685fdec61b3d929311dc26a2ad5)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 tests/qemu-iotests/common.rc | 20 +++++++++++++++++++-
9ae3a8
 1 file changed, 19 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 tests/qemu-iotests/common.rc |   20 +++++++++++++++++++-
9ae3a8
 1 files changed, 19 insertions(+), 1 deletions(-)
9ae3a8
9ae3a8
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
9ae3a8
index 1b22db0..227c003 100644
9ae3a8
--- a/tests/qemu-iotests/common.rc
9ae3a8
+++ b/tests/qemu-iotests/common.rc
9ae3a8
@@ -197,12 +197,30 @@ _check_test_img()
9ae3a8
 
9ae3a8
 _img_info()
9ae3a8
 {
9ae3a8
+    discard=0
9ae3a8
+    regex_json_spec_start='^ *"format-specific": \{'
9ae3a8
     $QEMU_IMG info "$@" "$TEST_IMG" 2>&1 | \
9ae3a8
         sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
9ae3a8
             -e "s#$TEST_DIR#TEST_DIR#g" \
9ae3a8
             -e "s#$IMGFMT#IMGFMT#g" \
9ae3a8
             -e "/^disk size:/ D" \
9ae3a8
-            -e "/actual-size/ D"
9ae3a8
+            -e "/actual-size/ D" | \
9ae3a8
+        while IFS='' read line; do
9ae3a8
+            if [[ $line == "Format specific information:" ]]; then
9ae3a8
+                discard=1
9ae3a8
+            elif [[ $line =~ $regex_json_spec_start ]]; then
9ae3a8
+                discard=2
9ae3a8
+                regex_json_spec_end="^${line%%[^ ]*}\\},? *$"
9ae3a8
+            fi
9ae3a8
+            if [[ $discard == 0 ]]; then
9ae3a8
+                echo "$line"
9ae3a8
+            elif [[ $discard == 1 && ! $line ]]; then
9ae3a8
+                echo
9ae3a8
+                discard=0
9ae3a8
+            elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then
9ae3a8
+                discard=0
9ae3a8
+            fi
9ae3a8
+        done
9ae3a8
 }
9ae3a8
 
9ae3a8
 _get_pids_by_name()
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8