Example #1
0
    def set_boot_device(self, task, device, persistent=False):
        """Set the boot device for the task's node.

        Set the boot device to use on next reboot of the node.

        :param task: a task from TaskManager.
        :param device: the boot device, one of
                       :mod:`ironic.common.boot_devices`.
        :param persistent: Boolean value. True if the boot device will
                           persist to all future boots, False if not.
                           Default: False.
        :raises: InvalidParameterValue if an invalid boot device is specified
        :raises: MissingParameterValue if required ipmi parameters are missing.
        :raises: IPMIFailure on an error from ipmitool.

        """
        if device not in self.get_supported_boot_devices(task):
            raise exception.InvalidParameterValue(
                _("Invalid boot device %s specified.") % device)

        # note(JayF): IPMI spec indicates unless you send these raw bytes the
        # boot device setting times out after 60s. Since it's possible it
        # could be >60s before a node is rebooted, we should always send them.
        # This mimics pyghmi's current behavior, and the "option=timeout"
        # setting on newer ipmitool binaries.
        timeout_disable = "0x00 0x08 0x03 0x08"
        send_raw(task, timeout_disable)

        if task.node.driver_info.get('ipmi_force_boot_device', False):
            driver_utils.force_persistent_boot(task, device, persistent)
            # Reset persistent to False, in case of BMC does not support
            # persistent or we do not have admin rights.
            persistent = False

        cmd = "chassis bootdev %s" % device
        if persistent:
            cmd = cmd + " options=persistent"
        driver_info = _parse_driver_info(task.node)
        try:
            out, err = _exec_ipmitool(driver_info, cmd)
        except (exception.PasswordFileFailedToCreate,
                processutils.ProcessExecutionError) as e:
            LOG.warning(
                _LW('IPMI set boot device failed for node %(node)s '
                    'when executing "ipmitool %(cmd)s". '
                    'Error: %(error)s'), {
                        'node': driver_info['uuid'],
                        'cmd': cmd,
                        'error': e
                    })
            raise exception.IPMIFailure(cmd=cmd)
Example #2
0
    def set_boot_device(self, task, device, persistent=False):
        """Set the boot device for the task's node.

        Set the boot device to use on next reboot of the node.

        :param task: a task from TaskManager.
        :param device: the boot device, one of
                       :mod:`ironic.common.boot_devices`.
        :param persistent: Boolean value. True if the boot device will
                           persist to all future boots, False if not.
                           Default: False.
        :raises: InvalidParameterValue if an invalid boot device is specified
        :raises: MissingParameterValue if required ipmi parameters are missing.
        :raises: IPMIFailure on an error from ipmitool.

        """
        if device not in self.get_supported_boot_devices(task):
            raise exception.InvalidParameterValue(_(
                "Invalid boot device %s specified.") % device)

        # note(JayF): IPMI spec indicates unless you send these raw bytes the
        # boot device setting times out after 60s. Since it's possible it
        # could be >60s before a node is rebooted, we should always send them.
        # This mimics pyghmi's current behavior, and the "option=timeout"
        # setting on newer ipmitool binaries.
        timeout_disable = "0x00 0x08 0x03 0x08"
        send_raw(task, timeout_disable)

        if task.node.driver_info.get('ipmi_force_boot_device', False):
            driver_utils.force_persistent_boot(task,
                                               device,
                                               persistent)
            # Reset persistent to False, in case of BMC does not support
            # persistent or we do not have admin rights.
            persistent = False

        cmd = "chassis bootdev %s" % device
        if persistent:
            cmd = cmd + " options=persistent"
        driver_info = _parse_driver_info(task.node)
        try:
            out, err = _exec_ipmitool(driver_info, cmd)
        except (exception.PasswordFileFailedToCreate,
                processutils.ProcessExecutionError) as e:
            LOG.warning(_LW('IPMI set boot device failed for node %(node)s '
                            'when executing "ipmitool %(cmd)s". '
                            'Error: %(error)s'),
                        {'node': driver_info['uuid'], 'cmd': cmd, 'error': e})
            raise exception.IPMIFailure(cmd=cmd)
Example #3
0
 def test_force_persistent_boot_true(self):
     with task_manager.acquire(self.context, self.node.uuid, shared=False) as task:
         task.node.driver_info["ipmi_force_boot_device"] = True
         ret = driver_utils.force_persistent_boot(task, "pxe", True)
         self.assertIsNone(ret)
         task.node.refresh()
         self.assertIn("persistent_boot_device", task.node.driver_internal_info)
Example #4
0
 def test_force_persistent_boot_false(self):
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=False) as task:
         ret = driver_utils.force_persistent_boot(task, 'pxe', False)
         self.assertIsNone(ret)
         task.node.refresh()
         self.assertIs(
             False,
             task.node.driver_internal_info['is_next_boot_persistent'])
Example #5
0
 def test_force_persistent_boot_true(self):
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=False) as task:
         task.node.driver_info['ipmi_force_boot_device'] = True
         ret = driver_utils.force_persistent_boot(task, 'pxe', True)
         self.assertEqual(None, ret)
         task.node.refresh()
         self.assertIn('persistent_boot_device',
                       task.node.driver_internal_info)
Example #6
0
 def test_force_persistent_boot_true(self):
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=False) as task:
         task.node.driver_info['ipmi_force_boot_device'] = True
         ret = driver_utils.force_persistent_boot(task, 'pxe', True)
         self.assertEqual(None, ret)
         task.node.refresh()
         self.assertIn('persistent_boot_device',
                       task.node.driver_internal_info)
Example #7
0
 def test_force_persistent_boot_false(self):
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=False) as task:
         ret = driver_utils.force_persistent_boot(task, 'pxe', False)
         self.assertIsNone(ret)
         task.node.refresh()
         self.assertEqual(
             False,
             task.node.driver_internal_info['is_next_boot_persistent'])
Example #8
0
    def set_boot_device(self, task, device, persistent=False):
        """Set the boot device for the task's node.

        Set the boot device to use on next reboot of the node.

        :param task: a task from TaskManager.
        :param device: the boot device, one of
                       :mod:`ironic.common.boot_devices`.
        :param persistent: Boolean value. True if the boot device will
                           persist to all future boots, False if not.
                           Default: False.
        :raises: InvalidParameterValue if an invalid boot device is specified
                 or required ipmi credentials are missing.
        :raises: MissingParameterValue when required ipmi credentials
                 are missing.
        :raises: IPMIFailure on an error from pyghmi.
        """
        if device not in self.get_supported_boot_devices(task):
            raise exception.InvalidParameterValue(
                _("Invalid boot device %s specified.") % device)

        if task.node.driver_info.get('ipmi_force_boot_device', False):
            driver_utils.force_persistent_boot(task, device, persistent)
            # Reset persistent to False, in case of BMC does not support
            # persistent or we do not have admin rights.
            persistent = False

        boot_mode = deploy_utils.get_boot_mode_for_deploy(task.node)
        driver_info = _parse_driver_info(task.node)
        try:
            ipmicmd = ipmi_command.Command(bmc=driver_info['address'],
                                           userid=driver_info['username'],
                                           password=driver_info['password'])
            bootdev = _BOOT_DEVICES_MAP[device]
            uefiboot = boot_mode == 'uefi'
            ipmicmd.set_bootdev(bootdev, persist=persistent, uefiboot=uefiboot)
        except pyghmi_exception.IpmiException as e:
            LOG.error(
                _LE("IPMI set boot device failed for node %(node_id)s "
                    "with the following error: %(error)s"), {
                        'node_id': driver_info['uuid'],
                        'error': e
                    })
            raise exception.IPMIFailure(cmd=e)
Example #9
0
    def set_boot_device(self, task, device, persistent=False):
        """Set the boot device for the task's node.

        Set the boot device to use on next reboot of the node.

        :param task: a task from TaskManager.
        :param device: the boot device, one of
                       :mod:`ironic.common.boot_devices`.
        :param persistent: Boolean value. True if the boot device will
                           persist to all future boots, False if not.
                           Default: False.
        :raises: InvalidParameterValue if an invalid boot device is specified
                 or required ipmi credentials are missing.
        :raises: MissingParameterValue when required ipmi credentials
                 are missing.
        :raises: IPMIFailure on an error from pyghmi.
        """
        if device not in self.get_supported_boot_devices(task):
            raise exception.InvalidParameterValue(_(
                "Invalid boot device %s specified.") % device)

        if task.node.driver_info.get('ipmi_force_boot_device', False):
            driver_utils.force_persistent_boot(task,
                                               device,
                                               persistent)
            # Reset persistent to False, in case of BMC does not support
            # persistent or we do not have admin rights.
            persistent = False

        boot_mode = deploy_utils.get_boot_mode_for_deploy(task.node)
        driver_info = _parse_driver_info(task.node)
        try:
            ipmicmd = ipmi_command.Command(bmc=driver_info['address'],
                                           userid=driver_info['username'],
                                           password=driver_info['password'])
            bootdev = _BOOT_DEVICES_MAP[device]
            uefiboot = boot_mode == 'uefi'
            ipmicmd.set_bootdev(bootdev, persist=persistent, uefiboot=uefiboot)
        except pyghmi_exception.IpmiException as e:
            LOG.error(_LE("IPMI set boot device failed for node %(node_id)s "
                          "with the following error: %(error)s"),
                      {'node_id': driver_info['uuid'], 'error': e})
            raise exception.IPMIFailure(cmd=e)