@classmethod
  def _NotifyUsingSocket(cls, cb, errcls):
    """Opens a Unix socket and waits for another program to connect.

    @type cb: callable
    @param cb: Callback to send socket name to client
    @type errcls: class
    @param errcls: Exception class to use for errors

    """

    # Using a temporary directory as there's no easy way to create temporary
    # sockets without writing a custom loop around tempfile.mktemp and
    # socket.bind

    socket_wrapper = TestSocketWrapper()
    sock, path = socket_wrapper.Create()

    cb(path)

    try:
      sock.settimeout(cls._CLIENT_CONNECT_TIMEOUT)
      (conn, _) = sock.accept()
    except socket.error, err:
      raise errcls("Client didn't connect in time (%s)" % err)
    finally:
      socket_wrapper.Destroy()

    # Wait for client to close
    try:
      try:
        # pylint: disable=E1101
        # Instance of '_socketobject' has no ... member
        conn.settimeout(cls._CLIENT_CONFIRM_TIMEOUT)
        conn.recv(1)
      except socket.error, err:
        raise errcls("Client failed to confirm notification (%s)" % err)
    finally:
      conn.close()
dataset/ETHPy150Open ganeti/ganeti/lib/cmdlib/test.py/LUTestJqueue._NotifyUsingSocket/original