Esempio n. 1
0
def _fetch(context, image_href, path, force_raw=False):
    """Fetch image and convert to raw format if needed."""
    path_tmp = "%s.part" % path
    images.fetch(context, image_href, path_tmp, force_raw=False)
    # Notes(yjiang5): If glance can provide the virtual size information,
    # then we can firstly clean cache and then invoke images.fetch().
    if force_raw:
        if images.force_raw_will_convert(image_href, path_tmp):
            required_space = images.converted_size(path_tmp, estimate=False)
            directory = os.path.dirname(path_tmp)
            try:
                _clean_up_caches(directory, required_space)
            except exception.InsufficientDiskSpace:

                # try again with an estimated raw size instead of the full size
                required_space = images.converted_size(path_tmp, estimate=True)
                try:
                    _clean_up_caches(directory, required_space)
                except exception.InsufficientDiskSpace:
                    LOG.warning(
                        'Not enough space for estimated image size. '
                        'Consider lowering '
                        '[DEFAULT]raw_image_growth_factor=%s',
                        CONF.raw_image_growth_factor)
                    raise

        images.image_to_raw(image_href, path, path_tmp)
    else:
        os.rename(path_tmp, path)
Esempio n. 2
0
def _setup_deploy_iso(task, ramdisk_options):
    """Attaches virtual media and sets it as boot device.

    This method attaches the given deploy ISO as virtual media, prepares the
    arguments for ramdisk in virtual media floppy.

    :param task: a TaskManager instance containing the node to act on.
    :param ramdisk_options: the options to be passed to the ramdisk in virtual
        media floppy.
    :raises: ImageRefValidationFailed if no image service can handle specified
       href.
    :raises: ImageCreationFailed, if it failed while creating the floppy image.
    :raises: IRMCOperationError, if some operation on iRMC failed.
    :raises: InvalidParameterValue if the validation of the
        PowerInterface or ManagementInterface fails.
    """
    d_info = task.node.driver_info

    deploy_iso_href = d_info['irmc_deploy_iso']
    if service_utils.is_image_href_ordinary_file_name(deploy_iso_href):
        deploy_iso_file = deploy_iso_href
    else:
        deploy_iso_file = _get_deploy_iso_name(task.node)
        deploy_iso_fullpathname = os.path.join(
            CONF.irmc.remote_image_share_root, deploy_iso_file)
        images.fetch(task.context, deploy_iso_href, deploy_iso_fullpathname)

    _setup_vmedia_for_boot(task, deploy_iso_file, ramdisk_options)
    manager_utils.node_set_boot_device(task, boot_devices.CDROM)
Esempio n. 3
0
def _setup_vmedia(task, mode, ramdisk_options):
    """Attaches virtual media and sets it as boot device.

    This method attaches the deploy or rescue ISO as virtual media, prepares
    the arguments for ramdisk in virtual media floppy.

    :param task: a TaskManager instance containing the node to act on.
    :param mode: Label indicating a deploy or rescue operation being
                 carried out on the node. Supported values are
                 'deploy' and 'rescue'.
    :param ramdisk_options: the options to be passed to the ramdisk in virtual
        media floppy.
    :raises: ImageRefValidationFailed if no image service can handle specified
       href.
    :raises: ImageCreationFailed, if it failed while creating the floppy image.
    :raises: IRMCOperationError, if some operation on iRMC failed.
    :raises: InvalidParameterValue if the validation of the
        PowerInterface or ManagementInterface fails.
    """

    if mode == 'rescue':
        iso = task.node.driver_info['irmc_rescue_iso']
    else:
        iso = task.node.driver_info['irmc_deploy_iso']

    if _is_image_href_ordinary_file_name(iso):
        iso_file = iso
    else:
        iso_file = _get_iso_name(task.node, label=mode)
        iso_fullpathname = os.path.join(CONF.irmc.remote_image_share_root,
                                        iso_file)
        images.fetch(task.context, iso, iso_fullpathname)

    _setup_vmedia_for_boot(task, iso_file, ramdisk_options)
    manager_utils.node_set_boot_device(task, boot_devices.CDROM)
Esempio n. 4
0
def _setup_vmedia(task, mode, ramdisk_options):
    """Attaches virtual media and sets it as boot device.

    This method attaches the deploy or rescue ISO as virtual media, prepares
    the arguments for ramdisk in virtual media floppy.

    :param task: a TaskManager instance containing the node to act on.
    :param mode: Label indicating a deploy or rescue operation being
                 carried out on the node. Supported values are
                 'deploy' and 'rescue'.
    :param ramdisk_options: the options to be passed to the ramdisk in virtual
        media floppy.
    :raises: ImageRefValidationFailed if no image service can handle specified
       href.
    :raises: ImageCreationFailed, if it failed while creating the floppy image.
    :raises: IRMCOperationError, if some operation on iRMC failed.
    :raises: InvalidParameterValue if the validation of the
        PowerInterface or ManagementInterface fails.
    """

    if mode == 'rescue':
        iso = task.node.driver_info['irmc_rescue_iso']
    else:
        iso = task.node.driver_info['irmc_deploy_iso']

    if _is_image_href_ordinary_file_name(iso):
        iso_file = iso
    else:
        iso_file = _get_iso_name(task.node, label=mode)
        iso_fullpathname = os.path.join(
            CONF.irmc.remote_image_share_root, iso_file)
        images.fetch(task.context, iso, iso_fullpathname)

    _setup_vmedia_for_boot(task, iso_file, ramdisk_options)
    manager_utils.node_set_boot_device(task, boot_devices.CDROM)
Esempio n. 5
0
def _setup_deploy_iso(task, ramdisk_options):
    """Attaches virtual media and sets it as boot device.

    This method attaches the given deploy ISO as virtual media, prepares the
    arguments for ramdisk in virtual media floppy.

    :param task: a TaskManager instance containing the node to act on.
    :param ramdisk_options: the options to be passed to the ramdisk in virtual
        media floppy.
    :raises: ImageRefValidationFailed if no image service can handle specified
       href.
    :raises: ImageCreationFailed, if it failed while creating the floppy image.
    :raises: IRMCOperationError, if some operation on iRMC failed.
    :raises: InvalidParameterValue if the validation of the
        PowerInterface or ManagementInterface fails.
    """
    d_info = task.node.driver_info

    deploy_iso_href = d_info["irmc_deploy_iso"]
    if service_utils.is_image_href_ordinary_file_name(deploy_iso_href):
        deploy_iso_file = deploy_iso_href
    else:
        deploy_iso_file = _get_deploy_iso_name(task.node)
        deploy_iso_fullpathname = os.path.join(CONF.irmc.remote_image_share_root, deploy_iso_file)
        images.fetch(task.context, deploy_iso_href, deploy_iso_fullpathname)

    _setup_vmedia_for_boot(task, deploy_iso_file, ramdisk_options)
    manager_utils.node_set_boot_device(task, boot_devices.CDROM)
Esempio n. 6
0
def _prepare_boot_iso(task, root_uuid):
    """Prepare a boot ISO to boot the node.

    :param task: a TaskManager instance containing the node to act on.
    :param root_uuid: the uuid of the root partition.
    :raises: MissingParameterValue, if any of the required parameters are
        missing.
    :raises: InvalidParameterValue, if any of the parameters have invalid
        value.
    :raises: ImageCreationFailed, if creating boot ISO
       for BIOS boot_mode failed.
    """
    deploy_info = _parse_deploy_info(task.node)
    driver_internal_info = task.node.driver_internal_info

    # fetch boot iso
    if deploy_info.get('irmc_boot_iso'):
        boot_iso_href = deploy_info['irmc_boot_iso']
        if _is_image_href_ordinary_file_name(boot_iso_href):
            driver_internal_info['irmc_boot_iso'] = boot_iso_href
        else:
            boot_iso_filename = _get_iso_name(task.node, label='boot')
            boot_iso_fullpathname = os.path.join(
                CONF.irmc.remote_image_share_root, boot_iso_filename)
            images.fetch(task.context, boot_iso_href, boot_iso_fullpathname)

            driver_internal_info['irmc_boot_iso'] = boot_iso_filename

    # create boot iso
    else:
        image_href = deploy_info['image_source']
        image_props = ['kernel_id', 'ramdisk_id']
        image_properties = images.get_image_properties(
            task.context, image_href, image_props)
        kernel_href = (task.node.instance_info.get('kernel')
                       or image_properties['kernel_id'])
        ramdisk_href = (task.node.instance_info.get('ramdisk')
                        or image_properties['ramdisk_id'])

        deploy_iso_href = deploy_info['irmc_deploy_iso']
        boot_mode = boot_mode_utils.get_boot_mode(task.node)
        kernel_params = CONF.pxe.pxe_append_params

        boot_iso_filename = _get_iso_name(task.node, label='boot')
        boot_iso_fullpathname = os.path.join(
            CONF.irmc.remote_image_share_root, boot_iso_filename)

        images.create_boot_iso(task.context, boot_iso_fullpathname,
                               kernel_href, ramdisk_href,
                               deploy_iso_href=deploy_iso_href,
                               root_uuid=root_uuid,
                               kernel_params=kernel_params,
                               boot_mode=boot_mode)

        driver_internal_info['irmc_boot_iso'] = boot_iso_filename

    # save driver_internal_info['irmc_boot_iso']
    task.node.driver_internal_info = driver_internal_info
    task.node.save()
Esempio n. 7
0
def _prepare_boot_iso(task, root_uuid):
    """Prepare a boot ISO to boot the node.

    :param task: a TaskManager instance containing the node to act on.
    :param root_uuid: the uuid of the root partition.
    :raises: MissingParameterValue, if any of the required parameters are
        missing.
    :raises: InvalidParameterValue, if any of the parameters have invalid
        value.
    :raises: ImageCreationFailed, if creating boot ISO
       for BIOS boot_mode failed.
    """
    deploy_info = _parse_deploy_info(task.node)
    driver_internal_info = task.node.driver_internal_info

    # fetch boot iso
    if deploy_info.get('irmc_boot_iso'):
        boot_iso_href = deploy_info['irmc_boot_iso']
        if service_utils.is_image_href_ordinary_file_name(boot_iso_href):
            driver_internal_info['irmc_boot_iso'] = boot_iso_href
        else:
            boot_iso_filename = _get_boot_iso_name(task.node)
            boot_iso_fullpathname = os.path.join(
                CONF.irmc.remote_image_share_root, boot_iso_filename)
            images.fetch(task.context, boot_iso_href, boot_iso_fullpathname)

            driver_internal_info['irmc_boot_iso'] = boot_iso_filename

    # create boot iso
    else:
        image_href = deploy_info['image_source']
        image_props = ['kernel_id', 'ramdisk_id']
        image_properties = images.get_image_properties(
            task.context, image_href, image_props)
        kernel_href = (task.node.instance_info.get('kernel') or
                       image_properties['kernel_id'])
        ramdisk_href = (task.node.instance_info.get('ramdisk') or
                        image_properties['ramdisk_id'])

        deploy_iso_filename = _get_deploy_iso_name(task.node)
        deploy_iso = ('file://' + os.path.join(
            CONF.irmc.remote_image_share_root, deploy_iso_filename))
        boot_mode = deploy_utils.get_boot_mode_for_deploy(task.node)
        kernel_params = CONF.pxe.pxe_append_params

        boot_iso_filename = _get_boot_iso_name(task.node)
        boot_iso_fullpathname = os.path.join(
            CONF.irmc.remote_image_share_root, boot_iso_filename)

        images.create_boot_iso(task.context, boot_iso_fullpathname,
                               kernel_href, ramdisk_href,
                               deploy_iso, root_uuid,
                               kernel_params, boot_mode)

        driver_internal_info['irmc_boot_iso'] = boot_iso_filename

    # save driver_internal_info['irmc_boot_iso']
    task.node.driver_internal_info = driver_internal_info
    task.node.save()
Esempio n. 8
0
def _fetch_to_raw(context, image_href, path, image_service=None):
    """Fetch image and convert to raw format if needed."""
    path_tmp = "%s.part" % path
    images.fetch(context, image_href, path_tmp, image_service)
    required_space = images.converted_size(path_tmp)
    directory = os.path.dirname(path_tmp)
    _clean_up_caches(directory, required_space)
    images.image_to_raw(image_href, path, path_tmp)
Esempio n. 9
0
def _fetch_to_raw(context, image_href, path, image_service=None):
    """Fetch image and convert to raw format if needed."""
    path_tmp = "%s.part" % path
    images.fetch(context, image_href, path_tmp, image_service)
    required_space = images.converted_size(path_tmp)
    directory = os.path.dirname(path_tmp)
    _clean_up_caches(directory, required_space)
    images.image_to_raw(image_href, path, path_tmp)
Esempio n. 10
0
    def test_fetch_image_service_force_raw(self, open_mock, image_to_raw_mock, image_service_mock):
        mock_file_handle = mock.MagicMock(spec=file)
        mock_file_handle.__enter__.return_value = "file"
        open_mock.return_value = mock_file_handle

        images.fetch("context", "image_href", "path", force_raw=True)

        open_mock.assert_called_once_with("path", "wb")
        image_service_mock.return_value.download.assert_called_once_with("image_href", "file")
        image_to_raw_mock.assert_called_once_with("image_href", "path", "path.part")
Esempio n. 11
0
    def test_fetch_image_service(self, open_mock):
        mock_file_handle = mock.MagicMock(spec=file)
        mock_file_handle.__enter__.return_value = 'file'
        open_mock.return_value = mock_file_handle
        image_service_mock = mock.Mock()

        images.fetch('context', 'image_href', 'path', image_service_mock)

        open_mock.assert_called_once_with('path', 'wb')
        image_service_mock.download.assert_called_once_with(
            'image_href', 'file')
Esempio n. 12
0
    def test_fetch_image_service_force_raw(self, open_mock, image_to_raw_mock,
                                           image_service_mock):
        mock_file_handle = mock.MagicMock(spec=file)
        mock_file_handle.__enter__.return_value = 'file'
        open_mock.return_value = mock_file_handle

        images.fetch('context', 'image_href', 'path', force_raw=True)

        open_mock.assert_called_once_with('path', 'wb')
        image_service_mock.return_value.download.assert_called_once_with(
            'image_href', 'file')
        image_to_raw_mock.assert_called_once_with('image_href', 'path',
                                                  'path.part')
Esempio n. 13
0
def _fetch(context, image_href, path, force_raw=False):
    """Fetch image and convert to raw format if needed."""
    path_tmp = "%s.part" % path
    images.fetch(context, image_href, path_tmp, force_raw=False)
    # Notes(yjiang5): If glance can provide the virtual size information,
    # then we can firstly clean cache and then invoke images.fetch().
    if force_raw:
        required_space = images.converted_size(path_tmp)
        directory = os.path.dirname(path_tmp)
        _clean_up_caches(directory, required_space)
        images.image_to_raw(image_href, path, path_tmp)
    else:
        os.rename(path_tmp, path)
Esempio n. 14
0
    def test_fetch_image_service_force_raw(self, open_mock, image_to_raw_mock,
                                           image_service_mock):
        mock_file_handle = mock.MagicMock(spec=file)
        mock_file_handle.__enter__.return_value = 'file'
        open_mock.return_value = mock_file_handle

        images.fetch('context', 'image_href', 'path', force_raw=True)

        open_mock.assert_called_once_with('path', 'wb')
        image_service_mock.return_value.download.assert_called_once_with(
            'image_href', 'file')
        image_to_raw_mock.assert_called_once_with(
            'image_href', 'path', 'path.part')
Esempio n. 15
0
def _fetch(context, image_href, path, force_raw=False):
    """Fetch image and convert to raw format if needed."""
    path_tmp = "%s.part" % path
    images.fetch(context, image_href, path_tmp, force_raw=False)
    # Notes(yjiang5): If glance can provide the virtual size information,
    # then we can firstly clean cache and then invoke images.fetch().
    if force_raw:
        required_space = images.converted_size(path_tmp)
        directory = os.path.dirname(path_tmp)
        _clean_up_caches(directory, required_space)
        images.image_to_raw(image_href, path, path_tmp)
    else:
        os.rename(path_tmp, path)