def test_get_paths_status(fake_dmsetup): res = devicemapper.getPathsStatus() expected = { "67:16": "failed", "65:240": "active", "66:64": "active", "65:224": "active", "65:160": "active", "66:176": "failed", } assert res == expected
def test_get_paths_status(fake_dmsetup): fake_dmsetup.write(DMSETUP_SCRIPT.format(FAKE_DMSETUP_OUTPUT)) res = devicemapper.getPathsStatus() expected = { "67:16": "failed", "65:240": "active", "66:64": "active", "65:224": "active", "65:160": "active", "66:176": "failed", } assert res == expected
def test_get_paths_status(monkeypatch, fake_dmsetup_status): monkeypatch.setattr(devicemapper, "device_name", lambda major_minor: major_minor) dmsetup.status.lines = FAKE_DMSETUP_STATUS res = devicemapper.getPathsStatus() expected = { "67:16": "failed", "65:240": "active", "66:64": "active", "65:224": "active", "65:160": "active", "66:176": "failed", } assert res == expected
def pathListIter(filterGuids=()): filterLen = len(filterGuids) if filterGuids else -1 devsFound = 0 knownSessions = {} svdsm = supervdsm.getProxy() pathStatuses = devicemapper.getPathsStatus() for dmId, guid in getMPDevsIter(): if devsFound == filterLen: break if filterGuids and guid not in filterGuids: continue devsFound += 1 devInfo = { "guid": guid, "dm": dmId, "capacity": str(getDeviceSize(dmId)), "serial": svdsm.getScsiSerial(dmId), "paths": [], "connections": [], "devtypes": [], "devtype": "", "vendor": "", "product": "", "fwrev": "", "logicalblocksize": "", "physicalblocksize": "", "discard_max_bytes": getDeviceDiscardMaxBytes(dmId), "discard_zeroes_data": getDeviceDiscardZeroesData(dmId), } for slave in devicemapper.getSlaves(dmId): if not devicemapper.isBlockDevice(slave): log.warning("No such physdev '%s' is ignored" % slave) continue if not devInfo["vendor"]: try: devInfo["vendor"] = getVendor(slave) except Exception: log.warn("Problem getting vendor from device `%s`", slave, exc_info=True) if not devInfo["product"]: try: devInfo["product"] = getModel(slave) except Exception: log.warn("Problem getting model name from device `%s`", slave, exc_info=True) if not devInfo["fwrev"]: try: devInfo["fwrev"] = getFwRev(slave) except Exception: log.warn("Problem getting fwrev from device `%s`", slave, exc_info=True) if (not devInfo["logicalblocksize"] or not devInfo["physicalblocksize"]): try: logBlkSize, phyBlkSize = getDeviceBlockSizes(slave) devInfo["logicalblocksize"] = str(logBlkSize) devInfo["physicalblocksize"] = str(phyBlkSize) except Exception: log.warn("Problem getting blocksize from device `%s`", slave, exc_info=True) pathInfo = {} pathInfo["physdev"] = slave pathInfo["state"] = pathStatuses.get(slave, "failed") pathInfo["capacity"] = str(getDeviceSize(slave)) try: hbtl = getHBTL(slave) except OSError as e: if e.errno == errno.ENOENT: log.warn("Device has no hbtl: %s", slave) pathInfo["lun"] = 0 else: log.error("Error: %s while trying to get hbtl of device: " "%s", str(e.message), slave) raise else: pathInfo["lun"] = hbtl.lun if iscsi.devIsiSCSI(slave): devInfo["devtypes"].append(DEV_ISCSI) pathInfo["type"] = DEV_ISCSI sessionID = iscsi.getiScsiSession(slave) if sessionID not in knownSessions: # FIXME: This entire part is for BC. It should be moved to # hsm and not preserved for new APIs. New APIs should keep # numeric types and sane field names. sess = iscsi.getSessionInfo(sessionID) sessionInfo = { "connection": sess.target.portal.hostname, "port": str(sess.target.portal.port), "iqn": sess.target.iqn, "portal": str(sess.target.tpgt), "initiatorname": sess.iface.name } # Note that credentials must be sent back in order for # the engine to tell vdsm how to reconnect later if sess.credentials: cred = sess.credentials sessionInfo['user'] = cred.username sessionInfo['password'] = cred.password knownSessions[sessionID] = sessionInfo devInfo["connections"].append(knownSessions[sessionID]) else: devInfo["devtypes"].append(DEV_FCP) pathInfo["type"] = DEV_FCP if devInfo["devtype"] == "": devInfo["devtype"] = pathInfo["type"] elif (devInfo["devtype"] != DEV_MIXED and devInfo["devtype"] != pathInfo["type"]): devInfo["devtype"] == DEV_MIXED devInfo["paths"].append(pathInfo) yield devInfo
def devicemapper_getPathsStatus(): return devicemapper.getPathsStatus()
def pathListIter(filterGuids=()): filterLen = len(filterGuids) if filterGuids else -1 devsFound = 0 knownSessions = {} svdsm = supervdsm.getProxy() pathStatuses = devicemapper.getPathsStatus() for dmId, guid in getMPDevsIter(): if devsFound == filterLen: break if filterGuids and guid not in filterGuids: continue devsFound += 1 devInfo = { "guid": guid, "dm": dmId, "capacity": str(getDeviceSize(dmId)), "serial": svdsm.getScsiSerial(dmId), "paths": [], "connections": [], "devtypes": [], "devtype": "", "vendor": "", "product": "", "fwrev": "", "logicalblocksize": "", "physicalblocksize": "", } for slave in devicemapper.getSlaves(dmId): if not devicemapper.isBlockDevice(slave): log.warning("No such physdev '%s' is ignored" % slave) continue if not devInfo["vendor"]: try: devInfo["vendor"] = getVendor(slave) except Exception: log.warn("Problem getting vendor from device `%s`", slave, exc_info=True) if not devInfo["product"]: try: devInfo["product"] = getModel(slave) except Exception: log.warn("Problem getting model name from device `%s`", slave, exc_info=True) if not devInfo["fwrev"]: try: devInfo["fwrev"] = getFwRev(slave) except Exception: log.warn("Problem getting fwrev from device `%s`", slave, exc_info=True) if (not devInfo["logicalblocksize"] or not devInfo["physicalblocksize"]): try: logBlkSize, phyBlkSize = getDeviceBlockSizes(slave) devInfo["logicalblocksize"] = str(logBlkSize) devInfo["physicalblocksize"] = str(phyBlkSize) except Exception: log.warn("Problem getting blocksize from device `%s`", slave, exc_info=True) pathInfo = {} pathInfo["physdev"] = slave pathInfo["state"] = pathStatuses.get(slave, "failed") pathInfo["capacity"] = str(getDeviceSize(slave)) try: hbtl = getHBTL(slave) except OSError as e: if e.errno == errno.ENOENT: log.warn("Device has no hbtl: %s", slave) pathInfo["lun"] = 0 else: log.error("Error: %s while trying to get hbtl of device: " "%s", str(e.message), slave) raise else: pathInfo["lun"] = hbtl.lun if iscsi.devIsiSCSI(slave): devInfo["devtypes"].append(DEV_ISCSI) pathInfo["type"] = DEV_ISCSI sessionID = iscsi.getiScsiSession(slave) if sessionID not in knownSessions: # FIXME: This entire part is for BC. It should be moved to # hsm and not preserved for new APIs. New APIs should keep # numeric types and sane field names. sess = iscsi.getSessionInfo(sessionID) sessionInfo = { "connection": sess.target.portal.hostname, "port": str(sess.target.portal.port), "iqn": sess.target.iqn, "portal": str(sess.target.tpgt), "initiatorname": sess.iface.name } # Note that credentials must be sent back in order for # the engine to tell vdsm how to reconnect later if sess.credentials: cred = sess.credentials sessionInfo['user'] = cred.username sessionInfo['password'] = cred.password knownSessions[sessionID] = sessionInfo devInfo["connections"].append(knownSessions[sessionID]) else: devInfo["devtypes"].append(DEV_FCP) pathInfo["type"] = DEV_FCP if devInfo["devtype"] == "": devInfo["devtype"] = pathInfo["type"] elif (devInfo["devtype"] != DEV_MIXED and devInfo["devtype"] != pathInfo["type"]): devInfo["devtype"] == DEV_MIXED devInfo["paths"].append(pathInfo) yield devInfo
def test_get_paths_status_no_mutltipath(monkeypatch): monkeypatch.setattr(devicemapper, "run_dmsetup_status", lambda: NO_MULTIPATH_DEVICE) assert devicemapper.getPathsStatus() == {}
def test_get_paths_status_no_device(monkeypatch): monkeypatch.setattr(devicemapper, "run_dmsetup_status", lambda: NO_DEVICE_MAPPER_DEVICES) assert devicemapper.getPathsStatus() == {}
def test_get_paths_status_no_device(fake_dmsetup_status): assert devicemapper.getPathsStatus() == {}