diff --git a/ironic/drivers/modules/agent.py b/ironic/drivers/modules/agent.py index 9a9bb94b3b..a4576c0935 100644 --- a/ironic/drivers/modules/agent.py +++ b/ironic/drivers/modules/agent.py @@ -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) diff --git a/ironic/tests/unit/drivers/modules/test_agent.py b/ironic/tests/unit/drivers/modules/test_agent.py index 590a22e08e..a76bd5e556 100644 --- a/ironic/tests/unit/drivers/modules/test_agent.py +++ b/ironic/tests/unit/drivers/modules/test_agent.py @@ -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') diff --git a/releasenotes/notes/use-image-format-for-memory-check-25b1f06701ccdc47.yaml b/releasenotes/notes/use-image-format-for-memory-check-25b1f06701ccdc47.yaml new file mode 100644 index 0000000000..9684fb9a97 --- /dev/null +++ b/releasenotes/notes/use-image-format-for-memory-check-25b1f06701ccdc47.yaml @@ -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.