From 05278f31d54d89ef0a68e94af389d66a3c3b6f74 Mon Sep 17 00:00:00 2001 From: Ramesh Nachimuthu Date: Fri, 28 Mar 2014 17:48:54 +0530 Subject: AutoDiscovery: Auto discovery for gluster entities Basic plugin which will discover all the basic gluster entities and creates nagios configuration. Change-Id: I71f05dec9bcce74969db300393f7f7c178161dba Signed-off-by: Ramesh Nachimuthu Reviewed-on: https://code.engineering.redhat.com/gerrit/22100 Reviewed-by: Sahina Bose --- tests/Makefile.am | 1 + tests/test_config_generator.py | 74 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/test_config_generator.py (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 40a09a3..9e860b7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,6 +22,7 @@ test_modules = \ test_check_cluster_volusage.py \ test_check_remote_host.py \ test_notify_ovirt_engine_handler.py \ + test_config_generator.py \ $(NULL) dist_nagiosserveraddonstests_DATA = \ diff --git a/tests/test_config_generator.py b/tests/test_config_generator.py new file mode 100644 index 0000000..21500a9 --- /dev/null +++ b/tests/test_config_generator.py @@ -0,0 +1,74 @@ +#!/usr/bin/python +# 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 +# + +import mock +from plugins import config_generator +from testrunner import PluginsTestCase as TestCaseBase + + +class TestGlusterNagiosConfManager(TestCaseBase): + # Method to test the generateNagiosConfigFromGlusterCluster() method + @mock.patch('plugins.config_generator.GlusterNagiosConfManager.' + 'generateConfigFiles') + def testGenerateConfigFiles(self, mock_generateConfigFiles): + confManager = self.__getGlusterNagiosConfManager() + clusterData = self.__createDummyCluster() + clusterConfig = confManager.generateNagiosConfigFromGlusterCluster( + clusterData) + mock_generateConfigFiles.assert_called() + self.__verifyConfig(clusterConfig, clusterData) + + def __verifyConfig(self, clusterConfig, clusterData): + self.assertTrue(len(clusterConfig), len(clusterData['hosts']) + 1) + self.__verifyClusterConfig(clusterConfig[0], clusterData) + for index in range(0, len(clusterData['hosts'])): + self.__verifyHostConfig(clusterConfig[index + 1], + clusterData['hosts'][index]) + + def __verifyHostConfig(self, hostConfig, hostData): + self.assertEqual(hostConfig['host_name'], hostData['hostip']) + self.assertEqual(hostConfig['alias'], hostData['hostip']) + self.assertEqual(hostConfig['address'], hostData['hostip']) + self.assertEqual(hostConfig['use'], 'gluster-host') + + def __verifyClusterConfig(self, config, clusterData): + self.assertEqual(config['host_name'], clusterData['name']) + self.assertEqual(config['alias'], clusterData['name']) + self.assertEqual(config['address'], clusterData['name']) + self.assertEqual(config['check_command'], "check_dummy") + self.assertEqual(config['use'], 'gluster-cluster') + + def createBricks(self, count): + bricks = [] + for number in range(count): + brickDir = "/mnt/Brick-%s" % (number + 1) + bricks.append({'brickpath': brickDir}) + return bricks + + def __createDummyCluster(self): + cluster = {'name': 'Test-Cluster', 'hosts': [], 'volumes': []} + cluster['hosts'].append({'hostip': '10.70.43.1', + 'bricks': self.createBricks(1)}) + cluster['hosts'].append({'hostip': '10.70.43.2', + 'bricks': self.createBricks(2)}) + cluster['volumes'].append({'name': 'Volume1', "typeStr": "T"}) + return cluster + + def __getGlusterNagiosConfManager(self): + return config_generator.GlusterNagiosConfManager( + "/tmp/nagios/gluster", "../config", "gluster-host.cfg.template") -- cgit