Add backing file format to the output

Since libvirt 6, it might be important to understand the
format of the backing image [1] and verify it before operations.

So we adding backing file format to the output of the QemuImgInfo

[1] https://libvirt.org/kbase/backing_chains.html

Change-Id: If83289882e79a973bc77f332408f8f7317351f6f
This commit is contained in:
Dmitriy Rabotyagov 2021-05-01 12:12:40 +03:00 committed by Dmitriy Rabotyagov
parent d8b3e046ce
commit 3b5eebdc1c
2 changed files with 19 additions and 2 deletions

View File

@ -58,6 +58,7 @@ class QemuImgInfo(object):
details = json.loads(cmd_output or '{}')
self.image = details.get('filename')
self.backing_file = details.get('backing-filename')
self.backing_file_format = details.get('backing-filename-format')
self.file_format = details.get('format')
self.virtual_size = details.get('virtual-size')
self.cluster_size = details.get('cluster-size')
@ -75,6 +76,7 @@ class QemuImgInfo(object):
details = self._parse(cmd_output or '')
self.image = details.get('image')
self.backing_file = details.get('backing_file')
self.backing_file_format = details.get('backing_file_format')
self.file_format = details.get('file_format')
self.virtual_size = details.get('virtual_size')
self.cluster_size = details.get('cluster_size')
@ -91,6 +93,7 @@ class QemuImgInfo(object):
'disk_size: %s' % self.disk_size,
'cluster_size: %s' % self.cluster_size,
'backing_file: %s' % self.backing_file,
'backing_file_format: %s' % self.backing_file_format,
]
if self.snapshots:
lines.append("snapshots: %s" % self.snapshots)

View File

@ -174,6 +174,12 @@ class ImageUtilsHumanQemuTestCase(ImageUtilsHumanRawTestCase):
exp_backing_file='/b/3a988059e51a_2')),
]
_qcow2_backing_file_format = [
('no_backing_file_format', dict(backing_file_format=None)),
('backing_file_format', dict(backing_file_format='qcow2',
exp_backing_file_format='qcow2')),
]
@classmethod
def generate_scenarios(cls):
cls.scenarios = testscenarios.multiply_scenarios(
@ -185,7 +191,8 @@ class ImageUtilsHumanQemuTestCase(ImageUtilsHumanRawTestCase):
cls._snapshot_count,
cls._qcow2_cluster_size,
cls._qcow2_encrypted,
cls._qcow2_backing_file)
cls._qcow2_backing_file,
cls._qcow2_backing_file_format)
@mock.patch("debtcollector.deprecate")
def test_qemu_img_info_human_format(self, mock_deprecate):
@ -194,6 +201,9 @@ class ImageUtilsHumanQemuTestCase(ImageUtilsHumanRawTestCase):
if self.backing_file is not None:
img_info = img_info + ('backing file: %s' %
self.backing_file,)
if self.backing_file_format is not None:
img_info = img_info + ('backing file format: %s' %
self.backing_file_format,)
if self.encrypted is not None:
img_info = img_info + ('encrypted: %s' % self.encrypted,)
if self.garbage_before_snapshot is True:
@ -211,6 +221,9 @@ class ImageUtilsHumanQemuTestCase(ImageUtilsHumanRawTestCase):
if self.backing_file is not None:
self.assertEqual(image_info.backing_file,
self.exp_backing_file)
if self.backing_file_format is not None:
self.assertEqual(image_info.backing_file_format,
self.exp_backing_file_format)
if self.encrypted is not None:
self.assertEqual(image_info.encrypted, self.encrypted)
@ -223,7 +236,8 @@ class ImageUtilsBlankTestCase(test_base.BaseTestCase):
example_output = '\n'.join(['image: None', 'file_format: None',
'virtual_size: None', 'disk_size: None',
'cluster_size: None',
'backing_file: None'])
'backing_file: None',
'backing_file_format: None'])
image_info = imageutils.QemuImgInfo()
self.assertEqual(str(image_info), example_output)
self.assertEqual(len(image_info.snapshots), 0)