summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Grover <agrover@redhat.com>2012-10-18 14:12:21 -0700
committerAndy Grover <agrover@redhat.com>2012-10-18 14:12:21 -0700
commit5135ebe092b6a0a0032902a31b984ebb5438990f (patch)
tree9f79f6572cb529bab986267b32e9c966af030c49
parentc55df11a8f87ef18f620312dd81f42b0c3e9b905 (diff)
downloadrtslib-fb-5135ebe092b6a0a0032902a31b984ebb5438990f.tar.gz
Convert exception to RTSLibError if fwrite in _set_enable failsv2.1.fb23
Also, have _get_enable return True/False rather than 1/0 Signed-off-by: Andy Grover <agrover@redhat.com>
-rw-r--r--rtslib/target.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/rtslib/target.py b/rtslib/target.py
index 0e8f556..bf907da 100644
--- a/rtslib/target.py
+++ b/rtslib/target.py
@@ -1075,22 +1075,22 @@ class TPG(CFSNode):
# If the TPG does not have the enable attribute, then it is always
# enabled.
if os.path.isfile(path):
- return int(fread(path))
+ return bool(int(fread(path)))
else:
- return 1
+ return True
def _set_enable(self, boolean):
'''
Enables or disables the TPG. Raises an error if trying to disable a TPG
- without en enable attribute (but enabling works in that case).
+ without an enable attribute (but enabling works in that case).
'''
self._check_self()
path = "%s/enable" % self.path
- if os.path.isfile(path):
- if boolean and not self._get_enable():
- fwrite(path, "1")
- elif not boolean and self._get_enable():
- fwrite(path, "0")
+ if os.path.isfile(path) and (boolean != self._get_enable()):
+ try:
+ fwrite(path, str(int(boolean)))
+ except IOError, e:
+ raise RTSLibError("Cannot change enable state: %s" % e)
elif not boolean:
raise RTSLibError("TPG cannot be disabled.")