All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, vsementsov@virtuozzo.com,
	qemu-devel@nongnu.org, mreitz@redhat.com,
	andrey.shinkevich@virtuozzo.com, den@openvz.org
Subject: [PATCH v3 2/6] iotests: move check for printable data to QcowHeaderExtension class
Date: Mon,  1 Jun 2020 16:48:09 +0300	[thread overview]
Message-ID: <1591019293-211155-3-git-send-email-andrey.shinkevich@virtuozzo.com> (raw)
In-Reply-To: <1591019293-211155-1-git-send-email-andrey.shinkevich@virtuozzo.com>

Let us differ binary data type from string one for the extension data
variable and keep the string as the QcowHeaderExtension class member
in the script qcow2.py.

Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
 tests/qemu-iotests/qcow2.py | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py
index e824b09..18e4923 100755
--- a/tests/qemu-iotests/qcow2.py
+++ b/tests/qemu-iotests/qcow2.py
@@ -13,6 +13,12 @@ class QcowHeaderExtension:
     QCOW2_EXT_MAGIC_DATA_FILE = 0x44415441
 
     def __init__(self, magic, length, data):
+        data_str = data[:length]
+        if all(c in string.printable.encode('ascii') for c in data_str):
+            data_str = "'%s'" % data_str.decode('ascii')
+        else:
+            data_str = "<binary>"
+
         if length % 8 != 0:
             padding = 8 - (length % 8)
             data += b"\0" * padding
@@ -21,6 +27,7 @@ class QcowHeaderExtension:
         self.length = length
         self.data = data
         self.name = self.extension_name(magic)
+        self.data_str = data_str
 
     @classmethod
     def create(cls, magic, data):
@@ -162,16 +169,10 @@ class QcowHeader:
     def dump_extensions(self):
         for ex in self.extensions:
 
-            data = ex.data[:ex.length]
-            if all(c in string.printable.encode('ascii') for c in data):
-                data = "'%s'" % data.decode('ascii')
-            else:
-                data = "<binary>"
-
             print("%-25s %s" % ("Header extension:", ex.name))
             print("%-25s %#x" % ("magic", ex.magic))
             print("%-25s %d" % ("length", ex.length))
-            print("%-25s %s" % ("data", data))
+            print("%-25s %s" % ("data", ex.data_str))
             print("")
 
 
-- 
1.8.3.1



  parent reply	other threads:[~2020-06-01 13:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-01 13:48 [PATCH v3 0/6] iotests: Dump QCOW2 dirty bitmaps metadata Andrey Shinkevich
2020-06-01 13:48 ` [PATCH v3 1/6] iotests: Add extension names to qcow2.py dump Andrey Shinkevich
2020-06-02 16:05   ` Eric Blake
2020-06-02 16:07     ` Eric Blake
2020-06-02 19:25   ` Vladimir Sementsov-Ogievskiy
2020-06-01 13:48 ` Andrey Shinkevich [this message]
2020-06-02 16:14   ` [PATCH v3 2/6] iotests: move check for printable data to QcowHeaderExtension class Eric Blake
2020-06-02 19:32   ` Vladimir Sementsov-Ogievskiy
2020-06-01 13:48 ` [PATCH v3 3/6] iotests: dump bitmap extension data with qcow2.py Andrey Shinkevich
2020-06-02 16:16   ` Eric Blake
2020-06-02 20:10   ` Vladimir Sementsov-Ogievskiy
2020-06-01 13:48 ` [PATCH v3 4/6] iotests: Dump bitmap directory info " Andrey Shinkevich
2020-06-02 17:35   ` Eric Blake
2020-06-02 21:15   ` Vladimir Sementsov-Ogievskiy
2020-06-01 13:48 ` [PATCH v3 5/6] iotests: Dump bitmap table entries serialized in QCOW2 image Andrey Shinkevich
2020-06-02 17:38   ` Eric Blake
2020-06-02 21:26   ` Vladimir Sementsov-Ogievskiy
2020-06-01 13:48 ` [PATCH v3 6/6] iotests: Dump QCOW2 image metadata in JSON format with qcow2.py Andrey Shinkevich
2020-06-02 17:40   ` Eric Blake
2020-06-02 21:36   ` Vladimir Sementsov-Ogievskiy
2020-06-01 21:46 ` [PATCH v3 0/6] iotests: Dump QCOW2 dirty bitmaps metadata Eric Blake
2020-06-04  7:54   ` Andrey Shinkevich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1591019293-211155-3-git-send-email-andrey.shinkevich@virtuozzo.com \
    --to=andrey.shinkevich@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.