summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Rabotyagov <dmitriy.rabotyagov@citynetwork.eu>2021-05-01 12:12:40 +0300
committerDmitriy Rabotyagov <noonedeadpunk@ya.ru>2021-11-11 10:57:50 +0000
commit3b5eebdc1c8606552ca00cff8f675f556e076d0e (patch)
treebba627c09bda14b9478c0cf124d672a46e99835c
parentd8b3e046ce10289fc73010eb3d0d6c23f6713569 (diff)
downloadoslo-utils-3b5eebdc1c8606552ca00cff8f675f556e076d0e.tar.gz
Add backing file format to the output4.12.0
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
-rw-r--r--oslo_utils/imageutils.py3
-rw-r--r--oslo_utils/tests/test_imageutils.py18
2 files changed, 19 insertions, 2 deletions
diff --git a/oslo_utils/imageutils.py b/oslo_utils/imageutils.py
index d764a7f..4808091 100644
--- a/oslo_utils/imageutils.py
+++ b/oslo_utils/imageutils.py
@@ -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)
diff --git a/oslo_utils/tests/test_imageutils.py b/oslo_utils/tests/test_imageutils.py
index 6b25226..5705ca8 100644
--- a/oslo_utils/tests/test_imageutils.py
+++ b/oslo_utils/tests/test_imageutils.py
@@ -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)