summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Grover <agrover@redhat.com>2014-04-15 11:57:15 -0700
committerAndy Grover <agrover@redhat.com>2014-04-15 11:57:15 -0700
commit9e336d2137be30a1f5ec05bf0f78b86a5bf2ae6b (patch)
treeb177486a683b907225c56aa20c43b870454e2930
parente07dc0d9714699335ba9c356adae21b9aca2fb38 (diff)
downloadrtslib-fb-9e336d2137be30a1f5ec05bf0f78b86a5bf2ae6b.tar.gz
Change set_parameters/attributes to take an err_func
We don't want to silently hide errors when setting things, but we also don't want to stop. Since these are both called from setup() functions, we can just pass an err_func to them and they can call it if there's a problem, but keep going. When calling set_attribute for the storageobject, use a custom err_func that also includes the name and plugin in the message. Signed-off-by: Andy Grover <agrover@redhat.com>
-rw-r--r--rtslib/root.py10
-rw-r--r--rtslib/target.py4
-rw-r--r--rtslib/utils.py14
3 files changed, 16 insertions, 12 deletions
diff --git a/rtslib/root.py b/rtslib/root.py
index df2d41c..391c35d 100644
--- a/rtslib/root.py
+++ b/rtslib/root.py
@@ -197,10 +197,12 @@ class RTSRoot(CFSNode):
except (TypeError, ValueError):
err_func("Could not create StorageObject %s" % so['name'])
continue
- try:
- set_attributes(so_obj, so.get('attributes', {}))
- except RTSLibError as e:
- err_func("Could not set an attribute for %s: %s" % (so['name'], e))
+
+ # Custom err func to include block name
+ def so_err_func(x):
+ return err_func("Storage Object %s/%s: %s" % (so['plugin'], so['name'], x))
+
+ set_attributes(so_obj, so.get('attributes', {}), so_err_func)
# Don't need to create fabric modules
for index, fm in enumerate(config.get('fabric_modules', [])):
diff --git a/rtslib/target.py b/rtslib/target.py
index 73f82fc..c9ccc8e 100644
--- a/rtslib/target.py
+++ b/rtslib/target.py
@@ -400,8 +400,8 @@ class TPG(CFSNode):
@classmethod
def setup(cls, t_obj, tpg, err_func):
tpg_obj = cls(t_obj, tag=tpg.get("tag", None))
- set_attributes(tpg_obj, tpg.get('attributes', {}))
- set_parameters(tpg_obj, tpg.get('parameters', {}))
+ set_attributes(tpg_obj, tpg.get('attributes', {}), err_func)
+ set_parameters(tpg_obj, tpg.get('parameters', {}), err_func)
for lun in tpg.get('luns', []):
LUN.setup(tpg_obj, lun, err_func)
diff --git a/rtslib/utils.py b/rtslib/utils.py
index ca0e7bc..baae9e3 100644
--- a/rtslib/utils.py
+++ b/rtslib/utils.py
@@ -433,17 +433,19 @@ def _set_auth_attr(self, value, attribute, ignore=False):
if not ignore:
raise
-def set_attributes(obj, attr_dict):
+def set_attributes(obj, attr_dict, err_func):
for name, value in attr_dict.iteritems():
- # Setting some attributes may return an error, before kernel 3.3
- with ignored(RTSLibError):
+ try:
obj.set_attribute(name, value)
+ except RTSLibError as e:
+ err_func(str(e))
-def set_parameters(obj, param_dict):
+def set_parameters(obj, param_dict, err_func):
for name, value in param_dict.iteritems():
- # Setting some parameters may return an error, before kernel 3.3
- with ignored(RTSLibError):
+ try:
obj.set_parameter(name, value)
+ except RTSLibError as e:
+ err_func(str(e))
def _test():
'''Run the doctests'''