def test_expire_old_sessions(self, mock_service): for num in range(20): self.node.driver_info['ibmc_username'] = '******' % num ibmc_utils.get_system(self.node) self.assertEqual(mock_service.call_count, 20) self.assertEqual(len(ibmc_utils.SessionCache.sessions), 10)
def test_auth_auto(self, mock_service): ibmc_utils.get_system(self.node) mock_service.assert_called_with( self.parsed_driver_info['address'], username=self.parsed_driver_info['username'], password=self.parsed_driver_info['password'], verify_ca=True)
def get_boot_device(self, task): """Get the current boot device for a node. :param task: A task from TaskManager. :raises: InvalidParameterValue on malformed parameter(s) :raises: MissingParameterValue on missing parameter(s) :raises: IBMCConnectionError when it fails to connect to iBMC :raises: IBMCError on an error from the iBMC :returns: a dictionary containing: :boot_device: the boot device, one of :mod:`ironic.common.boot_devices` or None if it is unknown. :persistent: Boolean value or None, True if the boot device persists, False otherwise. None if it's disabled. """ self.validate(task) system = utils.get_system(task.node) boot = system.boot target = boot.get('target') enabled = boot.get('enabled') return { 'boot_device': mappings.BOOT_DEVICE_MAP.get(target), 'persistent': mappings.BOOT_DEVICE_PERSISTENT_MAP.get(enabled) }
def set_boot_device(self, task, device, persistent=False): """Set the boot device for a node. :param task: A task from TaskManager. :param device: The boot device, one of :mod:`ironic.common.boot_device`. :param persistent: Boolean value. True if the boot device will persist to all future boots, False if not. Default: False. :raises: InvalidParameterValue on malformed parameter(s) :raises: MissingParameterValue on missing parameter(s) :raises: IBMCConnectionError when it fails to connect to iBMC :raises: IBMCError on an error from the iBMC """ self.validate(task) system = utils.get_system(task.node) try: system.set_system_boot_source( mappings.BOOT_DEVICE_MAP_REV[device], enabled=mappings.BOOT_DEVICE_PERSISTENT_MAP_REV[persistent]) except requests.exceptions.RequestException as e: error_msg = (_('IBMC set boot device failed for node ' '%(node)s. Error: %(error)s') % { 'node': task.node.uuid, 'error': e }) LOG.error(error_msg) raise exception.IBMCError(error=error_msg)
def set_power_state(self, task, power_state, timeout=None): """Set the power state of the task's node. :param task: A TaskManager instance containing the node to act on. :param power_state: Any power state from :mod:`ironic.common.states`. :param timeout: Time to wait for the node to reach the requested state. :raises: InvalidParameterValue on malformed parameter(s) :raises: MissingParameterValue if a required parameter is missing. :raises: IBMCConnectionError when it fails to connect to iBMC :raises: IBMCError on an error from the iBMC """ self.validate(task) system = utils.get_system(task.node) try: system.reset_system( mappings.SET_POWER_STATE_MAP_REV.get(power_state)) except requests.exceptions.RequestException as e: error_msg = (_('IBMC set power state failed for node ' '%(node)s. Error: %(error)s') % { 'node': task.node.uuid, 'error': e }) LOG.error(error_msg) raise exception.IBMCError(error=error_msg) target_state = TARGET_STATE_MAP.get(power_state, power_state) cond_utils.node_wait_for_power_state(task, target_state, timeout=timeout)
def reboot(self, task, timeout=None): """Perform a hard reboot of the task's node. :param task: A TaskManager instance containing the node to act on. :param timeout: Time to wait for the node to become powered on. :raises: InvalidParameterValue on malformed parameter(s) :raises: MissingParameterValue if a required parameter is missing. :raises: IBMCConnectionError when it fails to connect to iBMC :raises: IBMCError on an error from the iBMC """ self.validate(task) system = utils.get_system(task.node) current_power_state = (mappings.GET_POWER_STATE_MAP.get( system.power_state)) try: if current_power_state == states.POWER_ON: system.reset_system( mappings.SET_POWER_STATE_MAP_REV.get(states.REBOOT)) else: system.reset_system( mappings.SET_POWER_STATE_MAP_REV.get(states.POWER_ON)) except requests.exceptions.RequestException as e: error_msg = (_('IBMC reboot failed for node %(node)s. ' 'Error: %(error)s') % { 'node': task.node.uuid, 'error': e }) LOG.error(error_msg) raise exception.IBMCError(error=error_msg) cond_utils.node_wait_for_power_state(task, states.POWER_ON, timeout=timeout)
def test_get_system(self, mock_service): fake_conn = mock_service.return_value fake_system = fake_conn.get_system.return_value response = ibmc_utils.get_system(self.node) self.assertEqual(fake_system, response) fake_conn.get_system.assert_called_once_with( '/redfish/v1/Systems/FAKESYSTEM')
def get_supported_boot_devices(self, task): """Get a list of the supported boot devices. :param task: a task from TaskManager. :raises: InvalidParameterValue on malformed parameter(s) :raises: MissingParameterValue on missing parameter(s) :returns: A list with the supported boot devices defined in :mod:`ironic.common.boot_devices`. """ self.validate(task) system = utils.get_system(task.node) supported_boot_devices = system.get_supported_boot_devices() return list(map(mappings.BOOT_DEVICE_MAP.get, supported_boot_devices))
def get_power_state(self, task): """Get the current power state of the task's node. :param task: A TaskManager instance containing the node to act on. :returns: A power state. One of :mod:`ironic.common.states`. :raises: InvalidParameterValue on malformed parameter(s) :raises: MissingParameterValue on missing parameter(s) :raises: IBMCConnectionError when it fails to connect to iBMC :raises: IBMCError on an error from the iBMC """ self.validate(task) system = utils.get_system(task.node) return mappings.GET_POWER_STATE_MAP.get(system.power_state)
def get_boot_mode(self, task): """Get the current boot mode for a node. Provides the current boot mode of the node. :param task: A task from TaskManager. :raises: InvalidParameterValue on malformed parameter(s) :raises: MissingParameterValue on missing parameter(s) :raises: IBMCConnectionError when it fails to connect to iBMC :returns: The boot mode, one of :mod:`ironic.common.boot_mode` or None if it is unknown. """ self.validate(task) system = utils.get_system(task.node) return mappings.BOOT_MODE_MAP.get(system.boot.get('mode'))
def set_boot_mode(self, task, mode): """Set the boot mode for a node. Set the boot mode to use on next reboot of the node. :param task: A task from TaskManager. :param mode: The boot mode, one of :mod:`ironic.common.boot_modes`. :raises: InvalidParameterValue on malformed parameter(s) :raises: MissingParameterValue on missing parameter(s) :raises: IBMCConnectionError when it fails to connect to iBMC :raises: IBMCError on an error from the iBMC """ self.validate(task) system = utils.get_system(task.node) boot_device = system.boot.get('target') if not boot_device: error_msg = (_('Cannot change boot mode on node %(node)s ' 'because its boot device is not set.') % { 'node': task.node.uuid }) LOG.error(error_msg) raise exception.IBMCError(error_msg) boot_override = system.boot.get('enabled') if not boot_override: error_msg = (_('Cannot change boot mode on node %(node)s ' 'because its boot source override is not set.') % { 'node': task.node.uuid }) LOG.error(error_msg) raise exception.IBMCError(error_msg) try: system.set_system_boot_source( boot_device, enabled=boot_override, mode=mappings.BOOT_MODE_MAP_REV[mode]) except requests.exceptions.RequestException as e: error_msg = (_('Setting boot mode to %(mode)s ' 'failed for node %(node)s. Error : %(error)s') % { 'node': task.node.uuid, 'mode': mode, 'error': e }) LOG.error(error_msg) raise exception.IBMCError(error=error_msg)
def boot_up_seq(self, task, **kwargs): """List boot type order of the node. :param task: A TaskManager instance containing the node to act on. :param kwargs: Not used. :raises: InvalidParameterValue if kwargs does not contain 'method'. :raises: MissingParameterValue :returns: A dictionary, containing node boot up sequence, in ascending order. """ self.validate(task) system = utils.get_system(task.node) try: boot_seq = system.boot_sequence return {'boot_up_sequence': boot_seq} except requests.exceptions.RequestException as e: error_msg = (_('IBMC get bootup sequence failed ' 'for node %(node)s. Error: %(error)s') % {'node': task.node.uuid, 'error': e}) LOG.error(error_msg) raise exception.IBMCError(error=error_msg)
def inject_nmi(self, task): """Inject NMI, Non Maskable Interrupt. Inject NMI (Non Maskable Interrupt) for a node immediately. :param task: A TaskManager instance containing the node to act on. :raises: InvalidParameterValue on malformed parameter(s) :raises: MissingParameterValue on missing parameter(s) :raises: IBMCConnectionError when it fails to connect to iBMC :raises: IBMCError on an error from the Sushy library """ self.validate(task) system = utils.get_system(task.node) try: system.reset_system(constants.RESET_NMI) except requests.exceptions.RequestException as e: error_msg = (_('IBMC inject NMI failed for node %(node)s. ' 'Error: %(error)s') % { 'node': task.node.uuid, 'error': e }) LOG.error(error_msg) raise exception.IBMCError(error=error_msg)
def test_ensure_new_session_username(self, mock_service): self.node.driver_info['ibmc_username'] = '******' ibmc_utils.get_system(self.node) self.node.driver_info['ibmc_username'] = '******' ibmc_utils.get_system(self.node) self.assertEqual(2, mock_service.call_count)
def test_ensure_new_session_address(self, mock_service): self.node.driver_info['ibmc_address'] = 'http://bmc.foo' ibmc_utils.get_system(self.node) self.node.driver_info['ibmc_address'] = 'http://bmc.bar' ibmc_utils.get_system(self.node) self.assertEqual(2, mock_service.call_count)
def test_ensure_session_reuse(self, mock_service): ibmc_utils.get_system(self.node) ibmc_utils.get_system(self.node) self.assertEqual(1, mock_service.call_count)