From f6934b13b3706c810bdff311b15a2d33ad22a29a Mon Sep 17 00:00:00 2001 From: Sahina Bose Date: Fri, 8 Aug 2014 18:34:50 +0530 Subject: nagios-commons: Added a new exception class Added different exception in case of transaction lock errors, so that the plugins can return correct state based on the exception messages Change-Id: Ibbe5dd17b4829765505451f5a6554d2ade4b2980 Bug-Url:https://bugzilla.redhat.com/show_bug.cgi?id=1109752 Signed-off-by: Sahina Bose Reviewed-on: http://review.gluster.org/8442 Reviewed-by: Bala FA --- glusternagios/glustercli.py | 48 +++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'glusternagios/glustercli.py') diff --git a/glusternagios/glustercli.py b/glusternagios/glustercli.py index 18caa79..111c9a9 100755 --- a/glusternagios/glustercli.py +++ b/glusternagios/glustercli.py @@ -26,6 +26,7 @@ from hostname import getHostNameFqdn, HostNameException glusterCmdPath = CommandPath("gluster", "/usr/sbin/gluster") +_TRANS_IN_PROGRESS = "another transaction is in progress" # Class for exception definition @@ -53,6 +54,10 @@ class GlusterCmdFailedException(Exception): return s +class GlusterLockedException(GlusterCmdFailedException): + pass + + if hasattr(etree, 'ParseError'): _etreeExceptions = (etree.ParseError, AttributeError, ValueError) else: @@ -148,14 +153,27 @@ def _getLocalIpAddress(): def _execGluster(cmd): - return utils.execCmd(cmd) + rc, out, err = utils.execCmd(cmd) + if rc != 0: + if ((err is not None and + any(_TRANS_IN_PROGRESS in e.lower() for e in err)) or + (out is not None and + any("connection failed" in o.lower() for o in out))): + raise GlusterLockedException(rc, out, err) + return rc, out, err def _execGlusterXml(cmd): cmd.append('--xml') rc, out, err = utils.execCmd(cmd) if rc != 0: - raise GlusterCmdFailedException(rc, out, err) + if ((err is not None and + any(_TRANS_IN_PROGRESS in e.lower() for e in err)) or + (out is not None and + any("connection failed" in o.lower() for o in out))): + raise GlusterLockedException(rc, out, err) + else: + raise GlusterCmdFailedException(rc, out, err) try: tree = etree.fromstring('\n'.join(out)) rv = int(tree.find('opRet').text) @@ -174,6 +192,7 @@ def _execGlusterXml(cmd): def hostUUIDGet(): command = _getGlusterSystemCmd() + ["uuid", "get"] rc, out, err = _execGluster(command) + if rc == 0: for line in out: if line.startswith('UUID: '): @@ -355,10 +374,8 @@ def volumeStatus(volumeName, brick=None, option=None): command.append(brick) if option: command.append(option) - try: - xmltree = _execGlusterXml(command) - except GlusterCmdFailedException as e: - raise GlusterCmdFailedException(rc=e.rc, err=e.err) + xmltree = _execGlusterXml(command) + try: if option == 'detail': return _parseVolumeStatusDetail(xmltree) @@ -443,10 +460,8 @@ def volumeInfo(volumeName=None, remoteServer=None): command += ['--remote-host=%s' % remoteServer] if volumeName: command.append(volumeName) - try: - xmltree = _execGlusterXml(command) - except GlusterCmdFailedException as e: - raise GlusterCmdFailedException(rc=e.rc, err=e.err) + xmltree = _execGlusterXml(command) + try: return _parseVolumeInfo(xmltree) except _etreeExceptions: @@ -592,7 +607,7 @@ def volumeGeoRepStatus(volumeName, remoteServer=None): if rc == 0: return _parseVolumeGeoRepStatus(volumeName, out) - raise GlusterCmdFailedException(rc=rc, err=err) + raise GlusterCmdFailedException(rc=rc, out=out, err=err) def volumeHealSplitBrainStatus(volumeName, remoteServer=None): @@ -620,7 +635,7 @@ def volumeHealSplitBrainStatus(volumeName, remoteServer=None): value['unsyncedentries'] = 0 volume[volumeName] = value return volume - raise GlusterCmdFailedException(rc=rc, err=err) + raise GlusterCmdFailedException(rc=rc, out=out, err=err) def volumeQuotaStatus(volumeName, remoteServer=None): @@ -637,12 +652,13 @@ def volumeQuotaStatus(volumeName, remoteServer=None): command += ['--remote-host=%s' % remoteServer] rc, out, err = _execGluster(command) + if rc == 0: return _parseVolumeQuotaStatus(out, isDisabled=False) else: if len(err) > 0 and err[0].find("Quota is disabled") > -1: return _parseVolumeQuotaStatus(out, isDisabled=True) - raise GlusterCmdFailedException(rc, err) + raise GlusterCmdFailedException(rc=rc, out=out, err=err) def _parsePeerStatus(tree, gHostName, gUuid, gStatus): @@ -674,10 +690,8 @@ def peerStatus(): """ command = _getGlusterPeerCmd() + ["status"] - try: - xmltree = _execGlusterXml(command) - except GlusterCmdFailedException as e: - raise GlusterCmdFailedException(rc=e.rc, err=e.err) + xmltree = _execGlusterXml(command) + try: return _parsePeerStatus(xmltree, "localhost", hostUUIDGet(), HostStatus.CONNECTED) -- cgit