diff options
author | Nishanth Thomas <nthomas@redhat.com> | 2014-11-07 00:54:13 +0530 |
---|---|---|
committer | Sahina Bose <sabose@redhat.com> | 2014-11-17 21:39:56 -0800 |
commit | abb72c79f7f2906195c0b7e33d3ad198dd372aec (patch) | |
tree | bc10679f1a6ce46c28b3a90a51d817c981386e49 | |
parent | 40a0f0670b126897f5a98445ed51669b9dc88ec6 (diff) |
gluster-nagios-addons:discover_volumes to return proper error in case of exception
discoverVolumes was not returning the error message in case of exception
while retrieving the data from the backend. Due this the calling funtions
always expect a list and causing inconsistent results
https://bugzilla.redhat.com/show_bug.cgi?id=1136205
https://bugzilla.redhat.com/show_bug.cgi?id=1109843
Signed-off-by: Nishanth Thomas <nthomas@redhat.com>
Change-Id: I518a5f94fd5d414028970379e268e0aa8a408285
Reviewed-on: http://review.gluster.org/9065
Reviewed-by: Shubhendu Tripathi <shtripat@redhat.com>
Tested-by: Nishanth Thomas <nishusemail@gmail.com>
Reviewed-by: Sahina Bose <sabose@redhat.com>
-rwxr-xr-x | plugins/discover_volumes.py | 16 | ||||
-rw-r--r-- | tests/test_discover_volumes.py | 6 |
2 files changed, 16 insertions, 6 deletions
diff --git a/plugins/discover_volumes.py b/plugins/discover_volumes.py index 53d17a8..c175247 100755 --- a/plugins/discover_volumes.py +++ b/plugins/discover_volumes.py @@ -50,7 +50,15 @@ def discoverVolumes(volumeName, list): } """ resultlist = {} - volumes = glustercli.volumeInfo(volumeName) + try: + volumes = glustercli.volumeInfo(volumeName) + except glustercli.GlusterLockedException as e: + resultString = ("UNKNOWN: temporary error. %s" % '.'.join(e.err)) + return utils.PluginStatusCode.UNKNOWN, resultString + except glustercli.GlusterCmdFailedException as e: + resultString = ("UNKNOWN: Failed to get the volume Information. " + "%s" % '.'.join(e.err)) + return utils.PluginStatusCode.UNKNOWN, resultString for key, volume in volumes.iteritems(): volDict = {} volDict['name'] = key @@ -74,7 +82,7 @@ def discoverVolumes(volumeName, list): 'hostUuid': brick['hostUuid']}) resultlist[key] = volDict resultString = json.dumps(resultlist) - return resultString + return utils.PluginStatusCode.OK, resultString def get_arg_parser(): @@ -89,6 +97,6 @@ def get_arg_parser(): if __name__ == '__main__': args = get_arg_parser().parse_args() - resultString = discoverVolumes(args.volume, args.list) + status, resultString = discoverVolumes(args.volume, args.list) print resultString - sys.exit(utils.PluginStatusCode.OK) + sys.exit(status) diff --git a/tests/test_discover_volumes.py b/tests/test_discover_volumes.py index 626f2e3..e5d15b7 100644 --- a/tests/test_discover_volumes.py +++ b/tests/test_discover_volumes.py @@ -77,12 +77,14 @@ class TestDiscoverVolumes(TestCaseBase): def testDiscoverVolumesList(self): discover_volumes.glustercli.volumeInfo = self._mockGetVolumeInfo - volumesList = json.loads(discover_volumes.discoverVolumes(None, True)) + status, output = discover_volumes.discoverVolumes(None, True) + volumesList = json.loads(output) self._verifyVolumeList(volumesList) def testDiscoverVolumesInfo(self): discover_volumes.glustercli.volumeInfo = self._mockGetVolumeInfo - volumesList = json.loads(discover_volumes.discoverVolumes("V1", False)) + status, output = discover_volumes.discoverVolumes("V1", False) + volumesList = json.loads(output) self._verifyVolumeInfo(volumesList, "V1") def testAruguments(self): |