def set_power_state(self, task, pstate): """Turn the power on or off. :param task: a TaskManager instance containing the node to act on. :param pstate: The desired power state, one of ironic.common.states POWER_ON, POWER_OFF. :raises: InvalidParameterValue if an invalid power state was specified. :raises: MissingParameterValue if required ipmi parameters are missing :raises: PowerStateFailure if the power couldn't be set to pstate. """ driver_info = _parse_driver_info(task.node) if pstate == states.POWER_ON: driver_utils.ensure_next_boot_device(task, driver_info) state = _power_on(driver_info) elif pstate == states.POWER_OFF: state = _power_off(driver_info) else: raise exception.InvalidParameterValue( _("set_power_state called " "with invalid power state %s.") % pstate) if state != pstate: raise exception.PowerStateFailure(pstate=pstate)
def set_power_state(self, task, pstate): """Turn the power on or off. :param task: a TaskManager instance containing the node to act on. :param pstate: a power state that will be set on the task's node. :raises: IPMIFailure when the native ipmi call fails. :raises: MissingParameterValue when required ipmi credentials are missing. :raises: InvalidParameterValue when an invalid power state is specified :raises: PowerStateFailure when invalid power state is returned from ipmi. """ driver_info = _parse_driver_info(task.node) if pstate == states.POWER_ON: driver_utils.ensure_next_boot_device(task, driver_info) _power_on(driver_info) elif pstate == states.POWER_OFF: _power_off(driver_info) else: raise exception.InvalidParameterValue( _("set_power_state called with an invalid power state: %s.") % pstate)
def test_ensure_next_boot_device(self, node_set_boot_device_mock): with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: task.node.driver_internal_info['persistent_boot_device'] = 'pxe' driver_utils.ensure_next_boot_device(task, {'force_boot_device': True}) node_set_boot_device_mock.assert_called_once_with(task, 'pxe')
def set_power_state(self, task, pstate): """Turn the power on or off. :param task: a TaskManager instance containing the node to act on. :param pstate: a power state that will be set on the task's node. :raises: IPMIFailure when the native ipmi call fails. :raises: MissingParameterValue when required ipmi credentials are missing. :raises: InvalidParameterValue when an invalid power state is specified :raises: PowerStateFailure when invalid power state is returned from ipmi. """ driver_info = _parse_driver_info(task.node) if pstate == states.POWER_ON: driver_utils.ensure_next_boot_device(task, driver_info) _power_on(driver_info) elif pstate == states.POWER_OFF: _power_off(driver_info) else: raise exception.InvalidParameterValue( _("set_power_state called with an invalid power state: %s." ) % pstate)
def test_ensure_next_boot_device_clears_is_next_boot_persistent(self): with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: task.node.driver_internal_info["persistent_boot_device"] = "pxe" task.node.driver_internal_info["is_next_boot_persistent"] = False driver_utils.ensure_next_boot_device(task, {"force_boot_device": True}) task.node.refresh() self.assertNotIn("is_next_boot_persistent", task.node.driver_internal_info)
def test_ensure_next_boot_device(self, node_set_boot_device_mock): with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: task.node.driver_internal_info['persistent_boot_device'] = 'pxe' driver_utils.ensure_next_boot_device( task, {'force_boot_device': True} ) node_set_boot_device_mock.assert_called_once_with(task, 'pxe')
def test_ensure_next_boot_device_clears_is_next_boot_persistent(self): with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: task.node.driver_internal_info['persistent_boot_device'] = 'pxe' task.node.driver_internal_info['is_next_boot_persistent'] = False driver_utils.ensure_next_boot_device(task, {'force_boot_device': True}) task.node.refresh() self.assertNotIn('is_next_boot_persistent', task.node.driver_internal_info)
def test_ensure_next_boot_device_clears_is_next_boot_persistent(self): with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: task.node.driver_internal_info['persistent_boot_device'] = 'pxe' task.node.driver_internal_info['is_next_boot_persistent'] = False driver_utils.ensure_next_boot_device( task, {'force_boot_device': True} ) task.node.refresh() self.assertNotIn('is_next_boot_persistent', task.node.driver_internal_info)
def reboot(self, task): """Cycles the power to the task's node. :param task: a TaskManager instance containing the node to act on. :raises: IPMIFailure when the native ipmi call fails. :raises: MissingParameterValue when required ipmi credentials are missing. :raises: PowerStateFailure when invalid power state is returned from ipmi. """ driver_info = _parse_driver_info(task.node) driver_utils.ensure_next_boot_device(task, driver_info) _reboot(driver_info)
def reboot(self, task): """Cycles the power to the task's node. :param task: a TaskManager instance containing the node to act on. :raises: MissingParameterValue if required ipmi parameters are missing. :raises: InvalidParameterValue if an invalid power state was specified. :raises: PowerStateFailure if the final state of the node is not POWER_ON. """ driver_info = _parse_driver_info(task.node) _power_off(driver_info) driver_utils.ensure_next_boot_device(task, driver_info) state = _power_on(driver_info) if state != states.POWER_ON: raise exception.PowerStateFailure(pstate=states.POWER_ON)