@@ -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("")
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(-)