Skip to content

Commit

Permalink
Fix vmdk_allowed_types checking
Browse files Browse the repository at this point in the history
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.

Change-Id: I07b332a7edb814f6a91661651d9d24bfd6651ae7
Related-Bug: #2059809
(cherry picked from commit 08be7b2)
(cherry picked from commit 11301e7)
(cherry picked from commit 70a435f)
  • Loading branch information
kk7ds authored and gibizer committed Jul 4, 2024
1 parent 9e10ac2 commit f732f84
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions nova/tests/unit/virt/libvirt/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ def _test_create_image(
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,
Expand All @@ -144,7 +146,7 @@ def _test_create_image(
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}',
]

Expand Down Expand Up @@ -221,6 +223,25 @@ def test_create_image_size_none(self):
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'}}
)

def test_create_image_encryption(self):
encryption = {
'secret': 'a_secret',
Expand Down
2 changes: 2 additions & 0 deletions nova/virt/libvirt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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(
Expand Down

0 comments on commit f732f84

Please sign in to comment.