Coverage for sm/core/scsiutil : 22%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Fake scsiutil module"""
else:
except: pass
vendor_command = ['sginfo', '-M', device_path] (rc, stdout, _) = util.doexec(vendor_command) if rc != 0: raise f_exceptions.XenError( 'SCSIRead', 'sginfo failed {}, {}'.format(device_path, rc))
match = re.search(r'(^|.*\n)Vendor:\s+(.*)[$|\n]', stdout) if not match: raise f_exceptions.XenError( 'SCSIRead', 'sginfo no vendor match {}'.format(device_path)) return match.group(2).strip()
serial_command = ['sginfo', '-s', device_path] (rc, stdout, _) = util.doexec(serial_command) if rc != 0: raise f_exceptions.XenError( 'SCSIRead', 'sginfo failed {}, {}'.format(device_path, rc))
match = re.search(r'(^|.*\n)Serial Number\s+\'([^\']*)\'[$|\n]', stdout) if not match: raise f_exceptions.XenError( 'SCSIRead', 'sginfo no serial match {}'.format(device_path)) return match.group(2).strip()
devices = os.listdir(os.path.join('/dev/disk/by-scsid', SCSIid)) if 'mapper' in devices: devices.remove('mapper') return devices
device = os.path.join('/dev', getdev(device)) readcapcommand = ['/usr/bin/sg_readcap', '-b', device] (rc,stdout,stderr) = util.doexec(readcapcommand) if rc == 6: # retry one time for "Capacity data has changed" (rc,stdout,stderr) = util.doexec(readcapcommand) if rc != 0: raise f_exceptions.XenError("SCSIRead", "scsiutil.sg_readcap(%s) failed" % (device)) match = re.search('(^|.*\n)(0x[0-9a-fA-F]+) (0x[0-9a-fA-F]+)\n$', stdout) if not match: raise f_exceptions.XenError("SCSIRead", "scsiutil.sg_readcap(%s) failed to parse: %s" % (device, stdout)) (blockcount, blocksize) = match.group(2, 3) return (int(blockcount, 0) * int(blocksize, 0))
""" Refresh block devices given a path list """ for path in pathlist: dev = getdev(path) util.SMlog("Refreshing size for device %s (%s)" % (path, dev)) sysfs = os.path.join('/sys/block',dev,'device/rescan') if os.path.exists(sysfs): try: f = os.open(sysfs, os.O_WRONLY) os.write(f,'1') os.close(f) except: pass
""" Refresh all devices for the SCSIid. Returns True if all known devices and the mapper device are up to date. """ def get_primary_device(SCSIid): mapperdevice = os.path.join('/dev/mapper', SCSIid) if os.path.exists(mapperdevice): return mapperdevice else: devices = get_devices_by_SCSIid(SCSIid) if devices: return devices[0] else: return None
def get_outdated_size_devices(currentcapacity, devices): devicesthatneedrefresh = [] for device in devices: if getsize(device) != currentcapacity: devicesthatneedrefresh.append(device) return devicesthatneedrefresh
def refresh_devices_if_needed(primarydevice, SCSIid, currentcapacity): devices = get_devices_by_SCSIid(SCSIid) if "/dev/mapper/" in primarydevice: devices = set(devices + mpath_cli.list_paths(SCSIid)) devicesthatneedrefresh = get_outdated_size_devices(currentcapacity, devices) if devicesthatneedrefresh: # timing out avoids waiting for min(dev_loss_tmo, fast_io_fail_tmo) # if one or multiple devices don't answer util.timeout_call(10, refreshdev, devicesthatneedrefresh) if get_outdated_size_devices(currentcapacity, devicesthatneedrefresh): # in this state we shouldn't force resizing the mapper dev raise f_exceptions.XenError("DeviceResize", "Failed to get %s to agree on the " "current capacity." % devicesthatneedrefresh)
def refresh_mapper_if_needed(primarydevice, SCSIid, currentcapacity): if ("/dev/mapper/" in primarydevice and get_outdated_size_devices(currentcapacity, [primarydevice])): util.SMlog("Resizing multpath map for device %s" % SCSIid) mpath_cli.resize_map(SCSIid) if get_outdated_size_devices(currentcapacity, [primarydevice]): raise f_exceptions.XenError("DeviceResize", "Failed to get the mapper dev to " "agree on the current capacity.")
try: primarydevice = get_primary_device(SCSIid) if primarydevice: currentcapacity = sg_readcap(primarydevice) refresh_devices_if_needed(primarydevice, SCSIid, currentcapacity) refresh_mapper_if_needed(primarydevice, SCSIid, currentcapacity) else: util.SMlog("scsiutil.refresh_lun_size_by_SCSIid(%s) could not " "find any devices for the SCSIid." % SCSIid) return True except: util.SMlog("Error in scsiutil.refresh_lun_size_by_SCSIid(%s)" % SCSIid) return False |