diff options
author | Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 2020-06-06 11:18:03 +0300 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2020-06-09 15:47:09 -0500 |
commit | 0931fcc7beb1c2461f094e16720a979e749085e9 (patch) | |
tree | 0d5d345d31b3b2a360674dfe97f366b72b1f53e8 /tests | |
parent | 860543f055654017cdb5b25ed06c2bc91b72af70 (diff) | |
download | qemu-0931fcc7beb1c2461f094e16720a979e749085e9.zip qemu-0931fcc7beb1c2461f094e16720a979e749085e9.tar.gz qemu-0931fcc7beb1c2461f094e16720a979e749085e9.tar.bz2 |
qcow2_format.py: QcowHeaderExtension: add dump method
Obviously, for-loop body in dump_extensions should be the dump method
of extension.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Message-Id: <20200606081806.23897-11-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/qemu-iotests/qcow2_format.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_format.py index 74a82f9..d4ad543 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -108,6 +108,17 @@ class QcowHeaderExtension: self.length = length self.data = data + def dump(self): + data = self.data[:self.length] + if all(c in string.printable.encode('ascii') for c in data): + data = f"'{ data.decode('ascii') }'" + else: + data = '<binary>' + + print(f'{"magic":<25} {self.magic:#x}') + print(f'{"length":<25} {self.length}') + print(f'{"data":<25} {data}') + @classmethod def create(cls, magic, data): return QcowHeaderExtension(magic, len(data), data) @@ -210,15 +221,6 @@ class QcowHeader(Qcow2Struct): 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 = f"'{ data.decode('ascii') }'" - else: - data = '<binary>' - print('Header extension:') - print(f'{"magic":<25} {ex.magic:#x}') - print(f'{"length":<25} {ex.length}') - print(f'{"data":<25} {data}') + ex.dump() print() |