Example #1
0
def check_image_size(task, image_source):
    """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.
    :raises: InvalidParameterValue if size of the image is greater than
        the available ram size.
    """
    node = task.node
    properties = node.properties
    # skip check if 'memory_mb' is not defined
    if 'memory_mb' not in properties:
        LOG.warning(_LW('Skip the image size check as memory_mb is not '
                        'defined in properties on node %s.'), node.uuid)
        return

    image_show = images.image_show(task.context, image_source)
    if CONF.agent.stream_raw_images and image_show.get('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

    memory_size = int(properties.get('memory_mb'))
    image_size = int(image_show['size'])
    reserved_size = CONF.agent.memory_consumed_by_agent
    if (image_size + (reserved_size * units.Mi)) > (memory_size * units.Mi):
        msg = (_('Memory size is too small for requested image, if it is '
                 'less than (image size + reserved RAM size), will break '
                 'the IPA deployments. Image size: %(image_size)d MiB, '
                 'Memory size: %(memory_size)d MiB, Reserved size: '
                 '%(reserved_size)d MiB.')
               % {'image_size': image_size / units.Mi,
                  'memory_size': memory_size,
                  'reserved_size': reserved_size})
        raise exception.InvalidParameterValue(msg)
Example #2
0
def check_image_size(task, image_source):
    """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.
    :raises: InvalidParameterValue if size of the image is greater than
        the available ram size.
    """
    node = task.node
    properties = node.properties
    # skip check if 'memory_mb' is not defined
    if 'memory_mb' not in properties:
        LOG.warning(_LW('Skip the image size check as memory_mb is not '
                        'defined in properties on node %s.'), node.uuid)
        return

    image_show = images.image_show(task.context, image_source)
    if CONF.agent.stream_raw_images and image_show.get('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

    memory_size = int(properties.get('memory_mb'))
    image_size = int(image_show['size'])
    reserved_size = CONF.agent.memory_consumed_by_agent
    if (image_size + (reserved_size * units.Mi)) > (memory_size * units.Mi):
        msg = (_('Memory size is too small for requested image, if it is '
                 'less than (image size + reserved RAM size), will break '
                 'the IPA deployments. Image size: %(image_size)d MiB, '
                 'Memory size: %(memory_size)d MiB, Reserved size: '
                 '%(reserved_size)d MiB.')
               % {'image_size': image_size / units.Mi,
                  'memory_size': memory_size,
                  'reserved_size': reserved_size})
        raise exception.InvalidParameterValue(msg)
Example #3
0
def check_image_size(task, image_source):
    """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.
    :raises: InvalidParameterValue if size of the image is greater than
        the available ram size.
    """
    node = task.node
    properties = node.properties
    # skip check if 'memory_mb' is not defined
    if "memory_mb" not in properties:
        LOG.warning(
            _LW("Skip the image size check as memory_mb is not " "defined in properties on node %s."), node.uuid
        )
        return

    image_show = images.image_show(task.context, image_source)
    if CONF.agent.stream_raw_images and image_show.get("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

    memory_size = int(properties.get("memory_mb"))
    image_size = int(image_show["size"])
    reserved_size = CONF.agent.memory_consumed_by_agent
    if (image_size + (reserved_size * units.Mi)) > (memory_size * units.Mi):
        msg = _(
            "Memory size is too small for requested image, if it is "
            "less than (image size + reserved RAM size), will break "
            "the IPA deployments. Image size: %(image_size)d MiB, "
            "Memory size: %(memory_size)d MiB, Reserved size: "
            "%(reserved_size)d MiB."
        ) % {"image_size": image_size / units.Mi, "memory_size": memory_size, "reserved_size": reserved_size}
        raise exception.InvalidParameterValue(msg)
Example #4
0
 def test_image_show_image_service(self):
     image_service_mock = mock.MagicMock()
     images.image_show('context', 'image_href', image_service_mock)
     image_service_mock.show.assert_called_once_with('image_href')
Example #5
0
 def test_image_show_no_image_service(self, image_service_mock):
     images.image_show('context', 'image_href')
     image_service_mock.assert_called_once_with('image_href',
                                                context='context')
     image_service_mock.return_value.show.assert_called_once_with(
         'image_href')
Example #6
0
 def test_image_show_image_service(self):
     image_service_mock = mock.MagicMock()
     images.image_show('context', 'image_href', image_service_mock)
     image_service_mock.show.assert_called_once_with('image_href')
Example #7
0
 def test_image_show_no_image_service(self, image_service_mock):
     images.image_show('context', 'image_href')
     image_service_mock.assert_called_once_with('image_href',
                                                context='context')
     image_service_mock.return_value.show.assert_called_once_with(
         'image_href')