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
  nova/virt/libvirt/utils.py

NOTE(elod.illes): conflicts are due to patch to consolidate image
creation functions (I111cfc8a5eae27b15c6312957255fcf973038ddf) is only
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)
(cherry picked from commit a2acb31d79)
This commit is contained in:
Dan Smith
2024-07-01 09:06:40 -07:00
committed by Elod Illes
parent e7bdaac1b6
commit 3ba8ee1611
2 changed files with 28 additions and 3 deletions

View File

@@ -128,10 +128,12 @@ 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_execute.return_value = ('stdout', None)
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)
@@ -144,7 +146,7 @@ class LibvirtUtilsTestCase(test.NoDBTestCase):
mock_execute.assert_has_calls([mock.call(
'qemu-img', 'create', '-f', 'qcow2', '-o',
'backing_file=%s,backing_fmt=%s,cluster_size=%s' % (
mock.sentinel.backing_path, mock.sentinel.backing_fmt,
mock.sentinel.backing_path, backing_fmt,
mock.sentinel.cluster_size),
mock.sentinel.new_path)])
if backing_file:
@@ -175,6 +177,28 @@ class LibvirtUtilsTestCase(test.NoDBTestCase):
'data': {'data-file': mock.sentinel.data_file}},
)
def test_create_image_size_none(self):
self._test_create_cow_image(
backing_file=mock.sentinel.backing_file,
)
def test_create_image_vmdk(self):
self._test_create_cow_image(
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_cow_image,
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

@@ -155,7 +155,8 @@ def create_cow_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(