Ejemplo n.º 1
0
    def test_send_command_othererror_connecting(self):
        collectd = Mock()

        self.socket.connect.side_effect = IOError(errno.ENETUNREACH)

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        with self.assertRaises(IOError):
            s.send_command("a command")
Ejemplo n.º 2
0
    def test_send_command_othererror_connecting(self):
        collectd = Mock()

        self.socket.connect.side_effect = IOError(errno.ENETUNREACH)

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        with self.assertRaises(IOError):
            s.send_command("a command")
Ejemplo n.º 3
0
    def test_send_command_error_when_sending(self):
        collectd = Mock()

        self.response_chunks = [
            IOError(errno.ECONNREFUSED, ""),
        ]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        with self.assertRaises(IOError):
            s.send_command("a command")
Ejemplo n.º 4
0
    def test_send_command_error_when_sending(self):
        collectd = Mock()

        self.response_chunks = [
            IOError(errno.ECONNREFUSED, ""),
        ]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        with self.assertRaises(IOError):
            s.send_command("a command")
Ejemplo n.º 5
0
    def test_send_command_unknown_command(self):
        collectd = Mock()

        self.response_chunks = [b"Unknown command.\n", None]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("a command")

        self.assertEqual(result, "")

        collectd.error.assert_called_once_with(
            "Unknown HAProxy command: a command")
Ejemplo n.º 6
0
    def test_send_command_unknown_backend(self):
        collectd = Mock()

        self.response_chunks = [b"No such backend.\n", None]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("restart app09")

        self.assertEqual(result, "")

        collectd.error.assert_called_once_with(
            "No such server: 'restart app09'")
Ejemplo n.º 7
0
    def test_send_command_permission_denied(self):
        collectd = Mock()

        self.response_chunks = [b"Permission denied.\n", None]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("other command")

        self.assertEqual(result, "")

        collectd.error.assert_called_once_with(
            "Permission denied for command: other command")
Ejemplo n.º 8
0
    def test_send_command_unknown_command(self):
        collectd = Mock()

        self.response_chunks = [b"Unknown command.\n", None]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("a command")

        self.assertEqual(result, "")

        collectd.error.assert_called_once_with(
            "Unknown HAProxy command: a command"
        )
Ejemplo n.º 9
0
    def test_send_command_unknown_backend(self):
        collectd = Mock()

        self.response_chunks = [b"No such backend.\n", None]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("restart app09")

        self.assertEqual(result, "")

        collectd.error.assert_called_once_with(
            "No such server: 'restart app09'"
        )
Ejemplo n.º 10
0
    def test_send_command_permission_denied(self):
        collectd = Mock()

        self.response_chunks = [b"Permission denied.\n", None]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("other command")

        self.assertEqual(result, "")

        collectd.error.assert_called_once_with(
            "Permission denied for command: other command"
        )
Ejemplo n.º 11
0
    def test_send_command_connection_refused(self):
        collectd = Mock()

        self.socket.connect.side_effect = IOError(errno.ECONNREFUSED, "")

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("a command")

        self.socket.connect.assert_called_once_with("/var/run/sock.sock")
        self.assertEqual(result, None)

        collectd.error.assert_called_once_with(
            "Connection refused.  Is HAProxy running?")
Ejemplo n.º 12
0
    def test_send_command_connection_refused(self):
        collectd = Mock()

        self.socket.connect.side_effect = IOError(errno.ECONNREFUSED, "")

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("a command")

        self.socket.connect.assert_called_once_with("/var/run/sock.sock")
        self.assertEqual(result, None)

        collectd.error.assert_called_once_with(
            "Connection refused.  Is HAProxy running?"
        )
Ejemplo n.º 13
0
    def test_send_command_unreliable_network(self):
        collectd = Mock()

        self.response_chunks = [
            IOError(errno.EAGAIN, ""), b"this is\n", b"a\n",
            IOError(errno.EINTR, ""), b" fake response\n\n", None
        ]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("a command")

        self.socket.sendall.assert_called_once_with(b"a command\n")

        self.assertEqual(result, """this is
a
 fake response""")
Ejemplo n.º 14
0
    def test_send_command_unreliable_network(self):
        collectd = Mock()

        self.response_chunks = [
            IOError(errno.EAGAIN, ""),
            b"this is\n",
            b"a\n",
            IOError(errno.EINTR, ""),
            b" fake response\n\n",
            None
        ]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("a command")

        self.socket.sendall.assert_called_once_with(b"a command\n")

        self.assertEqual(
            result,
            """this is
a
 fake response"""
        )