Skip to content

Commit c730645

Browse files
authored
Merge pull request #87 from stackhpc/yoga-reapply-ossa-2024-001
Reapply OSSA-2024-001 patches for Yoga
2 parents 4b85693 + f94bbc1 commit c730645

File tree

3 files changed

+88
-8
lines changed

3 files changed

+88
-8
lines changed

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

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,86 @@ def test_create_image(self, mock_execute):
118118
@mock.patch('oslo_concurrency.processutils.execute')
119119
@mock.patch('nova.virt.images.qemu_img_info')
120120
@mock.patch('nova.image.format_inspector.detect_file_format')
121-
def test_create_cow_image(self, mock_detect, mock_info, mock_execute,
122-
mock_exists):
121+
def _test_create_cow_image(
122+
self, mock_detect, mock_info, mock_execute,
123+
mock_exists, backing_file=None, safety_check=True
124+
):
125+
if isinstance(backing_file, dict):
126+
backing_info = backing_file
127+
backing_file = backing_info.pop('file', None)
128+
else:
129+
backing_info = {}
130+
backing_backing_file = backing_info.pop('backing_file', None)
131+
backing_fmt = backing_info.pop('backing_fmt',
132+
mock.sentinel.backing_fmt)
133+
123134
mock_execute.return_value = ('stdout', None)
124135
mock_info.return_value = mock.Mock(
125-
file_format=mock.sentinel.backing_fmt,
136+
file_format=backing_fmt,
126137
cluster_size=mock.sentinel.cluster_size,
127-
backing_file=None)
128-
mock_detect.return_value.safety_check.return_value = True
138+
backing_file=backing_backing_file,
139+
format_specific=backing_info)
140+
141+
mock_detect.return_value.safety_check.return_value = safety_check
142+
129143
libvirt_utils.create_cow_image(mock.sentinel.backing_path,
130144
mock.sentinel.new_path)
131145
mock_info.assert_called_once_with(mock.sentinel.backing_path)
132146
mock_execute.assert_has_calls([mock.call(
133147
'qemu-img', 'create', '-f', 'qcow2', '-o',
134148
'backing_file=%s,backing_fmt=%s,cluster_size=%s' % (
135-
mock.sentinel.backing_path, mock.sentinel.backing_fmt,
149+
mock.sentinel.backing_path, backing_fmt,
136150
mock.sentinel.cluster_size),
137151
mock.sentinel.new_path)])
138-
mock_detect.return_value.safety_check.assert_called_once_with()
152+
if backing_file:
153+
mock_detect.return_value.safety_check.assert_called_once_with()
154+
155+
def test_create_image_qcow2(self):
156+
self._test_create_cow_image()
157+
158+
def test_create_image_backing_file(self):
159+
self._test_create_cow_image(
160+
backing_file=mock.sentinel.backing_file
161+
)
162+
163+
def test_create_image_base_has_backing_file(self):
164+
self.assertRaises(
165+
exception.InvalidDiskInfo,
166+
self._test_create_cow_image,
167+
backing_file={'file': mock.sentinel.backing_file,
168+
'backing_file': mock.sentinel.backing_backing_file},
169+
)
170+
171+
def test_create_image_base_has_data_file(self):
172+
self.assertRaises(
173+
exception.InvalidDiskInfo,
174+
self._test_create_cow_image,
175+
backing_file={'file': mock.sentinel.backing_file,
176+
'backing_file': mock.sentinel.backing_backing_file,
177+
'data': {'data-file': mock.sentinel.data_file}},
178+
)
179+
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+
)
139201

140202
@ddt.unpack
141203
@ddt.data({'fs_type': 'some_fs_type',

nova/tests/unit/virt/test_images.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,24 @@ def test_fetch_inspect_ami(self, imginfo, glance):
301301
# Make sure 'ami was translated into 'raw' before we call qemu-img
302302
imginfo.assert_called_once_with('/no.path.part', format='raw')
303303

304+
@mock.patch.object(images, 'IMAGE_API')
305+
@mock.patch.object(images, 'qemu_img_info')
306+
def test_fetch_inspect_aki(self, imginfo, glance):
307+
glance.get.return_value = {'disk_format': 'aki'}
308+
self.assertRaises(exception.ImageUnacceptable,
309+
images.fetch_to_raw, None, 'href123', '/no.path')
310+
# Make sure 'aki was translated into 'raw' before we call qemu-img
311+
imginfo.assert_called_once_with('/no.path.part', format='raw')
312+
313+
@mock.patch.object(images, 'IMAGE_API')
314+
@mock.patch.object(images, 'qemu_img_info')
315+
def test_fetch_inspect_ari(self, imginfo, glance):
316+
glance.get.return_value = {'disk_format': 'ari'}
317+
self.assertRaises(exception.ImageUnacceptable,
318+
images.fetch_to_raw, None, 'href123', '/no.path')
319+
# Make sure 'aki was translated into 'raw' before we call qemu-img
320+
imginfo.assert_called_once_with('/no.path.part', format='raw')
321+
304322
@mock.patch.object(images, 'IMAGE_API')
305323
@mock.patch.object(images, 'qemu_img_info')
306324
def test_fetch_inspect_unknown_format(self, imginfo, glance):

nova/virt/images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def do_image_deep_inspection(img, image_href, path):
160160
# No inspector was found
161161
LOG.warning('Unable to perform deep image inspection on type %r',
162162
img['disk_format'])
163-
if disk_format == 'ami':
163+
if disk_format in ('ami', 'aki', 'ari'):
164164
# A lot of things can be in a UEC, although it is typically a raw
165165
# filesystem. We really have nothing we can do other than treat it
166166
# like a 'raw', which is what qemu-img will detect a filesystem as

0 commit comments

Comments
 (0)