Fix vmdk_allowed_types checking

This restores the vmdk_allowed_types checking in create_image()
that was unintentionally lost by tightening the
qemu-type-matches-glance code in the fetch patch recently. Since we
are still detecting the format of base images without metadata, we
would have treated a vmdk file that claims to be raw as raw in fetch,
but then read it like a vmdk once it was used as a base image for
something else.

Conflicts:
  nova/tests/unit/virt/libvirt/test_utils.py

NOTE(elod.illes): conflicts are due to encryption support adding patch
I5d6d2a7b03b5ace0826af80c4004de852579ff12 was introduced in zed.

Change-Id: I07b332a7edb814f6a91661651d9d24bfd6651ae7
Related-Bug: #2059809
(cherry picked from commit 08be7b2a0d)
(cherry picked from commit 11301e7e3f)
(cherry picked from commit 70a435fd51)
(cherry picked from commit f732f84768)
This commit is contained in:
Dan Smith
2024-07-01 09:06:40 -07:00
committed by Elod Illes
parent 303c2c9644
commit a2acb31d79
2 changed files with 25 additions and 2 deletions

View File

@@ -117,9 +117,11 @@ class LibvirtUtilsTestCase(test.NoDBTestCase):
else:
backing_info = {}
backing_backing_file = backing_info.pop('backing_file', None)
backing_fmt = backing_info.pop('backing_fmt',
mock.sentinel.backing_fmt)
mock_info.return_value = mock.Mock(
file_format=mock.sentinel.backing_fmt,
file_format=backing_fmt,
cluster_size=mock.sentinel.cluster_size,
backing_file=backing_backing_file,
format_specific=backing_info,
@@ -139,7 +141,7 @@ class LibvirtUtilsTestCase(test.NoDBTestCase):
cow_opts = [
'-o',
f'backing_file={backing_file},'
f'backing_fmt={mock.sentinel.backing_fmt},'
f'backing_fmt={backing_fmt},'
f'cluster_size={mock.sentinel.cluster_size}',
]
@@ -193,6 +195,25 @@ class LibvirtUtilsTestCase(test.NoDBTestCase):
backing_file=mock.sentinel.backing_file,
)
def test_create_image_vmdk(self):
self._test_create_image(
'/some/vmdk', 'vmdk', '1234567891234',
backing_file={'file': mock.sentinel.backing_file,
'backing_fmt': 'vmdk',
'backing_file': None,
'data': {'create-type': 'monolithicSparse'}}
)
def test_create_image_vmdk_invalid_type(self):
self.assertRaises(exception.ImageUnacceptable,
self._test_create_image,
'/some/vmdk', 'vmdk', '1234567891234',
backing_file={'file': mock.sentinel.backing_file,
'backing_fmt': 'vmdk',
'backing_file': None,
'data': {'create-type': 'monolithicFlat'}}
)
@ddt.unpack
@ddt.data({'fs_type': 'some_fs_type',
'default_eph_format': None,

View File

@@ -148,6 +148,8 @@ def create_image(
reason=_('Base image failed safety check'))
base_details = images.qemu_img_info(backing_file)
if base_details.file_format == 'vmdk':
images.check_vmdk_image('base', base_details)
if base_details.backing_file is not None:
LOG.warning('Base image %s failed safety check', backing_file)
raise exception.InvalidDiskInfo(