Esempio n. 1
0
def t5(factory):
    pretty = '%s t5' % __file__
    print(pretty)

    handover = factory.make_master('master')
    avail_1 = handover.list_available()

    # make some allocations
    c1 = RemoteBroker(handover.address, home=factory.HOME.path)
    h1, w1 = c1.get_resources({'type': 'handset'}, {'type': 'workspace'})
    avail_2 = handover.list_available()
    c2 = RemoteBroker(handover.address, home=factory.HOME.path)
    h2, r2 = c2.get_resources({'type': 'handset'}, {'type': 'relay'})
    avail_3 = handover.list_available()

    adoption, config, fdtx_path = handover.begin_handover()
    session = RemoteSession(h2.address, h2.authkey)
    try:
        session.crash()  # kill the second session during the handover
    except ConnectionClosed:
        pass
    takeover = factory.make_takeover('master', adoption, config, fdtx_path)
    handover.end_handover(1)

    result = takeover.list_available()
    if len(result) != len(avail_2):
        print('FAIL %s: wrong avail: %s != %s' % (pretty, result, avail_2))
        return False

    return True
Esempio n. 2
0
def t3(HOME, master, forwarder):
    pretty = '%s t3' % __file__
    print(pretty)

    # get local and remote resources
    h1 = forwarder.get_resources({'type': 'handset', 'pretty': 'mary'})
    h2 = forwarder.get_resources({'type': 'handset', 'pretty': 'mary'})

    # crash the remote session
    r2 = RemoteSession(h2.address, h2.authkey, timeout=h2.timeout)
    try:
        r2.crash()
    except ConnectionClosed:
        pass  # good
    except Exception, e:
        print('FAIL %s: unexpected exception: %s' % (pretty, str(e)))
        return False
Esempio n. 3
0
def t7(HOME, master, forwarder_a, forwarder_b):
    pretty = '%s t7' % __file__
    print(pretty)

    # get local and remote resources
    h1 = forwarder_b.get_resources({'type': 'handset', 'pretty': 'jane'})
    h2 = forwarder_b.get_resources({'type': 'handset', 'pretty': 'jane'})
    h3 = forwarder_b.get_resources({'type': 'handset', 'pretty': 'jane'})

    # crash the last session in the chain
    r3 = RemoteSession(h3.address, h3.authkey, timeout=h3.timeout)
    try:
        r3.crash()
    except ConnectionClosed:
        pass  # good
    except Exception, e:
        print('FAIL %s: unexpected exception: %s' % (pretty, str(e)))
        return False
Esempio n. 4
0
def t2():
    pretty = '%s t2' % __file__
    print(pretty)

    sock, port = find_free_port()
    sock.shutdown(socket.SHUT_RDWR)
    sock.close()
    for i in range(5):
        s = Session(port, 'password', ('', 1), None, logging=False)
        s.start()
        r = RemoteSession(('', port), 'password', timeout=1, optimist=True)
        r.stop(__async__=True)  # throw away the response
        try:
            s.join(1)
        except Exception, e:
            print('FAIL %s: session did not join' % pretty)
            s.terminate()
            return False
Esempio n. 5
0
def t4(s, r):
    pretty = '%s t4' % __file__
    print(pretty)

    # connect supervisor and fail authentication (no authkey given)
    try:
        r2 = RemoteSession(('', r.port), 'password')
    except Exception, e:
        print('FAIL %s: could not connect supervisor: %s' % (pretty, str(e)))
        return False
Esempio n. 6
0
def t13(HOME, r):
    pretty = '%s t13' % __file__
    print(pretty)

    r = RemoteBroker(r.address, home=HOME.path)
    h = r.get_resources({'type':'handset'})
    p = h.get_profile()
    s = RemoteSession(h.address, h.authkey)
    s.stop(__async__=True)

    ok = False
    for i in range(10):
        if p not in r.list_allocations_all():
            ok = True
            break
        time.sleep(1)
    if not ok:
        print('FAIL %s: handset still allocated' % pretty)
        return False

    return True
Esempio n. 7
0
def t13(factory):
    pretty = '%s t13' % __file__
    print(pretty)

    handover = factory.make_master('master')

    # make some sessions
    c1 = RemoteBroker(handover.address, home=factory.HOME.path)
    h1, w1 = c1.get_resources({'type': 'handset'}, {'type': 'workspace'})
    avail_2 = handover.list_available()
    c2 = RemoteBroker(handover.address, home=factory.HOME.path)
    h2, r2 = c2.get_resources({'type': 'handset'}, {'type': 'relay'})
    avail_3 = handover.list_available()

    adoption, config, fdtx_path = handover.begin_handover()
    takeover = factory.make_takeover('master', adoption, config, fdtx_path)
    handover.end_handover(1)

    # crash the sessions
    session = RemoteSession(h1.address, h1.authkey)
    try:
        session.crash()
    except ConnectionClosed:
        pass
    session = RemoteSession(h2.address, h2.authkey)
    try:
        session.crash()
    except ConnectionClosed:
        pass

    for i in range(10):  # wait until only one session remains, then close it
        authkeys = handover.get_session_authkeys()
        if len(authkeys) == 1:
            break
        time.sleep(0.3)

    # check that the handover sends its exit message when the last session is
    # closed
    try:
        handover.close_session(authkeys[0])
    except Exit, e:
        if str(e) != 'broker restarted. please reconnect':
            print('FAIL %s: wrong exit message: %s' % (pretty, str(e)))
            return False
Esempio n. 8
0
 def decorated_fn():
     sock, port = find_free_port()
     s = MockSession(port, 'password', ('', 1), sock, logging=False)
     s.start()
     # spin until session is fully up and accepting connections
     for i in range(10):
         try:
             BlockingConnection(('', port),
                                'password').connect(timeout=5)
             break
         except ConnectionRefused:
             time.sleep(0.1)
             continue
     result = fn(s, RemoteSession(('', port), 'password'))
     try:
         s.terminate()
         s.join()
     except:
         pass
     return result
Esempio n. 9
0
    class Client(Process):

        def close_fds(self, exclude):
            exclude.extend([self.args[1].w, self.args[2].r])
            Process.close_fds(self, exclude)

        def run(self, address, q1, q2, home):
            r2 = RemoteBroker(address, home=home)
            try: # take whatever handset is available
                w, d = r2.get_resource({'type':'workspace'}, {'type':'handset'})
            except Exception, e:
                print('FAIL %s: got no handset: %s' % (pretty, str(e)))
                return
            q1.put([ # use the queue to synchronize with parent the process
                WorkspaceProfile(w.get_profile()),
                HandsetProfile(d.get_profile())])
            q2.get() # wait for one sync message before stopping
            session = RemoteSession(w.address, w.authkey)
            session.stop(__async__=True)
            q1.put('stopped the session')
            while True:
                time.sleep(1)
Esempio n. 10
0
 def __init__(self, address, authkey, profile):
     if not profile['type'] == 'workspace':
         raise Exception('not a workspace profile: %s' % profile)
     RemoteSession.__init__(self, address, authkey, profile)
Esempio n. 11
0
 def __init__(self, address, authkey, profile):
     if not profile['type'] == 'beryllium':
         raise Exception('not a beryllium profile: %s' % profile)
     RemoteSession.__init__(self, address, authkey, profile)
Esempio n. 12
0
 def __init__(self, address, authkey, profile):
     if not profile['type'] == 'relay':
         raise Exception('not a relay profile: %s' % profile)
     RemoteSession.__init__(self, address, authkey, profile)
Esempio n. 13
0
 def __init__(self, address, authkey, profile):
     if not profile['type'] == 'powermeter':
         raise Exception('not a powermeter profile: %s' % profile)
     RemoteSession.__init__(self, address, authkey, profile)
Esempio n. 14
0
def t1():
    pretty = '%s t1' % __file__
    print(pretty)

    sock, port = find_free_port()
    sock.shutdown(socket.SHUT_RDWR)
    sock.close()
    try:
        s = Session(port, 'password', ('', 1), None, logging=False)
        s.start()
    except Exception, e:
        print('FAIL %s: failed to create Session: %s' % (pretty, str(e)))
        return

    # connect to the session and tell it to stop itself
    r = RemoteSession(('', port), 'password', timeout=1, optimist=True)
    r.stop(__async__=True)  # throw away the response
    try:
        s.join(1)
    except Exception, e:
        print('FAIL %s: session did not join' % pretty)
        s.terminate()
        return False
    return True


# start/stop sessions on the same listening port a couple of times to check that
# sockets get closed properly
def t2():
    pretty = '%s t2' % __file__
    print(pretty)