diff options
author | Andy Grover <agrover@redhat.com> | 2014-11-13 11:35:16 -0800 |
---|---|---|
committer | Andy Grover <agrover@redhat.com> | 2014-11-13 11:35:16 -0800 |
commit | a0118567c3400bd63dafd8881e3e552ddea381e7 (patch) | |
tree | db596fae591e6a87dd1f93814fb6cd6f7a59b74c | |
parent | 236bef5f486f83d195068508046c05871d7c3112 (diff) | |
download | rtslib-fb-a0118567c3400bd63dafd8881e3e552ddea381e7.tar.gz |
Standardize on no periods in exception messages
Do not terminate our exception messages with a period. This follows how
they are used in the Python stdlib.
Also remove some str() conversions where the "%s" in the format string
should already be doing the conversion.
Signed-off-by: Andy Grover <agrover@redhat.com>
-rw-r--r-- | rtslib/fabric.py | 4 | ||||
-rw-r--r-- | rtslib/node.py | 19 | ||||
-rw-r--r-- | rtslib/target.py | 38 | ||||
-rw-r--r-- | rtslib/tcm.py | 26 | ||||
-rw-r--r-- | rtslib/utils.py | 6 |
5 files changed, 45 insertions, 48 deletions
diff --git a/rtslib/fabric.py b/rtslib/fabric.py index 982588c..cb9b5b9 100644 --- a/rtslib/fabric.py +++ b/rtslib/fabric.py @@ -176,7 +176,7 @@ class _BaseFabricModule(CFSNode): if os.path.isfile(path): return fread(path) else: - raise RTSLibError("Can't find version for fabric module %s." + raise RTSLibError("Can't find version for fabric module %s" % self.name) else: return None @@ -215,7 +215,7 @@ class _BaseFabricModule(CFSNode): def _assert_feature(self, feature): if not self.has_feature(feature): raise RTSLibError("This fabric module does not implement " - + "the %s feature." % feature) + + "the %s feature" % feature) def clear_discovery_auth_settings(self): self._check_self() diff --git a/rtslib/node.py b/rtslib/node.py index 27ca3fb..ed1e10a 100644 --- a/rtslib/node.py +++ b/rtslib/node.py @@ -47,17 +47,17 @@ class CFSNode(object): if mode not in ['any', 'lookup', 'create']: raise RTSLibError("Invalid mode: %s" % mode) if self.exists and mode == 'create': - raise RTSLibError("This %s already exists in configFS." + raise RTSLibError("This %s already exists in configFS" % self.__class__.__name__) elif not self.exists and mode == 'lookup': - raise RTSLibNotInCFS("No such %s in configfs: %s." + raise RTSLibNotInCFS("No such %s in configfs: %s" % (self.__class__.__name__, self.path)) if not self.exists: try: os.mkdir(self.path) except: - raise RTSLibError("Could not create %s in configFS." + raise RTSLibError("Could not create %s in configFS" % self.__class__.__name__) def _exists(self): @@ -65,7 +65,7 @@ class CFSNode(object): def _check_self(self): if not self.exists: - raise RTSLibNotInCFS("This %s does not exist in configFS." + raise RTSLibNotInCFS("This %s does not exist in configFS" % self.__class__.__name__) def _list_files(self, path, writable=None): @@ -134,7 +134,7 @@ class CFSNode(object): self._check_self() path = "%s/attrib/%s" % (self.path, str(attribute)) if not os.path.isfile(path): - raise RTSLibError("Cannot find attribute: %s." + raise RTSLibError("Cannot find attribute: %s" % str(attribute)) else: try: @@ -150,8 +150,7 @@ class CFSNode(object): self._check_self() path = "%s/attrib/%s" % (self.path, str(attribute)) if not os.path.isfile(path): - raise RTSLibError("Cannot find attribute: %s." - % str(attribute)) + raise RTSLibError("Cannot find attribute: %s" % attribute) else: return fread(path) @@ -167,8 +166,7 @@ class CFSNode(object): self._check_self() path = "%s/param/%s" % (self.path, str(parameter)) if not os.path.isfile(path): - raise RTSLibError("Cannot find parameter: %s." - % str(parameter)) + raise RTSLibError("Cannot find parameter: %s" % parameter) else: try: fwrite(path, "%s\n" % str(value)) @@ -184,8 +182,7 @@ class CFSNode(object): self._check_self() path = "%s/param/%s" % (self.path, str(parameter)) if not os.path.isfile(path): - raise RTSLibError("Cannot find RFC-3720 parameter: %s." - % str(parameter)) + raise RTSLibError("Cannot find RFC-3720 parameter: %s" % parameter) else: return fread(path) diff --git a/rtslib/target.py b/rtslib/target.py index fadbc36..de90a62 100644 --- a/rtslib/target.py +++ b/rtslib/target.py @@ -175,17 +175,17 @@ class TPG(CFSNode): tag = index break if tag is None: - raise RTSLibError("Cannot find an available TPG Tag.") + raise RTSLibError("Cannot find an available TPG Tag") else: tag = int(tag) if not tag > 0: - raise RTSLibError("The TPG Tag must be >0.") + raise RTSLibError("The TPG Tag must be >0") self._tag = tag if isinstance(parent_target, Target): self._parent_target = parent_target else: - raise RTSLibError("Invalid parent Target.") + raise RTSLibError("Invalid parent Target") self._path = "%s/tpgt_%d" % (self.parent_target.path, self.tag) @@ -195,7 +195,7 @@ class TPG(CFSNode): if filename.startswith("tpgt_") \ and os.path.isdir("%s/%s" % (target_path, filename)) \ and filename != "tpgt_%d" % self.tag: - raise RTSLibError("Target cannot have multiple TPGs.") + raise RTSLibError("Target cannot have multiple TPGs") self._create_in_cfs_ine(mode) if self.has_feature('nexus') and not self._get_nexus(): @@ -263,9 +263,9 @@ class TPG(CFSNode): self._check_self() if not self.has_feature('nexus'): - raise RTSLibError("The TPG does not use a nexus.") + raise RTSLibError("The TPG does not use a nexus") if self._get_nexus(): - raise RTSLibError("The TPG's nexus initiator WWN is already set.") + raise RTSLibError("The TPG's nexus initiator WWN is already set") fm = self.parent_target.fabric_module @@ -480,7 +480,7 @@ class LUN(CFSNode): if isinstance(parent_tpg, TPG): self._parent_tpg = parent_tpg else: - raise RTSLibError("Invalid parent TPG.") + raise RTSLibError("Invalid parent TPG") if lun is None: luns = [l.lun for l in self.parent_tpg.luns] @@ -501,7 +501,7 @@ class LUN(CFSNode): if storage_object is None and alias is not None: raise RTSLibError("The alias parameter has no meaning " \ - + "without the storage_object parameter.") + + "without the storage_object parameter") if storage_object is not None: self._create_in_cfs_ine('create') @@ -527,7 +527,7 @@ class LUN(CFSNode): if storage_object.exists: source = storage_object.path else: - raise RTSLibError("storage_object does not exist in configFS.") + raise RTSLibError("storage_object does not exist in configFS") os.symlink(source, destination) @@ -680,12 +680,12 @@ class NetworkPortal(CFSNode): try: self._port = int(port) except ValueError: - raise RTSLibError("Invalid port.") + raise RTSLibError("Invalid port") if isinstance(parent_tpg, TPG): self._parent_tpg = parent_tpg else: - raise RTSLibError("Invalid parent TPG.") + raise RTSLibError("Invalid parent TPG") self._path = "%s/np/%s:%d" \ % (self.parent_tpg.path, self.ip_address, self.port) @@ -693,7 +693,7 @@ class NetworkPortal(CFSNode): try: self._create_in_cfs_ine(mode) except OSError as msg: - raise RTSLibError(msg[1]) + raise RTSLibError(msg) def _get_ip_address(self): return self._ip_address @@ -791,7 +791,7 @@ class NodeACL(CFSNode): if isinstance(parent_tpg, TPG): self._parent_tpg = parent_tpg else: - raise RTSLibError("Invalid parent TPG.") + raise RTSLibError("Invalid parent TPG") fm = self.parent_tpg.parent_target.fabric_module self._node_wwn, self.wwn_type = normalize_wwn(fm.wwn_types, node_wwn) @@ -1015,23 +1015,23 @@ class MappedLUN(CFSNode): if not isinstance(parent_nodeacl, NodeACL): raise RTSLibError("The parent_nodeacl parameter must be " \ - + "a NodeACL object.") + + "a NodeACL object") else: self._parent_nodeacl = parent_nodeacl if not parent_nodeacl.exists: - raise RTSLibError("The parent_nodeacl does not exist.") + raise RTSLibError("The parent_nodeacl does not exist") try: self._mapped_lun = int(mapped_lun) except ValueError: raise RTSLibError("The mapped_lun parameter must be an " \ - + "integer value.") + + "integer value") self._path = "%s/lun_%d" % (self.parent_nodeacl.path, self.mapped_lun) if tpg_lun is None and write_protect is not None: raise RTSLibError("The write_protect parameter has no " \ - + "meaning without the tpg_lun parameter.") + + "meaning without the tpg_lun parameter") if tpg_lun is not None: self._create_in_cfs_ine('create') @@ -1052,14 +1052,14 @@ class MappedLUN(CFSNode): tpg_lun = int(tpg_lun) except ValueError: raise RTSLibError("The tpg_lun must be either an " - + "integer or a LUN object.") + + "integer or a LUN object") # Check that the tpg_lun exists in the TPG for lun in self.parent_nodeacl.parent_tpg.luns: if lun.lun == tpg_lun: tpg_lun = lun break if not (isinstance(tpg_lun, LUN) and tpg_lun): - raise RTSLibError("LUN %s does not exist in this TPG." + raise RTSLibError("LUN %s does not exist in this TPG" % str(tpg_lun)) os.symlink(tpg_lun.path, "%s/%s" % (self.path, str(uuid.uuid4())[-10:])) diff --git a/rtslib/tcm.py b/rtslib/tcm.py index 0861ae6..70b0a7f 100644 --- a/rtslib/tcm.py +++ b/rtslib/tcm.py @@ -44,7 +44,7 @@ class StorageObject(CFSNode): super(StorageObject, self).__init__() if "/" in name or " " in name or "\t" in name or "\n" in name: raise RTSLibError("A storage object's name cannot contain " - " /, newline or spaces/tabs.") + " /, newline or spaces/tabs") else: self._name = name self._backstore = _Backstore(name, type(self), mode) @@ -119,7 +119,7 @@ class StorageObject(CFSNode): return fread(path).partition(":")[2].strip() else: raise RTSLibError("Cannot read a T10 WWN Unit Serial from " - + "an unconfigured StorageObject.") + + "an unconfigured StorageObject") def _set_wwn(self, wwn): self._check_self() @@ -128,7 +128,7 @@ class StorageObject(CFSNode): fwrite(path, "%s\n" % wwn) else: raise RTSLibError("Cannot write a T10 WWN Unit Serial to " - + "an unconfigured StorageObject.") + + "an unconfigured StorageObject") def _set_udev_path(self, udev_path): self._check_self() @@ -326,14 +326,14 @@ class PSCSIStorageObject(StorageObject): raise RTSLibError("Cannot find SCSI device by " + "path, and dev " + "parameter not in H:C:T:L " - + "format: %s." % dev) + + "format: %s" % dev) else: udev_path = convert_scsi_hctl_to_path(hostid, channelid, targetid, lunid) if not udev_path: - raise RTSLibError("SCSI device does not exist.") + raise RTSLibError("SCSI device does not exist") else: udev_path = dev.strip() @@ -342,7 +342,7 @@ class PSCSIStorageObject(StorageObject): + "device %s (SCSI %d:%d:%d:%d) " % (udev_path, hostid, channelid, targetid, lunid) - + "is already in use.") + + "is already in use") self._control("scsi_host_id=%d," % hostid \ + "scsi_channel_id=%d," % channelid \ @@ -567,10 +567,10 @@ class FileIOStorageObject(StorageObject): block_type = get_blockdev_type(dev) if block_type is None: # a file if os.path.exists(os.path.realpath(dev)) and not os.path.isfile(dev): - raise RTSLibError("Path not to a file or block device.") + raise RTSLibError("Path not to a file or block device") if size is None: - raise RTSLibError("Path is to a file, size needed.") + raise RTSLibError("Path is to a file, size needed") self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size)) @@ -579,10 +579,10 @@ class FileIOStorageObject(StorageObject): # dump() saves it and thus restore() will call us with it. if block_type != 0: - raise RTSLibError("Device is not a TYPE_DISK block device.") + raise RTSLibError("Device is not a TYPE_DISK block device") if is_dev_in_use(dev): - raise RTSLibError("Device %s is already in use." % dev) + raise RTSLibError("Device %s is already in use" % dev) self._control("fd_dev_name=%s" % dev) @@ -676,10 +676,10 @@ class BlockStorageObject(StorageObject): def _configure(self, dev, wwn, readonly): self._check_self() if get_blockdev_type(dev) != 0: - raise RTSLibError("Device is not a TYPE_DISK block device.") + raise RTSLibError("Device is not a TYPE_DISK block device") if is_dev_in_use(dev): raise RTSLibError("Cannot configure StorageObject because " - + "device %s is already in use." % dev) + + "device %s is already in use" % dev) self._set_udev_path(dev) self._control("udev_path=%s" % dev) self._control("readonly=%d" % readonly) @@ -761,7 +761,7 @@ class UserBackedStorageObject(StorageObject): if size is not None: if level is None or config is None: raise RTSLibError("'size', 'level', and 'config' must be set when " - "creating a new UserBackedStorageObject.") + "creating a new UserBackedStorageObject") if '/' not in config: raise RTSLibError("'config' must contain a '/' separating subtype " "from its configuration string") diff --git a/rtslib/utils.py b/rtslib/utils.py index b2e74a8..713881e 100644 --- a/rtslib/utils.py +++ b/rtslib/utils.py @@ -245,7 +245,7 @@ def convert_scsi_hctl_to_path(host, controller, target, lun): lun = int(lun) except ValueError: raise RTSLibError( - "The host, controller, target and lun parameter must be integers.") + "The host, controller, target and lun parameter must be integers") for devname in os.listdir("/sys/block"): path = "/dev/%s" % devname @@ -285,7 +285,7 @@ def generate_wwn(wwn_type): elif wwn_type == 'eui': return "eui.001405" + uuid.uuid4().hex[-10:] else: - raise ValueError("Unknown WWN type: %s." % wwn_type) + raise ValueError("Unknown WWN type: %s" % wwn_type) def colonize(str): ''' @@ -378,7 +378,7 @@ def mount_configfs(): stderr=subprocess.PIPE) (stdoutdata, stderrdata) = process.communicate() if process.returncode != 0: - raise RTSLibError("Cannot mount configfs.") + raise RTSLibError("Cannot mount configfs") def dict_remove(d, items): for item in items: |