From 795fc58ef57127f257ea06c8c77ff8fba0662a4e Mon Sep 17 00:00:00 2001 From: Shubhendu Tripathi Date: Fri, 14 Mar 2014 12:56:53 +0530 Subject: nagios-server-addons: Check remote host plugin Plugins to ckeck the remote host status based on various services. Change-Id: I1e260829901aa8dd831f0ca1d58609addb9bcf1b Signed-off-by: Shubhendu Tripathi Reviewed-on: https://cuckoo.blr.redhat.com:8443/9 Reviewed-by: Sahina Bose Tested-by: Sahina Bose --- tests/test_check_remote_host.py | 47 ++++++++++++----------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) (limited to 'tests') diff --git a/tests/test_check_remote_host.py b/tests/test_check_remote_host.py index c5c602d..f7965f3 100644 --- a/tests/test_check_remote_host.py +++ b/tests/test_check_remote_host.py @@ -19,49 +19,28 @@ # import mock +import socket +import plugins from testrunner import PluginsTestCase as TestCaseBase -from plugins.check_remote_host import * -class TestHello(TestCaseBase): - # Method to test the execCmd() method - @mock.patch('check_remote_host.subprocess.Popen') - def testExecCmd(self, mock_popen): - reference = subprocess.Popen('any command', close_fds=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - out = "sample output" - err = "" - reference.communicate.return_value = (out, err) - self.assertTrue(reference.communicate, "communicate called") - - # Method to test the getPingStatus() method - @mock.patch('check_remote_host.execCmd') - def testGetPingStatus(self, mock_execCmd): - rc = 0 - out = "sample output" - err = "" - mock_execCmd.return_value = (rc, out, err) - getPingStatus('dummy host') - mock_execCmd.assert_called_with([ - '/usr/lib64/nagios/plugins/check_ping', '-H', 'dummy', 'host', - '-w', '3000.0,80%', '-c', '5000.0,100%']) - self.assertRaises(OSError, execCmd, - ['/usr/lib64/nagios/plugins/check_ping', '-H', - 'dummy', 'host', '-w', '3000.0,80%', '-c', - '5000.0,100%']) - +class TestCheckRemoteHost(TestCaseBase): # Method to test the checkLiveStatus() method - @mock.patch('check_remote_host.socket.socket') + @mock.patch('plugins.check_remote_host.livestatus.socket.socket') def testCheckLiveStatus(self, mock_socket): reference = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.assertTrue(mock_socket, "called") reference.recv.return_value = "0\n" - checkLiveStatus("dummy host", "dummy srvc") - reference.connect.assert_called_with('/var/spool/nagios/cmd/live') + plugins.check_remote_host.checkLiveStatus("dummy host", "dummy srvc") + reference.connect.assert_called_with("${localstatedir}/" + "spool/nagios/cmd/live") reference.send.assert_called_with("GET services\nColumns: state\n" "Filter: description = dummy srvc\n" "Filter: host_address = " - "dummy host\n") - self.assertEquals(0, checkLiveStatus("dummy host", "dummy srvc")) + "dummy host\n" + "Separators: 10 124 44 59") + self.assertEquals(0, + plugins. + check_remote_host. + checkLiveStatus("dummy host", "dummy srvc")) -- cgit