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.

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 08be7b2)
(cherry picked from commit 11301e7)
(cherry picked from commit 70a435f)
(cherry picked from commit f732f84)
(cherry picked from commit a2acb31)
(cherry picked from commit 3ba8ee1)
  • Loading branch information
kk7ds authored and priteau committed Jul 23, 2024
1 parent e9eb032 commit f94bbc1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 26 additions & 2 deletions nova/tests/unit/virt/libvirt/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ def _test_create_cow_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_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)
Expand All @@ -144,7 +146,7 @@ def _test_create_cow_image(
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:
Expand Down Expand Up @@ -175,6 +177,28 @@ def test_create_image_base_has_data_file(self):
'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,
Expand Down
3 changes: 2 additions & 1 deletion nova/virt/libvirt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f94bbc1

Please sign in to comment.