def test_get_glance_image_properties_default_all(self, image_service_mock): prop_dict = {'properties': {'p1': 'v1', 'p2': 'v2'}} image_service_obj_mock = image_service_mock.return_value image_service_obj_mock.show.return_value = prop_dict ret_val = images.get_glance_image_properties('con', 'uuid') image_service_mock.assert_called_once_with(version=1, context='con') image_service_obj_mock.show.assert_called_once_with('uuid') self.assertEqual({'p1': 'v1', 'p2': 'v2'}, ret_val)
def test_get_glance_image_properties_default_all( self, image_service_mock): prop_dict = {'properties': {'p1': 'v1', 'p2': 'v2'}} image_service_obj_mock = image_service_mock.return_value image_service_obj_mock.show.return_value = prop_dict ret_val = images.get_glance_image_properties('con', 'uuid') image_service_mock.assert_called_once_with(version=1, context='con') image_service_obj_mock.show.assert_called_once_with('uuid') self.assertEqual({'p1': 'v1', 'p2': 'v2'}, ret_val)
def _get_boot_iso(task, root_uuid): """This method returns a boot ISO to boot the node. It chooses one of the two options in the order as below: 1. Image deployed has a meta-property 'boot_iso' in Glance. This should refer to the UUID of the boot_iso which exists in Glance. 2. Generates a boot ISO on the fly using kernel and ramdisk mentioned in the image deployed. It uploads the generated boot ISO to Swift. :param task: a TaskManager instance containing the node to act on. :param root_uuid: the uuid of the root partition. :returns: the information about the boot ISO. Returns the information in the format 'glance:<glance-boot-iso-uuid>' or 'swift:<swift-boot_iso-object-name>'. In case of Swift, it is assumed that the object exists in CONF.ilo.swift_ilo_container. On error finding the boot iso, it returns None. :raises: MissingParameterValue, if any of the required parameters are missing in the node's driver_info or instance_info. :raises: InvalidParameterValue, if any of the parameters have invalid value in the node's driver_info or instance_info. :raises: SwiftOperationError, if operation with Swift fails. :raises: ImageCreationFailed, if creation of boot ISO failed. """ # Option 1 - Check if user has provided a boot_iso in Glance. LOG.debug("Trying to get a boot ISO to boot the baremetal node") deploy_info = _parse_deploy_info(task.node) image_href = deploy_info['image_source'] glance_properties = ( images.get_glance_image_properties(task.context, image_href, ['boot_iso', 'kernel_id', 'ramdisk_id'])) boot_iso_uuid = glance_properties.get('boot_iso') kernel_uuid = glance_properties.get('kernel_id') ramdisk_uuid = glance_properties.get('ramdisk_id') if boot_iso_uuid: LOG.debug("Found boot_iso %s in Glance", boot_iso_uuid) return 'glance:%s' % boot_iso_uuid # NOTE(faizan) For uefi boot_mode, operator should provide efi capable # boot-iso in glance if driver_utils.get_node_capability(task.node, 'boot_mode') == 'uefi': LOG.error(_LE("Unable to find boot_iso in Glance, required to deploy " "node %(node)s in UEFI boot mode."), {'node': task.node.uuid}) return if not kernel_uuid or not ramdisk_uuid: LOG.error(_LE("Unable to find 'kernel_id' and 'ramdisk_id' in Glance " "image %(image)s for generating boot ISO for %(node)s"), {'image': image_href, 'node': task.node.uuid}) return # NOTE(rameshg87): Functionality to share the boot ISOs created for # similar instances (instances with same deployed image) is # not implemented as of now. Creation/Deletion of such a shared boot ISO # will require synchronisation across conductor nodes for the shared boot # ISO. Such a synchronisation mechanism doesn't exist in ironic as of now. # Option 2 - Create boot_iso from kernel/ramdisk, upload to Swift # and provide its name. boot_iso_object_name = _get_boot_iso_object_name(task.node) kernel_params = CONF.pxe.pxe_append_params container = CONF.ilo.swift_ilo_container with tempfile.NamedTemporaryFile() as fileobj: boot_iso_tmp_file = fileobj.name images.create_boot_iso(task.context, boot_iso_tmp_file, kernel_uuid, ramdisk_uuid, root_uuid, kernel_params) swift_api = swift.SwiftAPI() swift_api.create_object(container, boot_iso_object_name, boot_iso_tmp_file) LOG.debug("Created boot_iso %s in Swift", boot_iso_object_name) return 'swift:%s' % boot_iso_object_name