def test_setup_vmedia_for_boot_with_url(self, attach_vmedia_mock): boot_iso = 'http://abc.com/img.iso' with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: ilo_common.setup_vmedia_for_boot(task, boot_iso) attach_vmedia_mock.assert_called_once_with(task.node, 'CDROM', boot_iso)
def _reboot_into(task, iso, ramdisk_options): """Reboots the node into a given boot ISO. This method attaches the given bootable ISO as virtual media, prepares the arguments for ramdisk in virtual media floppy, and then reboots the node. :param task: a TaskManager instance containing the node to act on. :param iso: a bootable ISO image href to attach to. Should be either of below: * A Swift object - It should be of format 'swift:<object-name>'. It is assumed that the image object is present in CONF.ilo.swift_ilo_container; * A Glance image - It should be format 'glance://<glance-image-uuid>' or just <glance-image-uuid>; * An HTTP URL. :param ramdisk_options: the options to be passed to the ramdisk in virtual media floppy. :raises: ImageCreationFailed, if it failed while creating the floppy image. :raises: IloOperationError, if some operation on iLO failed. """ ilo_common.setup_vmedia_for_boot(task, iso, ramdisk_options) # In UEFI boot mode, upon inserting virtual CDROM, one has to reset the # system to see it as a valid boot device in persistent boot devices. # But virtual CDROM device is always available for one-time boot. # During enable/disable of secure boot settings, iLO internally resets # the server twice. But it retains one time boot settings across internal # resets. Hence no impact of this change for secure boot deploy. manager_utils.node_set_boot_device(task, boot_devices.CDROM) manager_utils.node_power_action(task, states.REBOOT)
def _configure_vmedia_boot(self, task, root_uuid): """Configure vmedia boot for the node. :param task: a task from TaskManager. :param root_uuid: uuid of the root partition :returns: None :raises: IloOperationError, if some operation on iLO failed. """ node = task.node boot_iso = _get_boot_iso(task, root_uuid) if not boot_iso: LOG.error("Cannot get boot ISO for node %s", node.uuid) return # Upon deploy complete, some distros cloud images reboot the system as # part of its configuration. Hence boot device should be persistent and # not one-time. ilo_common.setup_vmedia_for_boot(task, boot_iso) manager_utils.node_set_boot_device(task, boot_devices.CDROM, persistent=True) i_info = node.instance_info i_info['ilo_boot_iso'] = boot_iso node.instance_info = i_info node.save()
def test_setup_vmedia_for_boot_with_swift(self, attach_vmedia_mock, swift_api_mock): swift_obj_mock = swift_api_mock.return_value boot_iso = "swift:object-name" swift_obj_mock.get_temp_url.return_value = "image_url" CONF.keystone_authtoken.auth_uri = "http://authurl" CONF.ilo.swift_ilo_container = "ilo_cont" CONF.ilo.swift_object_expiry_timeout = 1 with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: ilo_common.setup_vmedia_for_boot(task, boot_iso) swift_obj_mock.get_temp_url.assert_called_once_with("ilo_cont", "object-name", 1) attach_vmedia_mock.assert_called_once_with(task.node, "CDROM", "image_url")
def test_setup_vmedia_for_boot_with_parameters(self, prepare_image_mock, attach_vmedia_mock, temp_url_mock): parameters = {"a": "b"} boot_iso = "733d1c44-a2ea-414b-aca7-69decf20d810" prepare_image_mock.return_value = "floppy_url" temp_url_mock.return_value = "image_url" with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: ilo_common.setup_vmedia_for_boot(task, boot_iso, parameters) prepare_image_mock.assert_called_once_with(task, parameters) attach_vmedia_mock.assert_any_call(task.node, "FLOPPY", "floppy_url") temp_url_mock.assert_called_once_with(task.context, "733d1c44-a2ea-414b-aca7-69decf20d810") attach_vmedia_mock.assert_any_call(task.node, "CDROM", "image_url")
def _continue_deploy(self, task, **kwargs): """Continues the iSCSI deployment from where ramdisk left off. Continues the iSCSI deployment from the conductor node, finds the boot ISO to boot the node, and sets the node to boot from boot ISO. :param task: a TaskManager instance containing the node to act on. :param kwargs: kwargs containing parameters for iSCSI deployment. """ node = task.node if node.provision_state != states.DEPLOYWAIT: LOG.error(_LE('Node %s is not waiting to be deployed.'), node.uuid) return ilo_common.cleanup_vmedia_boot(task) root_uuid = iscsi_deploy.continue_deploy(task, **kwargs) if not root_uuid: return try: boot_iso = _get_boot_iso(task, root_uuid) if not boot_iso: LOG.error(_LE("Cannot get boot ISO for node %s"), node.uuid) return ilo_common.setup_vmedia_for_boot(task, boot_iso) ilo_common.set_boot_device(node, 'CDROM') address = kwargs.get('address') deploy_utils.notify_deploy_complete(address) node.provision_state = states.ACTIVE node.target_provision_state = states.NOSTATE i_info = node.instance_info i_info['ilo_boot_iso'] = boot_iso node.instance_info = i_info node.save() LOG.info(_LI('Deployment to node %s done'), node.uuid) except Exception as e: LOG.error( _LE('Deploy failed for instance %(instance)s. ' 'Error: %(error)s'), { 'instance': node.instance_uuid, 'error': e }) msg = _('Failed to continue iSCSI deployment.') iscsi_deploy.set_failed_state(task, msg)
def _attach_boot_iso(task): """Attaches boot ISO for a deployed node. This method checks the instance info of the baremetal node for a boot iso. It attaches the boot ISO on the baremetal node, and then sets the node to boot from virtual media cdrom. :param task: a TaskManager instance containing the node to act on. """ i_info = task.node.instance_info if 'ilo_boot_iso' in i_info: ilo_common.setup_vmedia_for_boot(task, i_info['ilo_boot_iso']) manager_utils.node_set_boot_device(task, boot_devices.CDROM)
def test_setup_vmedia_for_boot_with_swift(self, attach_vmedia_mock, swift_api_mock): swift_obj_mock = swift_api_mock.return_value boot_iso = 'swift:object-name' swift_obj_mock.get_temp_url.return_value = 'image_url' CONF.keystone_authtoken.auth_uri = 'http://authurl' CONF.ilo.swift_ilo_container = 'ilo_cont' CONF.ilo.swift_object_expiry_timeout = 1 with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: ilo_common.setup_vmedia_for_boot(task, boot_iso) swift_obj_mock.get_temp_url.assert_called_once_with( 'ilo_cont', 'object-name', 1) attach_vmedia_mock.assert_called_once_with(task.node, 'CDROM', 'image_url')
def test_setup_vmedia_for_boot_with_parameters(self, prepare_image_mock, attach_vmedia_mock, temp_url_mock): parameters = {'a': 'b'} boot_iso = 'glance:image-uuid' prepare_image_mock.return_value = 'floppy_url' temp_url_mock.return_value = 'image_url' with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: ilo_common.setup_vmedia_for_boot(task, boot_iso, parameters) prepare_image_mock.assert_called_once_with(task, parameters) attach_vmedia_mock.assert_any_call(task.node, 'FLOPPY', 'floppy_url') temp_url_mock.assert_called_once_with(task.context, 'image-uuid') attach_vmedia_mock.assert_any_call(task.node, 'CDROM', 'image_url')
def _continue_deploy(self, task, **kwargs): """Continues the iSCSI deployment from where ramdisk left off. Continues the iSCSI deployment from the conductor node, finds the boot ISO to boot the node, and sets the node to boot from boot ISO. :param task: a TaskManager instance containing the node to act on. :param kwargs: kwargs containing parameters for iSCSI deployment. """ node = task.node if node.provision_state != states.DEPLOYWAIT: LOG.error(_LE('Node %s is not waiting to be deployed.'), node.uuid) return ilo_common.cleanup_vmedia_boot(task) root_uuid = iscsi_deploy.continue_deploy(task, **kwargs) if not root_uuid: return try: boot_iso = _get_boot_iso(task, root_uuid) if not boot_iso: LOG.error(_LE("Cannot get boot ISO for node %s"), node.uuid) return ilo_common.setup_vmedia_for_boot(task, boot_iso) ilo_common.set_boot_device(node, 'CDROM') address = kwargs.get('address') deploy_utils.notify_deploy_complete(address) node.provision_state = states.ACTIVE node.target_provision_state = states.NOSTATE i_info = node.instance_info i_info['ilo_boot_iso'] = boot_iso node.instance_info = i_info node.save() LOG.info(_LI('Deployment to node %s done'), node.uuid) except Exception as e: LOG.error(_LE('Deploy failed for instance %(instance)s. ' 'Error: %(error)s'), {'instance': node.instance_uuid, 'error': e}) msg = _('Failed to continue iSCSI deployment.') iscsi_deploy.set_failed_state(task, msg)
def _configure_vmedia_boot(self, task, root_uuid): """Configure vmedia boot for the node.""" node = task.node boot_iso = _get_boot_iso(task, root_uuid) if not boot_iso: LOG.error(_LE("Cannot get boot ISO for node %s"), node.uuid) return # Upon deploy complete, some distros cloud images reboot the system as # part of its configuration. Hence boot device should be persistent and # not one-time. ilo_common.setup_vmedia_for_boot(task, boot_iso) manager_utils.node_set_boot_device(task, boot_devices.CDROM, persistent=True) i_info = node.instance_info if not i_info.get("ilo_boot_iso"): i_info["ilo_boot_iso"] = boot_iso node.instance_info = i_info
def _continue_deploy(self, task, **kwargs): """Continues the iSCSI deployment from where ramdisk left off. Continues the iSCSI deployment from the conductor node, finds the boot ISO to boot the node, and sets the node to boot from boot ISO. :param task: a TaskManager instance containing the node to act on. :param kwargs: kwargs containing parameters for iSCSI deployment. :raises: InvalidState """ node = task.node task.process_event('resume') ilo_common.cleanup_vmedia_boot(task) root_uuid = iscsi_deploy.continue_deploy(task, **kwargs) if not root_uuid: return try: boot_iso = _get_boot_iso(task, root_uuid) if not boot_iso: LOG.error(_LE("Cannot get boot ISO for node %s"), node.uuid) return ilo_common.setup_vmedia_for_boot(task, boot_iso) manager_utils.node_set_boot_device(task, boot_devices.CDROM) address = kwargs.get('address') deploy_utils.notify_deploy_complete(address) LOG.info(_LI('Deployment to node %s done'), node.uuid) i_info = node.instance_info i_info['ilo_boot_iso'] = boot_iso node.instance_info = i_info task.process_event('done') except Exception as e: LOG.error(_LE('Deploy failed for instance %(instance)s. ' 'Error: %(error)s'), {'instance': node.instance_uuid, 'error': e}) msg = _('Failed to continue iSCSI deployment.') deploy_utils.set_failed_state(task, msg)
def _reboot_into(task, iso, ramdisk_options): """Reboots the node into a given boot ISO. This method attaches the given bootable ISO as virtual media, prepares the arguments for ramdisk in virtual media floppy, and then reboots the node. :param task: a TaskManager instance containing the node to act on. :param iso: a bootable ISO image to attach to. The boot iso should be present in either Glance or in Swift. If present in Glance, it should be of format 'glance:<glance-image-uuid>'. If present in Swift, it should be of format 'swift:<object-name>'. It is assumed that object is present in CONF.ilo.swift_ilo_container. :param ramdisk_options: the options to be passed to the ramdisk in virtual media floppy. :raises: ImageCreationFailed, if it failed while creating the floppy image. :raises: IloOperationError, if some operation on iLO failed. """ ilo_common.setup_vmedia_for_boot(task, iso, ramdisk_options) manager_utils.node_set_boot_device(task, boot_devices.CDROM) manager_utils.node_power_action(task, states.REBOOT)
def _configure_vmedia_boot(self, task, root_uuid): """Configure vmedia boot for the node.""" node = task.node boot_iso = _get_boot_iso(task, root_uuid) if not boot_iso: LOG.error(_LE("Cannot get boot ISO for node %s"), node.uuid) return # Upon deploy complete, some distros cloud images reboot the system as # part of its configuration. Hence boot device should be persistent and # not one-time. ilo_common.setup_vmedia_for_boot(task, boot_iso) manager_utils.node_set_boot_device(task, boot_devices.CDROM, persistent=True) i_info = node.instance_info if not i_info.get('ilo_boot_iso'): i_info['ilo_boot_iso'] = boot_iso node.instance_info = i_info
def _attach_boot_iso(task): """Attaches boot ISO for a deployed node. This method checks the instance info of the baremetal node for a boot iso. It attaches the boot ISO on the baremetal node, and then sets the node to boot from virtual media cdrom. :param task: a TaskManager instance containing the node to act on. """ i_info = task.node.instance_info node_state = task.node.provision_state # NOTE: On instance rebuild, ilo_boot_iso will be present in # instance_info but the node will be in DEPLOYING state. # In such a scenario, the ilo_boot_iso shouldn't be # attached to the node while powering on the node (the node # should boot from deploy ramdisk instead, which will already # be attached by the deploy driver). if 'ilo_boot_iso' in i_info and node_state == states.ACTIVE: ilo_common.setup_vmedia_for_boot(task, i_info['ilo_boot_iso']) manager_utils.node_set_boot_device(task, boot_devices.CDROM)
def prepare_instance(self, task): """Prepares the boot of instance. This method prepares the boot of the instance after reading relevant information from the node's instance_info. It does the following depending on boot_option for deploy: - If the boot mode is 'uefi' and its booting from volume, then it sets the iSCSI target info and node to boot from 'UefiTarget' boot device. - If not 'boot from volume' and the boot_option requested for this deploy is 'local' or image is a whole disk image, then it sets the node to boot from disk. - Otherwise it finds/creates the boot ISO to boot the instance image, attaches the boot ISO to the bare metal and then sets the node to boot from CDROM. :param task: a task from TaskManager. :returns: None :raises: IloOperationError, if some operation on iLO failed. :raises: InstanceDeployFailure, if its try to boot iSCSI volume in 'BIOS' boot mode. """ ilo_common.cleanup_vmedia_boot(task) boot_mode = boot_mode_utils.get_boot_mode_for_deploy(task.node) boot_option = deploy_utils.get_boot_option(task.node) if deploy_utils.is_iscsi_boot(task): # It will set iSCSI info onto iLO if boot_mode == 'uefi': # Need to set 'ilo_uefi_iscsi_boot' param for clean up driver_internal_info = task.node.driver_internal_info driver_internal_info['ilo_uefi_iscsi_boot'] = True task.node.driver_internal_info = driver_internal_info task.node.save() task.driver.management.set_iscsi_boot_target(task) manager_utils.node_set_boot_device( task, boot_devices.ISCSIBOOT, persistent=True) else: msg = 'Virtual media can not boot volume in BIOS boot mode.' raise exception.InstanceDeployFailure(msg) elif boot_option == "ramdisk": boot_iso = _get_boot_iso(task, None) ilo_common.setup_vmedia_for_boot(task, boot_iso) manager_utils.node_set_boot_device(task, boot_devices.CDROM, persistent=True) else: # Boot from disk every time if the image deployed is # a whole disk image. node = task.node iwdi = node.driver_internal_info.get('is_whole_disk_image') if deploy_utils.get_boot_option(node) == "local" or iwdi: manager_utils.node_set_boot_device(task, boot_devices.DISK, persistent=True) else: drv_int_info = node.driver_internal_info root_uuid_or_disk_id = drv_int_info.get('root_uuid_or_disk_id') if root_uuid_or_disk_id: self._configure_vmedia_boot(task, root_uuid_or_disk_id) else: LOG.warning("The UUID for the root partition could not " "be found for node %s", node.uuid) # Set boot mode ilo_common.update_boot_mode(task) # Need to enable secure boot, if being requested ilo_common.update_secure_boot_mode(task, True)
def prepare_instance(self, task): """Prepares the boot of instance. This method prepares the boot of the instance after reading relevant information from the node's instance_info. It does the following depending on boot_option for deploy: - If the boot mode is 'uefi' and its booting from volume, then it sets the iSCSI target info and node to boot from 'UefiTarget' boot device. - If not 'boot from volume' and the boot_option requested for this deploy is 'local' or image is a whole disk image, then it sets the node to boot from disk. - Otherwise it finds/creates the boot ISO to boot the instance image, attaches the boot ISO to the bare metal and then sets the node to boot from CDROM. :param task: a task from TaskManager. :returns: None :raises: IloOperationError, if some operation on iLO failed. :raises: InstanceDeployFailure, if its try to boot iSCSI volume in 'BIOS' boot mode. """ ilo_common.cleanup_vmedia_boot(task) boot_mode = boot_mode_utils.get_boot_mode(task.node) boot_option = deploy_utils.get_boot_option(task.node) if deploy_utils.is_iscsi_boot(task): # It will set iSCSI info onto iLO if boot_mode == 'uefi': # Need to set 'ilo_uefi_iscsi_boot' param for clean up driver_internal_info = task.node.driver_internal_info driver_internal_info['ilo_uefi_iscsi_boot'] = True task.node.driver_internal_info = driver_internal_info task.node.save() task.driver.management.set_iscsi_boot_target(task) manager_utils.node_set_boot_device( task, boot_devices.ISCSIBOOT, persistent=True) else: msg = 'Virtual media can not boot volume in BIOS boot mode.' raise exception.InstanceDeployFailure(msg) elif boot_option == "ramdisk": boot_iso = _get_boot_iso(task, None) ilo_common.setup_vmedia_for_boot(task, boot_iso) manager_utils.node_set_boot_device(task, boot_devices.CDROM, persistent=True) else: # Boot from disk every time if the image deployed is # a whole disk image. node = task.node iwdi = node.driver_internal_info.get('is_whole_disk_image') if deploy_utils.get_boot_option(node) == "local" or iwdi: manager_utils.node_set_boot_device(task, boot_devices.DISK, persistent=True) else: drv_int_info = node.driver_internal_info root_uuid_or_disk_id = drv_int_info.get('root_uuid_or_disk_id') if root_uuid_or_disk_id: self._configure_vmedia_boot(task, root_uuid_or_disk_id) else: LOG.warning("The UUID for the root partition could not " "be found for node %s", node.uuid) # Set boot mode ilo_common.update_boot_mode(task) # Need to enable secure boot, if being requested ilo_common.update_secure_boot_mode(task, True)