summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamesh Nachimuthu <rnachimu@redhat.com>2014-05-01 12:37:54 +0530
committerSahina Bose <sabose@redhat.com>2014-05-02 02:23:55 -0700
commitd0327fab7fbaf2c6f30e807fb8c90dfe5fa9db5c (patch)
treefb9d155b0a7221e3ce26bce92f825d1cb255033b
parente222d3e0c4209d59f079d15484138bea9d859378 (diff)
autoconf: discover volume list and info separately
NRPE doesn't support transfering large junk of data as a result. Hence we have to discover the volume details one by one. Added two NRPE commands 'discover_volume_list' and 'discover_volume_info'. 'discover_volume_list' returns the list of volume names with volume type. 'discover_volume_info' returns the bricks details of a given volume. Change-Id: I753be5e407fe14988f23ca77007b3a585537b360 Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com> Reviewed-on: http://review.gluster.org/7630 Reviewed-by: Kanagaraj M <kmayilsa@redhat.com> Reviewed-by: Sahina Bose <sabose@redhat.com>
-rw-r--r--gluster-nagios-addons.spec.in3
-rw-r--r--plugins/Makefile.am2
-rwxr-xr-xplugins/discover_volumes.py83
-rwxr-xr-xplugins/discoverlogicalcomponents.py50
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/test_discover_volumes.py99
6 files changed, 186 insertions, 52 deletions
diff --git a/gluster-nagios-addons.spec.in b/gluster-nagios-addons.spec.in
index ec0d6b7..fb31946 100644
--- a/gluster-nagios-addons.spec.in
+++ b/gluster-nagios-addons.spec.in
@@ -144,7 +144,8 @@ command[check_vol_utilization]=sudo %{_libdir}/nagios/plugins/gluster/check_vol_
command[check_vol_status]=sudo %{_libdir}/nagios/plugins/gluster/check_volume_status.py -v \$ARG1\$ -t \$ARG2\$
###Auto Discovery related
command[discoverpeers]=sudo %{_libdir}/nagios/plugins/gluster/discoverpeers.py
-command[discoverlogicalcomponents]=sudo %{_libdir}/nagios/plugins/gluster/discoverlogicalcomponents.py
+command[discover_volume_list]=sudo %{_libdir}/nagios/plugins/gluster/discover_volumes.py -l
+command[discover_volume_info]=sudo %{_libdir}/nagios/plugins/gluster/discover_volumes.py -v \$ARG1\$
command[discoverhostparams]=sudo %{_libdir}/nagios/plugins/gluster/discoverhostparams.py
command[configure_gluster_node]=sudo %{_libdir}/nagios/plugins/gluster/configure_gluster_node.py -c \$ARG1\$ -n \$ARG2\$ -H \$ARG3\$
EOF
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 700072a..de6bf41 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -17,7 +17,7 @@ dist_glusternagiosplugins_PYTHON = \
check_proc_status.py \
cpu.py \
discoverpeers.py \
- discoverlogicalcomponents.py \
+ discover_volumes.py \
discoverhostparams.py \
configure_gluster_node.py \
__init__.py \
diff --git a/plugins/discover_volumes.py b/plugins/discover_volumes.py
new file mode 100755
index 0000000..f917d40
--- /dev/null
+++ b/plugins/discover_volumes.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python
+# discover_volumes.py -- nagios plugin for discovering
+#logical gluster components
+# Copyright (C) 2014 Red Hat Inc
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+#
+import json
+import sys
+import argparse
+
+from glusternagios import utils
+from glusternagios import glustercli
+
+
+def discoverVolumes(volumeName, list):
+ """
+ This method helps to discover volumes list and volume info
+ Parameters
+ ----------
+ list: Flag used for getting volume info. If the flag is 'True' then the
+ method will return only list of volume names with volume Type and doesn't
+ include the brick details. . If list is 'False' then returns the volume
+ details with brick information.
+
+ volumeName: Fetch information only for the given volume.
+ Note: glustercli.volumeInfo(volName) command accept a volumeName. But if
+ the volume name is not passed then it returns details about all the volumes
+ in the cluster.
+ Returns
+ ---------
+ Returns volume details in the following dictionary format
+ {
+ 'vol-name' : {vol-details}
+ 'vol-name' : {vol-details}
+ 'vol-name' : {vol-details}
+ ...
+ }
+ """
+ resultlist = {}
+ volumes = glustercli.volumeInfo(volumeName)
+ for key, volume in volumes.iteritems():
+ volDict = {}
+ volDict['name'] = key
+ volDict['type'] = volume['volumeType']
+ if not list:
+ volDict['bricks'] = []
+ for brick in volume['bricksInfo']:
+ brickproplist = brick['name'].split(':')
+ volDict['bricks'].append({'brickpath': brickproplist[1],
+ 'hostUuid': brick['hostUuid']})
+ resultlist[key] = volDict
+ resultString = json.dumps(resultlist)
+ return resultString
+
+
+def get_arg_parser():
+ parser = argparse.ArgumentParser(description="Discovery tool for "
+ "Gluster volumes")
+ parser.add_argument('-l', '--list', action='store_true', dest='list',
+ help="Fetch only list of volumes names")
+ parser.add_argument('-v', '--volume', action='store', dest='volume',
+ type=str, help='Volume name')
+ return parser
+
+
+if __name__ == '__main__':
+ args = get_arg_parser().parse_args()
+ resultString = discoverVolumes(args.volume, args.list)
+ print resultString
+ sys.exit(utils.PluginStatusCode.OK)
diff --git a/plugins/discoverlogicalcomponents.py b/plugins/discoverlogicalcomponents.py
deleted file mode 100755
index 0d826ff..0000000
--- a/plugins/discoverlogicalcomponents.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/python
-# discoverlogicalcomponents.py -- nagios plugin for discovering
-#logical gluster components
-# Copyright (C) 2014 Red Hat Inc
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-#
-import json
-import sys
-
-from glusternagios import utils
-from glusternagios import glustercli
-
-
-def discoverlogicalelements():
- resultlist = {}
- resultlist['volumes'] = []
-
- volumes = glustercli.volumeInfo()
- for volume in volumes.values():
- volDict = {}
- volDict['name'] = volume['volumeName']
- volDict['type'] = volume['volumeType']
- volDict['bricks'] = []
- for brick in volume['bricksInfo']:
- brickproplist = brick['name'].split(':')
- volDict['bricks'].append({'hostip': brickproplist[0],
- 'brickpath': brickproplist[1],
- 'hostUuid': brick['hostUuid']})
- resultlist['volumes'].append(volDict)
-
- resultstring = json.dumps(resultlist)
- print resultstring
- sys.exit(utils.PluginStatusCode.OK)
-
-
-if __name__ == '__main__':
- discoverlogicalelements()
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0712feb..0777a27 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -32,6 +32,7 @@ test_modules = \
test_sadf.py \
test_swap.py \
test_swap_dataFile.py \
+ test_discover_volumes.py \
$(NULL)
dist_glusternagiosaddonstests_DATA = \
diff --git a/tests/test_discover_volumes.py b/tests/test_discover_volumes.py
new file mode 100644
index 0000000..0a61ba7
--- /dev/null
+++ b/tests/test_discover_volumes.py
@@ -0,0 +1,99 @@
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from testrunner import PluginsTestCase as TestCaseBase
+from plugins import discover_volumes
+import json
+
+
+class TestDiscoverVolumes(TestCaseBase):
+ def _getVolumeInfo(self):
+ result = {}
+ result['V1'] = {"bricksInfo": [{"name": "172.16.53.1:/bricks/v1-1",
+ "hostUuid": "0000-1111"}],
+ "volumeType": "DISTRIBUTE", "volumeName": "V1"}
+ result['V2'] = {"bricksInfo": [{"name": "172.16.53.2:/bricks/v2-1",
+ "hostUuid": "0000-1112"}],
+ "volumeType": "DISTRIBUTE", "volumeName": "V2"}
+ return result
+
+ def _mockGetVolumeInfo(self, volumeName):
+ volumes = self._getVolumeInfo()
+ if volumeName:
+ return {volumeName: volumes.get(volumeName)}
+ else:
+ return volumes
+
+ def _getBrickByHostAndPath(self, bricksList, hostUuid, path):
+ for brick in bricksList:
+ if brick.get('hostUuid') == hostUuid and \
+ brick.get('brickpath') == path:
+ return brick
+ return None
+
+ def _verifyVolumeList(self, volDict):
+ expectedVolumes = self._getVolumeInfo()
+ self.assertEqual(len(expectedVolumes), len(volDict))
+ for volName, volumeExpected in expectedVolumes.iteritems():
+ vol = volDict[volName]
+ self.assertEqual(volumeExpected['volumeType'], vol['type'])
+ self.assertEqual(volumeExpected['volumeName'], vol['name'])
+ self.assertEqual(vol.get('bricks'), None)
+
+ def _verifyVolumeInfo(self, volDict, volName):
+ expectedVolumes = self._mockGetVolumeInfo(volName)
+ self.assertEqual(len(expectedVolumes), len(volDict))
+ for volName, volumeExpected in expectedVolumes.iteritems():
+ vol = volDict[volName]
+ self.assertEqual(volumeExpected['volumeType'], vol['type'])
+ self.assertEqual(volumeExpected['volumeName'], vol['name'])
+ self.assertEqual(len(volumeExpected.get('bricksInfo')),
+ len(vol.get('bricks')))
+ for brickExpected in volumeExpected.get('bricksInfo'):
+ brick = self._getBrickByHostAndPath(
+ vol.get('bricks'), brickExpected['hostUuid'],
+ brickExpected['name'].split(":")[1])
+ self.assertEqual(brick.get('hostUuid'),
+ brickExpected.get('hostUuid'))
+
+ def testDiscoverVolumesList(self):
+ discover_volumes.glustercli.volumeInfo = self._mockGetVolumeInfo
+ volumesList = json.loads(discover_volumes.discoverVolumes(None, True))
+ self._verifyVolumeList(volumesList)
+
+ def testDiscoverVolumesInfo(self):
+ discover_volumes.glustercli.volumeInfo = self._mockGetVolumeInfo
+ volumesList = json.loads(discover_volumes.discoverVolumes("V1", False))
+ self._verifyVolumeInfo(volumesList, "V1")
+
+ def testAruguments(self):
+ argParser = discover_volumes.get_arg_parser()
+ args = argParser.parse_args(["-l", "-v", "V1"])
+ self.assertEqual(args.list, True)
+ self.assertEqual(args.volume, "V1")
+ args = argParser.parse_args(["--list", "--volume", "V1"])
+ self.assertEqual(args.list, True)
+ self.assertEqual(args.volume, "V1")
+ args = argParser.parse_args(["--v", "V1"])
+ self.assertEqual(args.volume, "V1")
+ self.assertEqual(args.list, False)
+ args = argParser.parse_args(["-l"])
+ self.assertEqual(args.list, True)
+ self.assertEqual(args.volume, None)