summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSahina Bose <sabose@redhat.com>2014-05-05 17:32:05 +0530
committerSahina Bose <sabose@redhat.com>2014-05-05 05:22:28 -0700
commit255dbf79a9c987d354c5d27ea6af88dacfa54427 (patch)
tree0a11f0cf2c757fdd029b10ef972abe9a30f9e935
parent1c6a1c3c3e124f4d000b4fd1f0b9bb1732f6ee0e (diff)
plugins: Enhanced volume quota status plugin
Quota status plugin enhanced to return soft-limit as well as hard-limit exceeded messages along with the directories that it's exceeded on. Change-Id: I77a8686e2742e2174c9f5ebdade8f017a1ffad4e Signed-off-by: Sahina Bose <sabose@redhat.com> Reviewed-on: http://review.gluster.org/7672 Reviewed-by: Kanagaraj M <kmayilsa@redhat.com>
-rwxr-xr-xplugins/check_volume_status.py19
-rw-r--r--tests/test_check_volume_status.py24
2 files changed, 36 insertions, 7 deletions
diff --git a/plugins/check_volume_status.py b/plugins/check_volume_status.py
index 9404251..2a1e051 100755
--- a/plugins/check_volume_status.py
+++ b/plugins/check_volume_status.py
@@ -48,15 +48,26 @@ def getVolumeStatus(args):
def getVolumeQuotaStatus(args):
try:
- status = glustercli.volumeQuotaStatus(args.volume)
+ qstatus = glustercli.volumeQuotaStatus(args.volume)
except glustercli.GlusterCmdFailedException as e:
out = ("QUOTA: Quota status could not be determined %s"
% '.'.join(e.err))
return utils.PluginStatusCode.UNKNOWN, out
- if status == glustercli.VolumeQuotaStatus.EXCEEDED:
- return utils.PluginStatusCode.WARNING, "QUOTA: limit exceeded"
- elif status == glustercli.VolumeQuotaStatus.DISABLED:
+ returnMsg = "QUOTA:"
+ if qstatus.get("hard_ex_dirs") is not None:
+ hard_limit_ex = ', '.join(qstatus['hard_ex_dirs'])
+ returnMsg += ("hard limit exceeded on %s; " % hard_limit_ex)
+ if qstatus.get('soft_ex_dirs'):
+ soft_limit_ex = ', '.join(qstatus['soft_ex_dirs'])
+ returnMsg += ("soft limit exceeded on %s" % soft_limit_ex)
+
+ if qstatus['status'] == glustercli.VolumeQuotaStatus.SOFT_LIMIT_EXCEEDED:
+ return utils.PluginStatusCode.WARNING, returnMsg
+ elif (qstatus['status'] ==
+ glustercli.VolumeQuotaStatus.HARD_LIMIT_EXCEEDED):
+ return utils.PluginStatusCode.CRITICAL, returnMsg
+ elif qstatus['status'] == glustercli.VolumeQuotaStatus.DISABLED:
return utils.PluginStatusCode.OK, "QUOTA: not enabled or configured"
else:
return utils.PluginStatusCode.OK, "QUOTA: OK"
diff --git a/tests/test_check_volume_status.py b/tests/test_check_volume_status.py
index 4d4f940..ad43587 100644
--- a/tests/test_check_volume_status.py
+++ b/tests/test_check_volume_status.py
@@ -56,12 +56,18 @@ class TestCheckVolumeStatus(TestCaseBase):
@mock.patch('glusternagios.glustercli.volumeQuotaStatus')
def test_checkVolumeQuotaStatus(self, mock_volumeQuotaStatus):
- mock_volumeQuotaStatus.return_value = glustercli.\
- VolumeQuotaStatus.EXCEEDED
args = ArgParseMock('test-cluster', 'test-vol', 'quota')
+ mock_volumeQuotaStatus.return_value = _getQuotaStatusHardLimit()
exitStatusCode, exitStatusMsg = (check_volume_status
.getVolumeQuotaStatus(args))
- assert exitStatusCode == utils.PluginStatusCode.WARNING
+ assert exitStatusCode == utils.PluginStatusCode.CRITICAL
+ self.assertEqual("QUOTA:hard limit exceeded on dir1, dir2; "
+ "soft limit exceeded on dir3", exitStatusMsg)
+ mock_volumeQuotaStatus.return_value = _getQuotaStatusOk()
+ exitStatusCode, exitStatusMsg = (check_volume_status
+ .getVolumeQuotaStatus(args))
+ assert exitStatusCode == utils.PluginStatusCode.OK
+ self.assertEqual("QUOTA: OK", exitStatusMsg)
@mock.patch('glusternagios.glustercli.volumeGeoRepStatus')
def test_checkVolumeGeoRepStatus(self, mock_GeoRepStatus):
@@ -103,6 +109,18 @@ def _getEmptyVolume():
return {}
+def _getQuotaStatusHardLimit():
+ return {'status': 'HARD_LIMIT_EXCEEDED',
+ 'hard_ex_dirs': ['dir1', 'dir2'],
+ 'soft_ex_dirs': ['dir3']}
+
+
+def _getQuotaStatusOk():
+ return {'status': 'OK',
+ 'hard_ex_dirs': [],
+ 'soft_ex_dirs': []}
+
+
def _getGeoRepStatus(status):
return {'test-vol': {'status': status,
'detail': "rhs3-2.novalocal - faulty;"}}