diff options
author | Andy Grover <agrover@redhat.com> | 2016-08-12 10:19:14 -0700 |
---|---|---|
committer | Andy Grover <agrover@redhat.com> | 2016-08-12 10:19:14 -0700 |
commit | ba87a191edffe01235f86cfb145aa6834f5f0057 (patch) | |
tree | f702f9429098bf40d4c1b9adf7704990b793f9a5 /rtslib/utils.py | |
parent | 8277306b4d30e93b6985302c25910550d4172fff (diff) | |
download | rtslib-fb-ba87a191edffe01235f86cfb145aa6834f5f0057.tar.gz |
Rework convert_scsi_path_to_hctl and convert_scsi_hctl_to_path
Do not check for type=disk, this is not a requirement.
Raise an RTSLibError if not found, rather than returning None.
Rework PSCSIStorageObject._configure to use the new semantics, and avoid
else clauses in try blocks, since they are confusing and not strictly
needed.
Properly qualify DeviceNotFoundError as pyudev.DeviceNotFoundError.
Signed-off-by: Andy Grover <agrover@redhat.com>
Diffstat (limited to 'rtslib/utils.py')
-rw-r--r-- | rtslib/utils.py | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/rtslib/utils.py b/rtslib/utils.py index c9f8213..969d2d7 100644 --- a/rtslib/utils.py +++ b/rtslib/utils.py @@ -246,26 +246,15 @@ def convert_scsi_path_to_hctl(path): @param path: The udev path to the SCSI block device. @type path: string @return: An (host, controller, target, lun) tuple of integer - values representing the SCSI ID of the device, or None if no - match is found. + values representing the SCSI ID of the device, or raise RTSLibError. ''' try: path = os.path.realpath(path) device = pyudev.Device.from_device_file(_CONTEXT, path) - except (pyudev.DeviceNotFoundError, EnvironmentError, ValueError): - return None - - if device.device_type != u'disk': - return None - - parent = device.find_parent(subsystem='scsi') - if parent is None: - return None - - try: + parent = device.find_parent(subsystem='scsi') return [int(data) for data in parent.sys_name.split(':')] - except (ValueError, TypeError): - return None + except: + raise RTSLibError("Could not convert scsi path to hctl") def convert_scsi_hctl_to_path(host, controller, target, lun): ''' @@ -288,7 +277,7 @@ def convert_scsi_hctl_to_path(host, controller, target, lun): @type target: int @param lun: The SCSI Logical Unit Number. @type lun: int - @return: A string for the canonical path to the device, or empty string. + @return: A string for the canonical path to the device, or raise RTSLibError. ''' try: host = int(host) @@ -302,16 +291,18 @@ def convert_scsi_hctl_to_path(host, controller, target, lun): hctl = [host, controller, target, lun] try: scsi_device = pyudev.Device.from_name(_CONTEXT, 'scsi', ':'.join(hctl)) - except DeviceNotFoundError: - return '' + except pyudev.DeviceNotFoundError: + raise RTSLibError("Could not find path for SCSI hctl") devices = _CONTEXT.list_devices( subsystem='block', - DEVTYPE='disk', parent=scsi_device ) - return next((dev.device_node for dev in devices), '') + path = next((dev.device_node for dev in devices), '') + if path == None: + raise RTSLibError("Could not find path for SCSI hctl") + return path def generate_wwn(wwn_type): ''' |