コード例 #1
0
def exec_test_deferred(fun,
                       params,
                       protocol=None,
                       timeout=None,
                       make_conn=True):
    colourer = None

    if 'SALUT_TEST_REAL_AVAHI' not in os.environ:
        ensure_avahi_is_running()

    if sys.stdout.isatty() or 'CHECK_FORCE_COLOR' in os.environ:
        colourer = servicetest.install_colourer()

    bus = dbus.SessionBus()

    queue = servicetest.IteratingEventQueue(timeout)
    queue.verbose = (os.environ.get('CHECK_TWISTED_VERBOSE', '') != ''
                     or '-v' in sys.argv)

    if make_conn:
        try:
            conn = make_connection(bus, queue.append, params)
        except Exception, e:
            # This is normally because the connection's still kicking around
            # on the bus from a previous test. Let's bail out unceremoniously.
            print e
            os._exit(1)
コード例 #2
0
def exec_test_deferred(fun, params, protocol=None, timeout=None,
                        authenticator=None):
    # hack to ease debugging
    domish.Element.__repr__ = domish.Element.toXml
    colourer = None

    if sys.stdout.isatty() or 'CHECK_FORCE_COLOR' in os.environ:
        colourer = servicetest.install_colourer()

    queue = servicetest.IteratingEventQueue(timeout)
    queue.verbose = (
        os.environ.get('CHECK_TWISTED_VERBOSE', '') != ''
        or '-v' in sys.argv)

    bus = dbus.SessionBus()
    conn = make_connection(bus, queue.append, params)
    resource = params.get('resource') if params is not None else None
    (stream, port) = make_stream(queue.append, protocol=protocol,
        authenticator=authenticator, resource=resource)

    error = None

    try:
        fun(queue, bus, conn, stream)
    except Exception, e:
        traceback.print_exc()
        error = e
def exec_test_deferred (fun, params, protocol=None, timeout=None,
        make_conn=True):
    colourer = None

    if 'SALUT_TEST_REAL_AVAHI' not in os.environ:
        ensure_avahi_is_running()

    if sys.stdout.isatty() or 'CHECK_FORCE_COLOR' in os.environ:
        colourer = servicetest.install_colourer()

    bus = dbus.SessionBus()

    queue = servicetest.IteratingEventQueue(timeout)
    queue.verbose = (
        os.environ.get('CHECK_TWISTED_VERBOSE', '') != ''
        or '-v' in sys.argv)

    if make_conn:
        try:
            conn = make_connection(bus, queue.append, params)
        except Exception, e:
            # This is normally because the connection's still kicking around
            # on the bus from a previous test. Let's bail out unceremoniously.
            print e
            os._exit(1)
コード例 #4
0
def exec_test_deferred(fun,
                       params,
                       protocol=None,
                       timeout=None,
                       authenticator=None,
                       num_instances=1,
                       do_connect=True,
                       make_connection_func=make_connection,
                       expect_connected_func=expect_connected):
    # hack to ease debugging
    domish.Element.__repr__ = element_repr
    colourer = None

    if sys.stdout.isatty() or 'CHECK_FORCE_COLOR' in os.environ:
        colourer = servicetest.install_colourer()

    try:
        bus = dbus.SessionBus()
    except dbus.exceptions.DBusException as e:
        print e
        os._exit(1)

    queue = servicetest.IteratingEventQueue(timeout)
    queue.verbose = (os.environ.get('CHECK_TWISTED_VERBOSE', '') != ''
                     or '-v' in sys.argv)

    conns = []
    jids = []
    streams = []
    resource = params.get('resource') if params is not None else None
    for i in range(0, num_instances):
        if i == 0:
            suffix = ''
        else:
            suffix = str(i)

        try:
            (conn, jid) = make_connection_func(bus, queue.append, params,
                                               suffix)
        except Exception, e:
            # Crap. This is normally because the connection's still kicking
            # around on the bus. Let's bin any connections we *did* manage to
            # get going and then bail out unceremoniously.
            print e

            for conn in conns:
                conn.Disconnect()

            os._exit(1)

        conns.append(conn)
        jids.append(jid)
        streams.append(
            make_stream(queue.append,
                        protocol=protocol,
                        authenticator=authenticator,
                        resource=resource,
                        suffix=suffix))
コード例 #5
0
def exec_test_deferred(fun, params, protocol=None, timeout=None,
                        authenticator=None, num_instances=1,
                        do_connect=True,
                        make_connection_func=make_connection,
                        expect_connected_func=expect_connected):
    # hack to ease debugging
    domish.Element.__repr__ = element_repr
    colourer = None

    if sys.stdout.isatty() or 'CHECK_FORCE_COLOR' in os.environ:
        colourer = servicetest.install_colourer()

    try:
        bus = dbus.SessionBus()
    except dbus.exceptions.DBusException as e:
        print e
        os._exit(1)

    queue = servicetest.IteratingEventQueue(timeout)
    queue.verbose = (
        os.environ.get('CHECK_TWISTED_VERBOSE', '') != ''
        or '-v' in sys.argv)

    conns = []
    jids = []
    streams = []
    resource = params.get('resource') if params is not None else None
    for i in range(0, num_instances):
        if i == 0:
            suffix = ''
        else:
            suffix = str(i)

        try:
            (conn, jid) = make_connection_func(bus, queue.append, params, suffix)
        except Exception, e:
            # Crap. This is normally because the connection's still kicking
            # around on the bus. Let's bin any connections we *did* manage to
            # get going and then bail out unceremoniously.
            print e

            for conn in conns:
                conn.Disconnect()

            os._exit(1)

        conns.append(conn)
        jids.append(jid)
        streams.append(make_stream(queue.append, protocol=protocol,
                                   authenticator=authenticator,
                                   resource=resource, suffix=suffix))
コード例 #6
0
def exec_test_deferred(fun,
                       params,
                       protocol=None,
                       timeout=None,
                       authenticator=None,
                       num_instances=1,
                       do_connect=True,
                       make_connection_func=make_connection,
                       expect_connected_func=expect_connected):
    # hack to ease debugging
    domish.Element.__repr__ = element_repr
    colourer = None

    if sys.stdout.isatty() or 'CHECK_FORCE_COLOR' in os.environ:
        colourer = servicetest.install_colourer()

    try:
        bus = dbus.SessionBus()
    except dbus.exceptions.DBusException as e:
        print(e)
        os._exit(1)

    queue = servicetest.IteratingEventQueue(timeout)
    queue.verbose = (os.environ.get('CHECK_TWISTED_VERBOSE', '') != ''
                     or '-v' in sys.argv)

    port = os.environ.get('CHECK_TWISTED_PORT', '')
    if port != '':
        port = dbus.UInt32(port)
    else:
        port = dbus.UInt32(4242)
    if params:
        params = dict(params)
        # This means caller wants server to use non-standard port and hence
        # connection to fail. Let's move the client by large margin off to
        # prevent it hitting one of the instances spawned by meson
        if 'port' in params and params['port'] != 4242:
            params['port'] = port
            port = port - 1000
        else:
            params['port'] = port
    else:
        params = {'port': port}
    conns = []
    jids = []
    streams = []
    resource = params.get('resource') if params is not None else None
    for i in range(0, num_instances):
        if i == 0:
            suffix = ''
        else:
            suffix = str(i)

        try:
            (conn, jid) = make_connection_func(bus, queue.append, params,
                                               suffix)
        except Exception as e:
            # Crap. This is normally because the connection's still kicking
            # around on the bus. Let's bin any connections we *did* manage to
            # get going and then bail out unceremoniously.
            print(e)

            for conn in conns:
                conn.Disconnect()

            os._exit(1)

        conns.append(conn)
        jids.append(jid)
        streams.append(
            make_stream(queue.append,
                        protocol=protocol,
                        authenticator=authenticator,
                        resource=resource,
                        suffix=suffix))

    factory = StreamFactory(streams, jids)
    port = reactor.listenTCP(port, factory, interface='localhost')

    def signal_receiver(*args, **kw):
        if kw['path'] == '/org/freedesktop/DBus' and \
                kw['member'] == 'NameOwnerChanged':
            bus_name, old_name, new_name = args
            if new_name == '':
                for i, conn in enumerate(conns):
                    stream = streams[i]
                    jid = jids[i]
                    if conn._requested_bus_name == bus_name:
                        factory.lost_presence(stream, jid)
                        break
        queue.append(
            Event('dbus-signal',
                  path=unwrap(kw['path']),
                  signal=kw['member'],
                  args=[unwrap(arg) for arg in args],
                  interface=kw['interface']))

    match_all_signals = bus.add_signal_receiver(
        signal_receiver,
        None,  # signal name
        None,  # interface
        None,
        path_keyword='path',
        member_keyword='member',
        interface_keyword='interface',
        byte_arrays=True)

    error = None

    try:
        if do_connect:
            for conn in conns:
                conn.Connect()
                expect_connected_func(queue)

        if len(conns) == 1:
            fun(queue, bus, conns[0], streams[0])
        else:
            fun(queue, bus, conns, streams)
    except Exception as e:
        traceback.print_exc()
        error = e
        queue.verbose = False

    if colourer:
        sys.stdout = colourer.fh

    d = port.stopListening()

    # Does the Connection object still exist?
    for i, conn in enumerate(conns):
        if not bus.name_has_owner(conn.object.bus_name):
            # Connection has already been disconnected and destroyed
            continue
        try:
            if conn.Properties.Get(cs.CONN,
                                   'Status') == cs.CONN_STATUS_CONNECTED:
                # Connection is connected, properly disconnect it
                disconnect_conn(queue, conn, streams[i])
            else:
                # Connection is not connected, call Disconnect() to destroy it
                conn.Disconnect()
        except dbus.DBusException as e:
            pass
        except Exception as e:
            traceback.print_exc()
            error = e

        try:
            conn.Disconnect()
            raise AssertionError("Connection didn't disappear; "
                                 "all subsequent tests will probably fail")
        except dbus.DBusException as e:
            pass
        except Exception as e:
            traceback.print_exc()
            error = e

    match_all_signals.remove()

    if error is None:
        d.addBoth((lambda *args: reactor.crash()))
    else:
        # please ignore the POSIX behind the curtain
        d.addBoth((lambda *args: os._exit(1)))