From 57c6902d0dd84950adaa21cf6f649e679a913b37 Mon Sep 17 00:00:00 2001 From: Sahina Bose Date: Tue, 29 Sep 2015 12:19:04 +0530 Subject: nagios-plugins: CLI to parse heal info Added CLI to parse heal info and provide json output changed parsing of heal info to match the enhanced output patch - http://review.gluster.org/13231 Renamed VolumeSplitBrainStatus enum to generic VolumeHealInfoStatus BUG: 1267586 Change-Id: I948d00d0198894a9a670e72b311ab86c83af4b23 Signed-off-by: Sahina Bose Reviewed-on: http://review.gluster.org/12260 Reviewed-by: Ramesh N --- tests/test_glustercli.py | 112 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_glustercli.py b/tests/test_glustercli.py index d9ef1ab..d770b92 100644 --- a/tests/test_glustercli.py +++ b/tests/test_glustercli.py @@ -29,6 +29,8 @@ class GlusterCliTests(TestCaseBase): def _parseVolumeInfo_empty_test(self): out = """ + + 0 0 @@ -1114,13 +1116,23 @@ class GlusterCliTests(TestCaseBase): @mock.patch('glusternagios.utils.execCmd') @mock.patch('glusternagios.glustercli._getGlusterVolCmd') - def test_getVolumeHealSplitBrainStatusNonRepl(self, mock_glusterVolCmd, + @mock.patch('glusternagios.glustercli.volumeInfo') + def test_getVolumeHealSplitBrainStatusNonRepl(self, + mock_volumeInfo, + mock_glusterVolCmd, mock_execCmd,): mock_glusterVolCmd.return_value = ["gluster", "volume"] + mock_volumeInfo.return_value = {'test-vol': + {'volumeType': 'DISTRIBUTE', + 'replicaCount': 1, + 'brickCount': 2 + } + } mock_execCmd.return_value = 2, None, ["Volume test-vol is not " "of type replicate"] expectedOut = {'test-vol': - {'status': gcli.VolumeSplitBrainStatus.NOTAPPLICABLE, + {'status': gcli.VolumeHealInfoStatus.NOTAPPLICABLE, + 'undergoingheal': 0, 'unsyncedentries': 0}} status = gcli.volumeHealSplitBrainStatus("test-vol") print(status) @@ -1128,19 +1140,79 @@ class GlusterCliTests(TestCaseBase): @mock.patch('glusternagios.utils.execCmd') @mock.patch('glusternagios.glustercli._getGlusterVolCmd') - def test_getVolumeHealSplitBrainStatus(self, mock_glusterVolCmd, + @mock.patch('glusternagios.glustercli.volumeInfo') + def test_getVolumeHealSplitBrainStatus(self, + mock_volumeInfo, + mock_glusterVolCmd, mock_execCmd,): mock_glusterVolCmd.return_value = ["gluster", "volume"] + mock_volumeInfo.return_value = {'test-vol': + {'volumeType': 'REPLICATE', + 'replicaCount': 2, + 'brickCount': 2 + } + } mock_execCmd.return_value = (0, self.__getGlusterSelfHealInfoResult(), None) expectedOut = {'test-vol': - {'status': gcli.VolumeSplitBrainStatus.SPLITBRAIN, + {'status': gcli.VolumeHealInfoStatus.ENTRIESFOUND, + 'undergoingheal': 0, 'unsyncedentries': 10}} status = gcli.volumeHealSplitBrainStatus("test-vol") print(status) self.assertEquals(status, expectedOut) + @mock.patch('glusternagios.utils.execCmd') + @mock.patch('glusternagios.glustercli._getGlusterVolCmd') + @mock.patch('glusternagios.glustercli.volumeInfo') + def test_getVolumeHealInfoUndergoingStatus(self, + mock_volumeInfo, + mock_glusterVolCmd, + mock_execCmd,): + mock_glusterVolCmd.return_value = ["gluster", "volume"] + mock_volumeInfo.return_value = {'test-vol': + {'volumeType': 'REPLICATE', + 'replicaCount': 2, + 'brickCount': 2 + } + } + mock_execCmd.return_value = (0, + self.__getGlusterSelfHealInfoUndergoingResult(), + None) + expectedOut = {'test-vol': + {'status': gcli.VolumeHealInfoStatus.ENTRIESFOUND, + 'undergoingheal': 1, + 'unsyncedentries': 10}} + status = gcli.volumeHealSplitBrainStatus("test-vol") + print(status) + self.assertEquals(status, expectedOut) + + @mock.patch('glusternagios.utils.execCmd') + @mock.patch('glusternagios.glustercli._getGlusterVolCmd') + @mock.patch('glusternagios.glustercli.volumeInfo') + def test_getVolumeHealSplitBrainStatusNoBrick(self, + mock_volumeInfo, + mock_glusterVolCmd, + mock_execCmd,): + mock_glusterVolCmd.return_value = ["gluster", "volume"] + mock_volumeInfo.return_value = {'test-vol': + {'volumeType': 'REPLICATE', + 'replicaCount': 2, + 'brickCount': 2 + } + } + mock_execCmd.return_value = (0, + self.__getGlusterSelfHealInfoResultBrickDown(), + None) + expectedOut = {'test-vol': + {'status': gcli.VolumeHealInfoStatus.OK, + 'undergoingheal': 0, + 'unsyncedentries': 0}} + status = gcli.volumeHealSplitBrainStatus("test-vol") + print(status) + self.assertEquals(status, expectedOut) + @mock.patch('glusternagios.glustercli._getGlusterVolCmd') @mock.patch('glusternagios.glustercli.volumeInfo') def test_getVolumeGeoRepStatus(self, @@ -1272,6 +1344,38 @@ class GlusterCliTests(TestCaseBase): "/dir.10/file.2", "/dir.7/file.4"] + def __getGlusterSelfHealInfoUndergoingResult(self): + return ["Gathering list of entries to be healed " + "on volume rep has been successful", + "", + "Brick node2:/bricks/b3", + "Status: Brick is Not connected", + "Number of entries in split-brain: NA" + "", + "Brick node1:/bricks/b3", + "Number of entries in split-brain: 10", + "/dir.7/file.5 - Possibly undergoing heal", + "/dir.8/file.3", + "/dir.9/file.5", + "/dir.2/file.4", + "/dir.9/file.4", + "/dir.4/file.1", + "/file.4", + "/dir.7/file.2", + "/dir.10/file.2", + "/dir.7/file.4"] + + def __getGlusterSelfHealInfoResultBrickDown(self): + return ["Gathering list of entries to be healed " + "on volume rep has been successful", + "", + "Brick node2:/bricks/b3", + "Status: Brick is Not connected", + "Number of entries in split-brain: 0" + "", + "Brick node1:/bricks/b3", + "Number of entries in split-brain: -"] + def __getGlusterGeoRepStatusResult(self): return """ -- cgit