summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRamesh Nachimuthu <rnachimu@redhat.com>2014-04-22 16:45:57 +0530
committerBala.FA <barumuga@redhat.com>2014-04-29 10:21:37 +0530
commitbee9f1ffe9e1586beda00e96d9e3da6171b3ab89 (patch)
treeb1bd463d9018edbeb9449e31d2fbef771965948a /tests
parent938e318bbfec1900aceea25c2702f234961c0493 (diff)
autoconf: use host name for host config
Discover the host name configured for the gluster node and use the same as host_name in nagios host configuration. Change-Id: Ib9eb8b3f3a1a03d1be28fa2faba44c2fc81fa0cf Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/test_config_generator.py19
-rw-r--r--tests/test_discovery.py82
3 files changed, 95 insertions, 7 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9e860b7..be571d6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,6 +23,7 @@ test_modules = \
test_check_remote_host.py \
test_notify_ovirt_engine_handler.py \
test_config_generator.py \
+ test_discovery.py
$(NULL)
dist_nagiosserveraddonstests_DATA = \
diff --git a/tests/test_config_generator.py b/tests/test_config_generator.py
index 891bcbc..6fe62d3 100644
--- a/tests/test_config_generator.py
+++ b/tests/test_config_generator.py
@@ -41,8 +41,8 @@ class TestGlusterNagiosConfManager(TestCaseBase):
clusterData['hosts'][index])
def __verifyHostConfig(self, hostConfig, hostData):
- self.assertEqual(hostConfig['host_name'], hostData['hostip'])
- self.assertEqual(hostConfig['alias'], hostData['hostip'])
+ self.assertEqual(hostConfig['host_name'], hostData['hostname'])
+ self.assertEqual(hostConfig['alias'], hostData['hostname'])
self.assertEqual(hostConfig['address'], hostData['hostip'])
self.assertEqual(hostConfig['use'], 'gluster-host')
@@ -50,23 +50,28 @@ class TestGlusterNagiosConfManager(TestCaseBase):
self.assertEqual(config['host_name'], clusterData['name'])
self.assertEqual(config['alias'], clusterData['name'])
self.assertEqual(config['address'], clusterData['name'])
- self.assertEqual(config['check_command'], "")
+ self.assertEqual(config.get('check_command'), None)
self.assertEqual(config['use'], 'gluster-cluster')
- def createBricks(self, count, volume):
+ def createBricks(self, count, volume, hostip):
bricks = []
for number in range(count):
brickDir = "/mnt/Brick-%s" % (number + 1)
bricks.append({'brickpath': brickDir,
- 'volumeName': volume})
+ 'volumeName': volume,
+ 'hostip': hostip})
return bricks
def __createDummyCluster(self):
cluster = {'name': 'Test-Cluster', 'hosts': [], 'volumes': []}
cluster['hosts'].append({'hostip': '10.70.43.1',
- 'bricks': self.createBricks(1, "Volume1")})
+ 'hostname': 'host-1',
+ 'bricks': self.createBricks(1, "Volume1",
+ '10.70.43.1')})
cluster['hosts'].append({'hostip': '10.70.43.2',
- 'bricks': self.createBricks(2, "Volume1")})
+ 'hostname': 'host-2',
+ 'bricks': self.createBricks(2, "Volume1",
+ '10.70.43.2')})
cluster['volumes'].append({'name': 'Volume1', "type": "T"})
return cluster
diff --git a/tests/test_discovery.py b/tests/test_discovery.py
new file mode 100644
index 0000000..0443cde
--- /dev/null
+++ b/tests/test_discovery.py
@@ -0,0 +1,82 @@
+#!/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 discovery
+from testrunner import PluginsTestCase as TestCaseBase
+
+
+class TestDiscovery(TestCaseBase):
+ def _mockExcecNRPECommand(self, host, command):
+ if command == "discoverlogicalcomponents":
+ return self._getLogicalComponents()
+ elif command == "discoverpeers":
+ return self._getPeers()
+ elif command == "discoverhostparams":
+ return self._getHostParams(host)
+
+ def _getLogicalComponents(self):
+ result = {}
+ result['volumes'] = []
+ result['volumes'].append({"bricks": [{"brickpath": "/bricks/v1-1",
+ "hostUuid": "0000-1111",
+ "hostip": "172.16.53.1"}],
+ "type": "DISTRIBUTE", "name": "V1"})
+ result['volumes'].append({"bricks": [{"brickpath": "/bricks/v2-1",
+ "hostUuid": "0000-1112",
+ "hostip": "172.16.53.2"}],
+ "type": "DISTRIBUTE", "name": "V2"})
+ return result
+
+ def _getPeers(self):
+ result = []
+ result.append({"hostip": "172.16.53.2"})
+ return result
+
+ def _getHostParams(self, hostip):
+ if hostip == "172.16.53.1":
+ return {"hostname": "node-1"}
+ elif hostip == "172.16.53.2":
+ return {"hostname": "node-2"}
+
+ def _verifyClusterData(self, clusterdata, clusterName, host):
+
+ self.assertEqual(clusterdata['hosts'][0]['hostip'],
+ self._getPeers()[0]['hostip'])
+ self.assertEqual(clusterdata['hosts'][1]['hostip'], host)
+ for host in clusterdata['hosts']:
+ hostDetails = self._getHostParams(host['hostip'])
+ self.assertEqual(host['hostname'], hostDetails['hostname'])
+ self.assertEqual(len(host['bricks']), 1)
+ volumes = self._getLogicalComponents()['volumes']
+ self.assertEqual(len(clusterdata['volumes']), len(volumes))
+
+ for i in range(len(volumes)):
+ self._verifyVolume(volumes[i], clusterdata['volumes'][i])
+
+ def _verifyVolume(self, expected, actual):
+ self.assertEqual(expected['name'], actual['name'])
+ self.assertEqual(expected['type'], actual['type'])
+
+ # Method to test the discoverCluster() method
+ def testDiscoverCluster(self):
+ discovery.excecNRPECommand = self._mockExcecNRPECommand
+ clusterName = "test-cluster"
+ host = "172.16.53.1"
+ clusterdata = discovery.discoverCluster(host, clusterName)
+ self._verifyClusterData(clusterdata, clusterName, host)