Merge "Handle images detected as ISO+GPT"
This commit is contained in:
@@ -605,7 +605,17 @@ class ImageProxy(glance.domain.proxy.Image):
|
||||
|
||||
virtual_size = 0
|
||||
try:
|
||||
inspector = data.format
|
||||
matches = data.formats
|
||||
matched_formats = {str(i): i for i in matches}
|
||||
if matched_formats.keys() == {'iso', 'gpt'}:
|
||||
# If iso+gpt, we choose the iso because bootable-as-block ISOs
|
||||
# can legitimately have a GPT bootloader in front.
|
||||
LOG.debug('Detected format as ISO+GPT, allowing as ISO')
|
||||
inspector = matched_formats['iso']
|
||||
else:
|
||||
# If multiple formats matched, but not exactly iso+gpt,
|
||||
# this will raise to disallow those combinations.
|
||||
inspector = data.format
|
||||
format = str(inspector)
|
||||
if format == self.image.disk_format:
|
||||
virtual_size = inspector.virtual_size
|
||||
|
||||
@@ -19,6 +19,7 @@ from cursive import exception as cursive_exception
|
||||
from cursive import signature_utils
|
||||
import glance_store
|
||||
from oslo_config import cfg
|
||||
from oslo_utils.imageutils import format_inspector
|
||||
import struct
|
||||
from unittest import mock
|
||||
|
||||
@@ -410,6 +411,48 @@ class TestStoreImage(utils.BaseTestCase):
|
||||
store_api, self.store_utils)
|
||||
image.set_data(iter((data,)), 1024)
|
||||
|
||||
@mock.patch('oslo_utils.imageutils.format_inspector.InspectWrapper')
|
||||
def _test_image_set_data_inspector_multiple_formats(self, formats,
|
||||
fail_multiple,
|
||||
mock_wrapper):
|
||||
mock_result = mock_wrapper.return_value
|
||||
mock_result.formats = []
|
||||
for format in formats:
|
||||
inspector = mock.MagicMock()
|
||||
inspector.__str__.return_value = format
|
||||
mock_result.formats.append(inspector)
|
||||
|
||||
if fail_multiple:
|
||||
mock_result.format.side_effect = format_inspector.ImageFormatError
|
||||
else:
|
||||
mock_result.format.__str__.return_value = formats[0]
|
||||
context = glance.context.RequestContext(user=USER1)
|
||||
image_stub = ImageStub(UUID2, status='queued', locations=[])
|
||||
image_stub.disk_format = 'iso'
|
||||
store_api = unit_test_utils.FakeStoreAPIReader(max_size=2048)
|
||||
image = glance.location.ImageProxy(image_stub, context,
|
||||
store_api, self.store_utils)
|
||||
image.set_data(iter((['ABCD'],)), 1024)
|
||||
for inspector in mock_result.formats:
|
||||
inspector.__str__.assert_called()
|
||||
|
||||
def test_image_set_data_inspector_iso_gpt_as_iso(self):
|
||||
# ISO+GPT is allowed as ISO
|
||||
self._test_image_set_data_inspector_multiple_formats(['iso', 'gpt'],
|
||||
False)
|
||||
|
||||
def test_image_set_data_inspector_iso_qcow2_as_iso(self):
|
||||
# ISO+Qcow2 is not allowed
|
||||
self.assertRaises(exception.InvalidImageData,
|
||||
self._test_image_set_data_inspector_multiple_formats,
|
||||
['iso', 'qcow2'], True)
|
||||
|
||||
def test_image_set_data_inspector_qcow2_gpt_as_iso(self):
|
||||
# Qcow2 is not allowed (nor really possible)
|
||||
self.assertRaises(exception.InvalidImageData,
|
||||
self._test_image_set_data_inspector_multiple_formats,
|
||||
['iso', 'qcow2'], True)
|
||||
|
||||
def test_image_set_data_inspector_no_match_disabled(self):
|
||||
self.config(require_image_format_match=False, group='image_format')
|
||||
self.test_image_set_data_inspector_no_match()
|
||||
|
||||
@@ -17,7 +17,7 @@ oslo.config>=8.1.0 # Apache-2.0
|
||||
oslo.concurrency>=4.5.1 # Apache-2.0
|
||||
oslo.context>=2.22.0 # Apache-2.0
|
||||
oslo.upgradecheck>=1.3.0 # Apache-2.0
|
||||
oslo.utils>=7.3.0 # Apache-2.0
|
||||
oslo.utils>=7.4.0 # Apache-2.0
|
||||
stevedore!=3.0.0,>=1.20.0 # Apache-2.0
|
||||
futurist>=1.2.0 # Apache-2.0
|
||||
taskflow>=4.0.0 # Apache-2.0
|
||||
|
||||
Reference in New Issue
Block a user