Do not fail when raw image is larger than memory for http
When the image is larger than the memory and it is given as a URL, it will now not fail if the image format is specified and is raw. Story: 2007706 Task: 39829 Change-Id: I79dff2dc9d22580f7781324e22e1656c33c52a0b
This commit is contained in:
parent
c2b2e7521a
commit
16f5950f1b
@ -71,11 +71,12 @@ PARTITION_IMAGE_LABELS = ('kernel', 'ramdisk', 'root_gb', 'root_mb', 'swap_mb',
|
||||
|
||||
|
||||
@METRICS.timer('check_image_size')
|
||||
def check_image_size(task, image_source):
|
||||
def check_image_size(task, image_source, image_disk_format=None):
|
||||
"""Check if the requested image is larger than the ram size.
|
||||
|
||||
:param task: a TaskManager instance containing the node to act on.
|
||||
:param image_source: href of the image.
|
||||
:param image_disk_format: The disk format of the image if provided
|
||||
:raises: InvalidParameterValue if size of the image is greater than
|
||||
the available ram size.
|
||||
"""
|
||||
@ -88,7 +89,8 @@ def check_image_size(task, image_source):
|
||||
return
|
||||
|
||||
image_show = images.image_show(task.context, image_source)
|
||||
if CONF.agent.stream_raw_images and image_show.get('disk_format') == 'raw':
|
||||
if CONF.agent.stream_raw_images and (image_show.get('disk_format') == 'raw'
|
||||
or image_disk_format == 'raw'):
|
||||
LOG.debug('Skip the image size check since the image is going to be '
|
||||
'streamed directly onto the disk for node %s', node.uuid)
|
||||
return
|
||||
@ -417,6 +419,7 @@ class AgentDeploy(AgentDeployMixin, base.DeployInterface):
|
||||
params = {}
|
||||
image_source = node.instance_info.get('image_source')
|
||||
image_checksum = node.instance_info.get('image_checksum')
|
||||
image_disk_format = node.instance_info.get('image_disk_format')
|
||||
os_hash_algo = node.instance_info.get('image_os_hash_algo')
|
||||
os_hash_value = node.instance_info.get('image_os_hash_value')
|
||||
|
||||
@ -449,7 +452,7 @@ class AgentDeploy(AgentDeployMixin, base.DeployInterface):
|
||||
|
||||
validate_http_provisioning_configuration(node)
|
||||
|
||||
check_image_size(task, image_source)
|
||||
check_image_size(task, image_source, image_disk_format)
|
||||
# Validate the root device hints
|
||||
deploy_utils.get_root_device_for_deploy(node)
|
||||
validate_image_proxies(node)
|
||||
|
@ -121,6 +121,35 @@ class TestAgentMethods(db_base.DbTestCase):
|
||||
agent.check_image_size(task, 'fake-image')
|
||||
show_mock.assert_called_once_with(self.context, 'fake-image')
|
||||
|
||||
@mock.patch.object(images, 'image_show', autospec=True)
|
||||
def test_check_image_size_raw_stream_enabled_format_raw(self, show_mock):
|
||||
CONF.set_override('stream_raw_images', True, 'agent')
|
||||
# Image is bigger than memory but it's raw and will be streamed
|
||||
# so the test should pass
|
||||
show_mock.return_value = {
|
||||
'size': 15 * 1024 * 1024,
|
||||
}
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
shared=False) as task:
|
||||
task.node.properties['memory_mb'] = 10
|
||||
agent.check_image_size(task, 'fake-image', 'raw')
|
||||
show_mock.assert_called_once_with(self.context, 'fake-image')
|
||||
|
||||
@mock.patch.object(images, 'image_show', autospec=True)
|
||||
def test_check_image_size_raw_stream_enabled_format_qcow2(self, show_mock):
|
||||
CONF.set_override('stream_raw_images', True, 'agent')
|
||||
# Image is bigger than memory and won't be streamed
|
||||
show_mock.return_value = {
|
||||
'size': 15 * 1024 * 1024,
|
||||
}
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
shared=False) as task:
|
||||
task.node.properties['memory_mb'] = 10
|
||||
self.assertRaises(exception.InvalidParameterValue,
|
||||
agent.check_image_size,
|
||||
task, 'fake-image', 'qcow2')
|
||||
show_mock.assert_called_once_with(self.context, 'fake-image')
|
||||
|
||||
@mock.patch.object(images, 'image_show', autospec=True)
|
||||
def test_check_image_size_raw_stream_disabled(self, show_mock):
|
||||
CONF.set_override('stream_raw_images', False, 'agent')
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
If the disk format of the image is provided in the instance_info, skip the
|
||||
memory check if it is set to `raw` and raw image streaming is enabled. That
|
||||
allows to stream raw images provided as URL and not through Glance.
|
Loading…
Reference in New Issue
Block a user