Beispiel #1
0
def _set_power_state(task, target_state):
    """Turns the server power on/off or do a reboot.

    :param task: a TaskManager instance containing the node to act on.
    :param target_state: target state of the node.
    :raises: InvalidParameterValue if an invalid power state was specified.
    :raises: MissingParameterValue if some mandatory information
        is missing on the node
    :raises: IRMCOperationError on an error from SCCI
    """

    node = task.node
    irmc_client = irmc_common.get_irmc_client(node)

    if target_state in (states.POWER_ON, states.REBOOT):
        irmc_boot.attach_boot_iso_if_needed(task)

    try:
        irmc_client(STATES_MAP[target_state])

    except KeyError:
        msg = _("_set_power_state called with invalid power state "
                "'%s'") % target_state
        raise exception.InvalidParameterValue(msg)

    except scci.SCCIClientError as irmc_exception:
        LOG.error(_LE("iRMC set_power_state failed to set state to %(tstate)s "
                      " for node %(node_id)s with error: %(error)s"),
                  {'tstate': target_state, 'node_id': node.uuid,
                   'error': irmc_exception})
        operation = _('iRMC set_power_state')
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)
Beispiel #2
0
def _set_power_state(task, target_state, timeout=None):
    """Turn the server power on/off or do a reboot.

    :param task: a TaskManager instance containing the node to act on.
    :param target_state: target state of the node.
    :param timeout: timeout (in seconds) positive integer (> 0) for any
      power state. ``None`` indicates default timeout.
    :raises: InvalidParameterValue if an invalid power state was specified.
    :raises: MissingParameterValue if some mandatory information
      is missing on the node
    :raises: IRMCOperationError on an error from SCCI or SNMP
    """
    node = task.node
    irmc_client = irmc_common.get_irmc_client(node)

    if target_state in (states.POWER_ON, states.REBOOT, states.SOFT_REBOOT):
        irmc_boot.attach_boot_iso_if_needed(task)

    try:
        irmc_client(STATES_MAP[target_state])

    except KeyError:
        msg = _("_set_power_state called with invalid power state "
                "'%s'") % target_state
        raise exception.InvalidParameterValue(msg)

    except scci.SCCIClientError as irmc_exception:
        LOG.error(
            "iRMC set_power_state failed to set state to %(tstate)s "
            " for node %(node_id)s with error: %(error)s", {
                'tstate': target_state,
                'node_id': node.uuid,
                'error': irmc_exception
            })
        operation = _('iRMC set_power_state')
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)

    try:
        if target_state in (states.SOFT_REBOOT, states.SOFT_POWER_OFF):
            # note (naohirot):
            # The following call covers both cases since SOFT_REBOOT matches
            # 'unknown' and SOFT_POWER_OFF matches 'off' or 'unknown'.
            _wait_power_state(task, states.SOFT_POWER_OFF, timeout=timeout)
        if target_state == states.SOFT_REBOOT:
            _wait_power_state(task, states.SOFT_REBOOT, timeout=timeout)

    except exception.SNMPFailure as snmp_exception:
        LOG.error(
            "iRMC failed to acknowledge the target state "
            "for node %(node_id)s. Error: %(error)s", {
                'node_id': node.uuid,
                'error': snmp_exception
            })
        raise exception.IRMCOperationError(operation=target_state,
                                           error=snmp_exception)
Beispiel #3
0
 def test_attach_boot_iso_if_needed_on_rebuild(
         self,
         setup_vmedia_mock,
         set_boot_device_mock):
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=True) as task:
         task.node.provision_state = states.DEPLOYING
         task.node.driver_internal_info['irmc_boot_iso'] = 'boot-iso'
         irmc_boot.attach_boot_iso_if_needed(task)
         self.assertFalse(setup_vmedia_mock.called)
         self.assertFalse(set_boot_device_mock.called)
Beispiel #4
0
 def test_attach_boot_iso_if_needed_on_rebuild(
         self,
         setup_vmedia_mock,
         set_boot_device_mock):
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=True) as task:
         task.node.provision_state = states.DEPLOYING
         task.node.driver_internal_info['irmc_boot_iso'] = 'boot-iso'
         irmc_boot.attach_boot_iso_if_needed(task)
         self.assertFalse(setup_vmedia_mock.called)
         self.assertFalse(set_boot_device_mock.called)
Beispiel #5
0
 def test_attach_boot_iso_if_needed(
         self,
         setup_vmedia_mock,
         set_boot_device_mock):
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=True) as task:
         task.node.provision_state = states.ACTIVE
         task.node.driver_internal_info['irmc_boot_iso'] = 'boot-iso'
         irmc_boot.attach_boot_iso_if_needed(task)
         setup_vmedia_mock.assert_called_once_with(task, 'boot-iso')
         set_boot_device_mock.assert_called_once_with(
             task, boot_devices.CDROM)
Beispiel #6
0
 def test_attach_boot_iso_if_needed(
         self,
         setup_vmedia_mock,
         set_boot_device_mock):
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=True) as task:
         task.node.provision_state = states.ACTIVE
         task.node.driver_internal_info['irmc_boot_iso'] = 'boot-iso'
         irmc_boot.attach_boot_iso_if_needed(task)
         setup_vmedia_mock.assert_called_once_with(task, 'boot-iso')
         set_boot_device_mock.assert_called_once_with(
             task, boot_devices.CDROM)
Beispiel #7
0
def _set_power_state(task, target_state, timeout=None):
    """Turn the server power on/off or do a reboot.

    :param task: a TaskManager instance containing the node to act on.
    :param target_state: target state of the node.
    :param timeout: timeout (in seconds) positive integer (> 0) for any
      power state. ``None`` indicates default timeout.
    :raises: InvalidParameterValue if an invalid power state was specified.
    :raises: MissingParameterValue if some mandatory information
      is missing on the node
    :raises: IRMCOperationError on an error from SCCI or SNMP
    """
    node = task.node
    irmc_client = irmc_common.get_irmc_client(node)

    if target_state in (states.POWER_ON, states.REBOOT, states.SOFT_REBOOT):
        irmc_boot.attach_boot_iso_if_needed(task)

    try:
        irmc_client(STATES_MAP[target_state])

    except KeyError:
        msg = _("_set_power_state called with invalid power state "
                "'%s'") % target_state
        raise exception.InvalidParameterValue(msg)

    except scci.SCCIClientError as irmc_exception:
        LOG.error("iRMC set_power_state failed to set state to %(tstate)s "
                  " for node %(node_id)s with error: %(error)s",
                  {'tstate': target_state, 'node_id': node.uuid,
                   'error': irmc_exception})
        operation = _('iRMC set_power_state')
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)

    try:
        if target_state in (states.SOFT_REBOOT, states.SOFT_POWER_OFF):
            # note (naohirot):
            # The following call covers both cases since SOFT_REBOOT matches
            # 'unknown' and SOFT_POWER_OFF matches 'off' or 'unknown'.
            _wait_power_state(task, states.SOFT_POWER_OFF, timeout=timeout)
        if target_state == states.SOFT_REBOOT:
            _wait_power_state(task, states.SOFT_REBOOT, timeout=timeout)

    except exception.SNMPFailure as snmp_exception:
        LOG.error("iRMC failed to acknowledge the target state "
                  "for node %(node_id)s. Error: %(error)s",
                  {'node_id': node.uuid, 'error': snmp_exception})
        raise exception.IRMCOperationError(operation=target_state,
                                           error=snmp_exception)
Beispiel #8
0
def _set_power_state(task, target_state):
    """Turns the server power on/off or do a reboot.

    :param task: a TaskManager instance containing the node to act on.
    :param target_state: target state of the node.
    :raises: InvalidParameterValue if an invalid power state was specified.
    :raises: MissingParameterValue if some mandatory information
        is missing on the node
    :raises: IRMCOperationError on an error from SCCI
    """

    node = task.node
    irmc_client = irmc_common.get_irmc_client(node)

    if target_state in (states.POWER_ON, states.REBOOT):
        irmc_boot.attach_boot_iso_if_needed(task)

    try:
        irmc_client(STATES_MAP[target_state])

    except KeyError:
        msg = _("_set_power_state called with invalid power state "
                "'%s'") % target_state
        raise exception.InvalidParameterValue(msg)

    except scci.SCCIClientError as irmc_exception:
        LOG.error(
            _LE("iRMC set_power_state failed to set state to %(tstate)s "
                " for node %(node_id)s with error: %(error)s"), {
                    'tstate': target_state,
                    'node_id': node.uuid,
                    'error': irmc_exception
                })
        operation = _('iRMC set_power_state')
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)