2020-01-30 19:32:23 +03:00
|
|
|
#!/usr/bin/env python3
|
2021-01-16 16:44:19 +03:00
|
|
|
# group: rw quick
|
2013-10-09 12:46:20 +04:00
|
|
|
#
|
|
|
|
# Test for additional information emitted by qemu-img info on qcow2
|
|
|
|
# images
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import json
|
|
|
|
import iotests
|
|
|
|
from iotests import qemu_img, qemu_img_pipe
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
test_img = os.path.join(iotests.test_dir, 'test.img')
|
|
|
|
|
|
|
|
class TestImageInfoSpecific(iotests.QMPTestCase):
|
|
|
|
'''Abstract base class for ImageInfoSpecific tests'''
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
if self.img_options is None:
|
|
|
|
self.skipTest('Skipping abstract test class')
|
|
|
|
qemu_img('create', '-f', iotests.imgfmt, '-o', self.img_options,
|
|
|
|
test_img, '128K')
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
os.remove(test_img)
|
|
|
|
|
|
|
|
class TestQemuImgInfo(TestImageInfoSpecific):
|
|
|
|
'''Abstract base class for qemu-img info tests'''
|
|
|
|
|
|
|
|
img_options = None
|
|
|
|
json_compare = None
|
|
|
|
human_compare = None
|
|
|
|
|
|
|
|
def test_json(self):
|
|
|
|
data = json.loads(qemu_img_pipe('info', '--output=json', test_img))
|
|
|
|
data = data['format-specific']
|
|
|
|
self.assertEqual(data['type'], iotests.imgfmt)
|
|
|
|
self.assertEqual(data['data'], self.json_compare)
|
|
|
|
|
|
|
|
def test_human(self):
|
|
|
|
data = qemu_img_pipe('info', '--output=human', test_img).split('\n')
|
|
|
|
data = data[(data.index('Format specific information:') + 1)
|
|
|
|
:data.index('')]
|
|
|
|
for field in data:
|
|
|
|
self.assertTrue(re.match('^ {4}[^ ]', field) is not None)
|
iotests: Different iterator behavior in Python 3
In Python 3, several functions now return iterators instead of lists.
This includes range(), items(), map(), and filter(). This means that if
we really want a list, we have to wrap those instances with list(). But
then again, the two instances where this is the case for map() and
filter(), there are shorter expressions which work without either
function.
On the other hand, sometimes we do just want an iterator, in which case
we have sometimes used xrange() and iteritems() which no longer exist in
Python 3. Just change these calls to be range() and items(), works in
both Python 2 and 3, and is really what we want in 3 (which is what
matters). But because it is so simple to do (and to find and remove
once we completely switch to Python 3), make range() be an alias for
xrange() in the two affected tests (044 and 163).
In one instance, we only wanted the first instance of the result of a
filter() call. Instead of using next(filter()) which would work only in
Python 3, or list(filter())[0] which would work everywhere but is a bit
weird, this instance is changed to use a generator expression with a
next() wrapped around, which works both in 2.7 and 3.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cleber Rosa <crosa@redhat.com>
Message-Id: <20181022135307.14398-6-mreitz@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2018-10-22 16:53:03 +03:00
|
|
|
data = [line.strip() for line in data]
|
2013-10-09 12:46:20 +04:00
|
|
|
self.assertEqual(data, self.human_compare)
|
|
|
|
|
|
|
|
class TestQMP(TestImageInfoSpecific):
|
|
|
|
'''Abstract base class for qemu QMP tests'''
|
|
|
|
|
|
|
|
img_options = None
|
|
|
|
qemu_options = ''
|
|
|
|
TestImageInfoSpecific = TestImageInfoSpecific
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.TestImageInfoSpecific.setUp(self)
|
|
|
|
self.vm = iotests.VM().add_drive(test_img, self.qemu_options)
|
|
|
|
self.vm.launch()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.vm.shutdown()
|
|
|
|
self.TestImageInfoSpecific.tearDown(self)
|
|
|
|
|
|
|
|
def test_qmp(self):
|
|
|
|
result = self.vm.qmp('query-block')['return']
|
iotests: Different iterator behavior in Python 3
In Python 3, several functions now return iterators instead of lists.
This includes range(), items(), map(), and filter(). This means that if
we really want a list, we have to wrap those instances with list(). But
then again, the two instances where this is the case for map() and
filter(), there are shorter expressions which work without either
function.
On the other hand, sometimes we do just want an iterator, in which case
we have sometimes used xrange() and iteritems() which no longer exist in
Python 3. Just change these calls to be range() and items(), works in
both Python 2 and 3, and is really what we want in 3 (which is what
matters). But because it is so simple to do (and to find and remove
once we completely switch to Python 3), make range() be an alias for
xrange() in the two affected tests (044 and 163).
In one instance, we only wanted the first instance of the result of a
filter() call. Instead of using next(filter()) which would work only in
Python 3, or list(filter())[0] which would work everywhere but is a bit
weird, this instance is changed to use a generator expression with a
next() wrapped around, which works both in 2.7 and 3.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cleber Rosa <crosa@redhat.com>
Message-Id: <20181022135307.14398-6-mreitz@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2018-10-22 16:53:03 +03:00
|
|
|
drive = next(drive for drive in result if drive['device'] == 'drive0')
|
2013-10-09 12:46:20 +04:00
|
|
|
data = drive['inserted']['image']['format-specific']
|
|
|
|
self.assertEqual(data['type'], iotests.imgfmt)
|
|
|
|
self.assertEqual(data['data'], self.compare)
|
|
|
|
|
|
|
|
class TestQCow2(TestQemuImgInfo):
|
|
|
|
'''Testing a qcow2 version 2 image'''
|
2021-12-23 19:01:33 +03:00
|
|
|
img_options = 'compat=0.10,compression_type=zlib'
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 11:25:18 +03:00
|
|
|
json_compare = { 'compat': '0.10', 'refcount-bits': 16,
|
|
|
|
'compression-type': 'zlib' }
|
|
|
|
human_compare = [ 'compat: 0.10', 'compression type: zlib',
|
|
|
|
'refcount bits: 16' ]
|
2013-10-09 12:46:20 +04:00
|
|
|
|
|
|
|
class TestQCow3NotLazy(TestQemuImgInfo):
|
|
|
|
'''Testing a qcow2 version 3 image with lazy refcounts disabled'''
|
2021-12-23 19:01:33 +03:00
|
|
|
img_options = 'compat=1.1,lazy_refcounts=off,compression_type=zstd'
|
2015-02-10 23:28:44 +03:00
|
|
|
json_compare = { 'compat': '1.1', 'lazy-refcounts': False,
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 11:25:18 +03:00
|
|
|
'refcount-bits': 16, 'corrupt': False,
|
2021-12-23 19:01:33 +03:00
|
|
|
'compression-type': 'zstd', 'extended-l2': False }
|
|
|
|
human_compare = [ 'compat: 1.1', 'compression type: zstd',
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 11:25:18 +03:00
|
|
|
'lazy refcounts: false', 'refcount bits: 16',
|
2020-07-10 19:13:13 +03:00
|
|
|
'corrupt: false', 'extended l2: false' ]
|
2013-10-09 12:46:20 +04:00
|
|
|
|
|
|
|
class TestQCow3Lazy(TestQemuImgInfo):
|
|
|
|
'''Testing a qcow2 version 3 image with lazy refcounts enabled'''
|
2021-12-23 19:01:33 +03:00
|
|
|
img_options = 'compat=1.1,lazy_refcounts=on,compression_type=zlib'
|
2015-02-10 23:28:44 +03:00
|
|
|
json_compare = { 'compat': '1.1', 'lazy-refcounts': True,
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 11:25:18 +03:00
|
|
|
'refcount-bits': 16, 'corrupt': False,
|
2020-07-10 19:13:13 +03:00
|
|
|
'compression-type': 'zlib', 'extended-l2': False }
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 11:25:18 +03:00
|
|
|
human_compare = [ 'compat: 1.1', 'compression type: zlib',
|
|
|
|
'lazy refcounts: true', 'refcount bits: 16',
|
2020-07-10 19:13:13 +03:00
|
|
|
'corrupt: false', 'extended l2: false' ]
|
2013-10-09 12:46:20 +04:00
|
|
|
|
|
|
|
class TestQCow3NotLazyQMP(TestQMP):
|
|
|
|
'''Testing a qcow2 version 3 image with lazy refcounts disabled, opening
|
|
|
|
with lazy refcounts enabled'''
|
2021-12-23 19:01:33 +03:00
|
|
|
img_options = 'compat=1.1,lazy_refcounts=off,compression_type=zlib'
|
2013-10-09 12:46:20 +04:00
|
|
|
qemu_options = 'lazy-refcounts=on'
|
2015-02-10 23:28:44 +03:00
|
|
|
compare = { 'compat': '1.1', 'lazy-refcounts': False,
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 11:25:18 +03:00
|
|
|
'refcount-bits': 16, 'corrupt': False,
|
2020-07-10 19:13:13 +03:00
|
|
|
'compression-type': 'zlib', 'extended-l2': False }
|
2015-02-10 23:28:44 +03:00
|
|
|
|
2013-10-09 12:46:20 +04:00
|
|
|
|
|
|
|
class TestQCow3LazyQMP(TestQMP):
|
|
|
|
'''Testing a qcow2 version 3 image with lazy refcounts enabled, opening
|
|
|
|
with lazy refcounts disabled'''
|
2021-12-23 19:01:33 +03:00
|
|
|
img_options = 'compat=1.1,lazy_refcounts=on,compression_type=zstd'
|
2013-10-09 12:46:20 +04:00
|
|
|
qemu_options = 'lazy-refcounts=off'
|
2015-02-10 23:28:44 +03:00
|
|
|
compare = { 'compat': '1.1', 'lazy-refcounts': True,
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 11:25:18 +03:00
|
|
|
'refcount-bits': 16, 'corrupt': False,
|
2021-12-23 19:01:33 +03:00
|
|
|
'compression-type': 'zstd', 'extended-l2': False }
|
2013-10-09 12:46:20 +04:00
|
|
|
|
|
|
|
TestImageInfoSpecific = None
|
|
|
|
TestQemuImgInfo = None
|
|
|
|
TestQMP = None
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-09-02 22:33:18 +03:00
|
|
|
iotests.main(supported_fmts=['qcow2'],
|
2021-12-23 19:01:28 +03:00
|
|
|
supported_protocols=['file'],
|
|
|
|
unsupported_imgopts=['refcount_bits'])
|