Skip to content

Commit d69d441

Browse files
kk7dsElod Illes
authored andcommitted
Reject qcow files with data-file attributes
Change-Id: Ic3fa16f55acc38cf6c1a4ac1dce4487225e66d04 Closes-Bug: #2059809 (cherry picked from commit ec9c55c) (cherry picked from commit 58d933e) (cherry picked from commit 736328f) (cherry picked from commit af4d819)
1 parent fefc1dd commit d69d441

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ class FakeImgInfo(object):
382382
FakeImgInfo.file_format = file_format
383383
FakeImgInfo.backing_file = backing_file
384384
FakeImgInfo.virtual_size = 1
385+
FakeImgInfo.format_specific = None if file_format == 'raw' else {}
385386

386387
return FakeImgInfo()
387388

nova/tests/unit/virt/test_images.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,37 @@ def test_fetch_to_raw_errors(self, convert_image, qemu_img_info, fetch):
112112
images.fetch_to_raw,
113113
None, 'href123', '/no/path')
114114

115+
@mock.patch.object(images, 'convert_image',
116+
side_effect=exception.ImageUnacceptable)
117+
@mock.patch.object(images, 'qemu_img_info')
118+
@mock.patch.object(images, 'fetch')
119+
def test_fetch_to_raw_data_file(self, convert_image, qemu_img_info_fn,
120+
fetch):
121+
# NOTE(danms): the above test needs the following line as well, as it
122+
# is broken without it.
123+
qemu_img_info = qemu_img_info_fn.return_value
124+
qemu_img_info.backing_file = None
125+
qemu_img_info.file_format = 'qcow2'
126+
qemu_img_info.virtual_size = 20
127+
qemu_img_info.format_specific = {'data': {'data-file': 'somefile'}}
128+
self.assertRaisesRegex(exception.ImageUnacceptable,
129+
'Image href123 is unacceptable.*somefile',
130+
images.fetch_to_raw,
131+
None, 'href123', '/no/path')
132+
133+
@mock.patch('os.rename')
134+
@mock.patch.object(images, 'qemu_img_info')
135+
@mock.patch.object(images, 'fetch')
136+
def test_fetch_to_raw_from_raw(self, fetch, qemu_img_info_fn, mock_rename):
137+
# Make sure we support a case where we fetch an already-raw image and
138+
# qemu-img returns None for "format_specific".
139+
qemu_img_info = qemu_img_info_fn.return_value
140+
qemu_img_info.file_format = 'raw'
141+
qemu_img_info.backing_file = None
142+
qemu_img_info.format_specific = None
143+
images.fetch_to_raw(None, 'href123', '/no/path')
144+
mock_rename.assert_called_once_with('/no/path.part', '/no/path')
145+
115146
@mock.patch.object(compute_utils, 'disk_ops_semaphore')
116147
@mock.patch('nova.privsep.utils.supports_direct_io', return_value=True)
117148
@mock.patch('oslo_concurrency.processutils.execute')

nova/virt/images.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ def fetch_to_raw(context, image_href, path, trusted_certs=None):
157157
reason=(_("fmt=%(fmt)s backed by: %(backing_file)s") %
158158
{'fmt': fmt, 'backing_file': backing_file}))
159159

160+
try:
161+
data_file = data.format_specific['data']['data-file']
162+
except (KeyError, TypeError, AttributeError):
163+
data_file = None
164+
if data_file is not None:
165+
raise exception.ImageUnacceptable(image_id=image_href,
166+
reason=(_("fmt=%(fmt)s has data-file: %(data_file)s") %
167+
{'fmt': fmt, 'data_file': data_file}))
168+
160169
if fmt == 'vmdk':
161170
check_vmdk_image(image_href, data)
162171

0 commit comments

Comments
 (0)