From d0327fab7fbaf2c6f30e807fb8c90dfe5fa9db5c Mon Sep 17 00:00:00 2001 From: Ramesh Nachimuthu Date: Thu, 1 May 2014 12:37:54 +0530 Subject: 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 Reviewed-on: http://review.gluster.org/7630 Reviewed-by: Kanagaraj M Reviewed-by: Sahina Bose --- tests/Makefile.am | 1 + tests/test_discover_volumes.py | 99 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 tests/test_discover_volumes.py (limited to 'tests') 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) -- cgit