From fdcfd605a72fb3c13ddade5dfed4275c929afff5 Mon Sep 17 00:00:00 2001 From: Sahina Bose Date: Thu, 10 Apr 2014 15:37:27 +0530 Subject: common: Added volume quota status Added volume quota status to glustercli Change-Id: Iefe0766d652dab7adb5d2514410434fb5c190631 Signed-off-by: Sahina Bose Signed-off-by: Kanagaraj M --- glusternagios/glustercli.py | 30 ++++++++++++++++++++++++++++++ tests/test_glustercli.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/glusternagios/glustercli.py b/glusternagios/glustercli.py index 0a126e7..03ea806 100755 --- a/glusternagios/glustercli.py +++ b/glusternagios/glustercli.py @@ -82,6 +82,12 @@ class VolumeStatus: OFFLINE = 'OFFLINE' +class VolumeQuotaStatus: + DISABLED = 'DISABLED' + OK = 'OK' + EXCEEDED = 'EXCEEDED' + + class TransportType: TCP = 'TCP' RDMA = 'RDMA' @@ -432,6 +438,30 @@ def volumeInfo(volumeName=None, remoteServer=None): raise GlusterCmdFailedException(err=[etree.tostring(xmltree)]) +def _parseVolumeQuotaStatus(out): + for line in out: + if line.startswith('quota: No quota') or line.find('not enabled') > -1: + return VolumeQuotaStatus.DISABLED + if line.find('Yes') > -1: + return VolumeQuotaStatus.EXCEEDED + return VolumeQuotaStatus.OK + + +def volumeQuotaStatus(volumeName, remoteServer=None): + """ + Returns: + STATUS + """ + command = _getGlusterVolCmd() + ["quota", volumeName, "list"] + if remoteServer: + command += ['--remote-host=%s' % remoteServer] + + rc, out, err = _execGluster(command) + if rc == 0: + return _parseVolumeQuotaStatus(out) + raise GlusterCmdFailedException(rc, err) + + def _parsePeerStatus(tree, gHostName, gUuid, gStatus): hostList = [{'hostname': gHostName, 'uuid': gUuid, diff --git a/tests/test_glustercli.py b/tests/test_glustercli.py index 53865cd..1f240fa 100644 --- a/tests/test_glustercli.py +++ b/tests/test_glustercli.py @@ -21,6 +21,7 @@ from testrunner import GlusterNagiosTestCase as TestCaseBase from glusternagios import glustercli as gcli import xml.etree.cElementTree as etree +import mock class GlusterCliTests(TestCaseBase): @@ -1057,3 +1058,45 @@ class GlusterCliTests(TestCaseBase): self._parseVolumeStatusDetail_test() self._parseVolumeStatusClients_test() self._parseVolumeStatusMem_test() + + @mock.patch('glusternagios.utils.execCmd') + @mock.patch('glusternagios.glustercli._getGlusterVolCmd') + def test_parseVolumeQuotaStatus(self, mock_glusterVolCmd, mock_execCmd,): + mock_glusterVolCmd.return_value = ["gluster", "volume"] + mock_execCmd.return_value = 0, ["quota command failed : " + "Quota is not enabled on " + "volume demo-test-vol"], None + status = gcli.volumeQuotaStatus("test-vol") + self.assertEquals(status, gcli.VolumeQuotaStatus.DISABLED) + mock_execCmd.return_value = 0, ["quota: No quota " + "configured on " + "volume demo-test-vol"], None + status = gcli.volumeQuotaStatus("test-vol") + self.assertEquals(status, gcli.VolumeQuotaStatus.DISABLED) + mock_execCmd.return_value = 0, self.__getQuotaOut(), None + status = gcli.volumeQuotaStatus("test-vol") + self.assertEquals(status, gcli.VolumeQuotaStatus.EXCEEDED) + + @mock.patch('glusternagios.utils.execCmd') + @mock.patch('glusternagios.glustercli._getGlusterVolCmd') + def test_parseVolumeQuotaStatusWhenException(self, + mock_glusterVolCmd, + mock_execCmd,): + mock_glusterVolCmd.return_value = ["gluster", "volume"] + mock_execCmd.return_value = -1, None, "err" + try: + gcli.volumeQuotaStatus("test-vol") + assert False + except gcli.GlusterCmdFailedException: + assert True + + def __getQuotaOut(self): + return \ + [" Path Hard-limit Soft-limit" + " Used Available Soft-limit exceeded? Hard-limit exceeded?", + "-------------------------------------------------------------" + "--------------------------------------------------------------", + "/test 200.0KB 80% " + " 200.0KB 0Bytes No No", + "/test/rewe 200.0KB 80% " + "200.0KB 0Bytes Yes Yes"] -- cgit