Skip to content

Commit 3ba8ee1

Browse files
kk7dsElod Illes
authored andcommitted
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 08be7b2) (cherry picked from commit 11301e7) (cherry picked from commit 70a435f) (cherry picked from commit f732f84) (cherry picked from commit a2acb31)
1 parent e7bdaac commit 3ba8ee1

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ def _test_create_cow_image(
128128
else:
129129
backing_info = {}
130130
backing_backing_file = backing_info.pop('backing_file', None)
131+
backing_fmt = backing_info.pop('backing_fmt',
132+
mock.sentinel.backing_fmt)
131133

132134
mock_execute.return_value = ('stdout', None)
133135
mock_info.return_value = mock.Mock(
134-
file_format=mock.sentinel.backing_fmt,
136+
file_format=backing_fmt,
135137
cluster_size=mock.sentinel.cluster_size,
136138
backing_file=backing_backing_file,
137139
format_specific=backing_info)
@@ -144,7 +146,7 @@ def _test_create_cow_image(
144146
mock_execute.assert_has_calls([mock.call(
145147
'qemu-img', 'create', '-f', 'qcow2', '-o',
146148
'backing_file=%s,backing_fmt=%s,cluster_size=%s' % (
147-
mock.sentinel.backing_path, mock.sentinel.backing_fmt,
149+
mock.sentinel.backing_path, backing_fmt,
148150
mock.sentinel.cluster_size),
149151
mock.sentinel.new_path)])
150152
if backing_file:
@@ -175,6 +177,28 @@ def test_create_image_base_has_data_file(self):
175177
'data': {'data-file': mock.sentinel.data_file}},
176178
)
177179

180+
def test_create_image_size_none(self):
181+
self._test_create_cow_image(
182+
backing_file=mock.sentinel.backing_file,
183+
)
184+
185+
def test_create_image_vmdk(self):
186+
self._test_create_cow_image(
187+
backing_file={'file': mock.sentinel.backing_file,
188+
'backing_fmt': 'vmdk',
189+
'backing_file': None,
190+
'data': {'create-type': 'monolithicSparse'}}
191+
)
192+
193+
def test_create_image_vmdk_invalid_type(self):
194+
self.assertRaises(exception.ImageUnacceptable,
195+
self._test_create_cow_image,
196+
backing_file={'file': mock.sentinel.backing_file,
197+
'backing_fmt': 'vmdk',
198+
'backing_file': None,
199+
'data': {'create-type': 'monolithicFlat'}}
200+
)
201+
178202
@ddt.unpack
179203
@ddt.data({'fs_type': 'some_fs_type',
180204
'default_eph_format': None,

nova/virt/libvirt/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def create_cow_image(
155155
reason=_('Base image failed safety check'))
156156

157157
base_details = images.qemu_img_info(backing_file)
158-
158+
if base_details.file_format == 'vmdk':
159+
images.check_vmdk_image('base', base_details)
159160
if base_details.backing_file is not None:
160161
LOG.warning('Base image %s failed safety check', backing_file)
161162
raise exception.InvalidDiskInfo(

0 commit comments

Comments
 (0)