Ejemplo n.º 1
0
  def testunit_assert_collectd_responds_WHEN_filesystem_is_readonly(
      self, mock_access):
    # Mock out os.access to guarantee that write access is rejected.
    mock_access.return_value = False

    with self.assertRaises(check_collectd_mlab.ReadonlyFilesystemError):
      check_collectd_mlab.assert_collectd_responds()

    self.assertTrue(mock_access.called)
Ejemplo n.º 2
0
  def testunit_assert_collectd_responds_WHEN_sock_readline_fails(
      self, mock_sock_connect):
    """Fails when reading from socket after a successful connection."""
    # After sending a default reply, the fake socket reaches EOF.
    mock_sock_connect.return_value = FakeSocketIO('1 default reply\n')

    with self.assertRaises(check_collectd_mlab.SocketReadlineError):
      check_collectd_mlab.assert_collectd_responds()

    mock_sock_connect.assert_called_with(
        check_collectd_mlab.COLLECTD_UNIXSOCK)
Ejemplo n.º 3
0
  def testunit_assert_collectd_responds_WHEN_sock_sendcmd_fails(
      self, mock_sock_connect):
    """Fails when sending a command after successfully creating a connection."""
    mock_sock = mock.Mock(spec_set=socket.socket)
    mock_sock.send.side_effect = socket.error('fake socket error')
    mock_sock_connect.return_value = mock_sock

    with self.assertRaises(check_collectd_mlab.SocketSendCommandError):
      check_collectd_mlab.assert_collectd_responds()

    mock_sock_connect.assert_called_with(
        check_collectd_mlab.COLLECTD_UNIXSOCK)
Ejemplo n.º 4
0
  def testunit_assert_collectd_responds_WHEN_sock_connect_fails(self):
    """Fails when creating a socket connection."""
    check_collectd_mlab.COLLECTD_UNIXSOCK = 'does_not_exist'

    with self.assertRaises(check_collectd_mlab.SocketConnectionError):
      check_collectd_mlab.assert_collectd_responds()