async def get_device_info(rack, board, device): """Get the device information for a device. Args: rack (str): The rack which the device resides on. board (str): The board which the device resides on. device (str): The ID of the device to get meta-info for. Returns: tuple(str, Device): A tuple where the first item is the name of the plugin that the device is associated with and the second item is the device information for that device. Raises: errors.DeviceNotFoundError: The given rack-board-device combination does not correspond to a known device. """ cid = utils.composite(rack, board, device) # This also builds the plugins cache _cache = await get_device_info_cache() dev = _cache.get(cid) if dev is None: raise errors.DeviceNotFoundError( _('{} does not correspond with a known device').format('/'.join( [rack, board, device]))) # If the device exists, it will have come from a plugin, so we should # always have the plugin name here. pcache = await _plugins_cache.get(PLUGINS_CACHE_KEY) return pcache.get(cid), dev
def test_synse_error_device_not_found(): """Check for DEVICE_NOT_FOUND error""" e = errors.DeviceNotFoundError('message') assert isinstance(e, exceptions.NotFound) assert isinstance(e, errors.SynseError) assert isinstance(e, errors.SynseNotFoundError) assert e.status_code == 404 assert e.error_id == errors.DEVICE_NOT_FOUND assert e.args[0] == 'message'
def get_resources(info_cache, rack=None, board=None, device=None): """Get the entries for the specified resources out of the resource info cache. If a given resource (rack, board, device) is provided as None, it will not be looked up and that resource will have None as its return value. If any of the specified resources can not be found in the cache, an error is raised. Args: info_cache (dict): The resource info cache. rack (str): The identifier for the rack to get info for. board (str): The identifier for the board to get info for. device (str): The identifier for the device to get info for. Returns: tuple: A 3-tuple with the corresponding rack, board, and device entry. Raises: errors.SynseError: Any of the specified resources were not found in the resource info cache. """ r, b, d = None, None, None if rack is not None: r = info_cache.get(rack) logger.debug(_('Rack info from cache: {}').format(r)) if not r: raise errors.RackNotFoundError( _('Unable to find rack "{}" in info cache').format(rack)) if board is not None: b = r['boards'].get(board) logger.debug(_('Board info from cache: {}').format(b)) if not b: raise errors.BoardNotFoundError( _('Unable to find board "{}" in info cache').format(board)) if device is not None: d = b['devices'].get(device) logger.debug(_('Device info from cache: {}').format(d)) if not d: raise errors.DeviceNotFoundError( _('Unable to find device "{}" in info cache').format(device)) return r, b, d
def _mock_device(*args, **kwargs): raise errors.DeviceNotFoundError('')