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
def t4(factory): pretty = '%s t4' % __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() # hand over adoption, config, fdtx_path = handover.begin_handover() takeover = factory.make_takeover('master', adoption, config, fdtx_path) handover.end_handover(1) # check that availability is correct. stop the sessions started against the # handover and check that the resources become availabe in the takeover result = takeover.list_available() if len(result) != len(avail_3): print('FAIL %s: wrong avail 3: %s != %s' % (pretty, result, avail_3)) return False ok = False del (c2) for i in range(10): # allow some time for brokers to detect session death result = takeover.list_available() if len(result) == len(avail_2): ok = True break time.sleep(0.3) if not ok: print('FAIL %s: wrong avail 2: %s != %s' % (pretty, result, avail_2)) return False ok = False del (c1) for i in range(10): # allow some time for brokers to detect session death result = takeover.list_available() if len(result) == len(avail_1): ok = True break time.sleep(0.3) if not ok: print('FAIL %s: wrong avail 1: %s != %s' % (pretty, result, avail_2)) return False return True
def t2(HOME, master): pretty = '%s t2' % __file__ print(pretty) c1 = RemoteBroker(master.address, authkey=master.authkey, home=HOME.path) c1.get_resources({'type': 'handset'}, {'type': 'workspace'}) c2 = RemoteBroker(master.address, authkey=master.authkey, home=HOME.path) c2.get_resources({'type': 'handset'}, {'type': 'relay'}) try: s = master.serialize() except Exception, e: print('FAIL %s: trivial serialization failed: %s' % (pretty, str(e))) return False
def t9(factory): pretty = '%s t9' % __file__ print(pretty) handover = factory.make_master('master') client = RemoteBroker(handover.address, home=factory.HOME.path) # make first allocation h, w = client.get_resources({'type': 'handset'}, {'type': 'workspace'}) # hand over adoption, config, fdtx_path = handover.begin_handover() takeover = factory.make_takeover('master', adoption, config, fdtx_path) handover.end_handover(1) # make seconc allocation try: client.get({'type': 'handset'}) print('FAIL %s: second allocation did not fail' % pretty) return False except Restarting: pass # good except Exception, e: print('FAIL %s: wrong exception: %s' % (pretty, e)) return False
def t3(factory): pretty = '%s t3' % __file__ print(pretty) master = factory.make_master('master', []) slave = factory.make_share(master, 'slave', True) time.sleep(1) r1 = master.list_equipment() r2 = slave.list_equipment() wanted = r2.pop() client = RemoteBroker(master.address, home=factory.HOME.path) handset = client.get_resources(wanted) del client # drop connection to "crash" client. note that this would not # work if we had made the allocation with the master because it would not # get garbage collected until t3() returns. # check that wanted is available again from the master found = False for i in range(10): if master.list_available(wanted): found = True break time.sleep(0.3) if not found: print('FAIL %s: resource not available after job crash' % pretty) return False if wanted not in slave.list_available(): print('FAIL %s: resource not available from slave' % pretty) return False return True
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
def t16(HOME, r): pretty = '%s t16' % __file__ print(pretty) result = True for i in range(20): r2 = RemoteBroker(r.address, home=HOME.path) try: h = r2.get_resources({'type':'handset'}) except Exception, e: print('FAIL %s: iteration %d failed: %s' % (pretty, i, str(e))) result = False break
def t11(factory): pretty = '%s t11' % __file__ print(pretty) master = factory.make_master('master') share = factory.make_share(master, 'share') share.start_sharing() time.sleep(1) client = RemoteBroker(address=master.address, home=factory.HOME.path) h1 = client.get_resources({'type': 'handset', 'serial': 'share-1'}) h2 = client.get_resources({'type': 'handset', 'serial': 'master-1'}) a1 = master.list_available() # restart the master adoption, config, fdtx_path = master.begin_handover() takeover = factory.make_takeover('master', adoption, config, fdtx_path) master.end_handover(1) # connect to the new master and check the availability again master = RemoteBroker(address=master.address, home=factory.HOME.path) ok = False for i in range(10): a2 = master.list_available() if len(a2) == len(a1): ok = True break time.sleep(0.3) if not ok: print('FAIL %s: wrong availability: %s' % (pretty, a2)) return False for profile in a2: if 'serial' in profile and profile['serial'] == 'share-1': print('FAIL %s: busy equipment shared' % pretty) return False return True
def t10(factory): pretty = '%s t10' % __file__ print(pretty) master = factory.make_master('master') share = factory.make_share(master, 'share') share.start_sharing() time.sleep(1) client = RemoteBroker(address=master.address, home=factory.HOME.path) h = client.get_resources({'type': 'handset', 'serial': 'share-1'}) a1 = master.list_available() # restart the share adoption, config, fdtx_path = share.begin_handover() takeover = factory.make_takeover('share', adoption, config, fdtx_path) a2 = master.list_available() if len(a1) == len(a2): print('FAIL %s: shared resources still visible: %s' % (pretty, a2)) return False # finish the handover so that takeover can start accepting RPC's. then # check that the master sees all equipment except the one allocated share.end_handover(1) ok = False for i in range(10): a3 = master.list_available() if len(a3) == len(a1): ok = True break time.sleep(0.3) if not ok: print('FAIL %s: wrong availability: %s' % (pretty, a3)) return False for profile in a3: if 'serial' in profile and profile['serial'] == 'share-1': print('FAIL %s: busy equipment shared' % pretty) return False # finally check that the resource can still be manipulated try: p = h.get_profile() if p['serial'] != 'share-1': print('FAIL %s: wrong profile: %s' % (pretty, p)) return False except Exception, e: print('FAIL %s: unexpected error: %s' % (pretty, e)) return False
def t6(factory, h1, h2, r1): pretty = '%s t6' % __file__ print(pretty) h1p = h1.get_profile() h2p = h2.get_profile() # create a master and a share (only the share will see real equipment) hsl_paths = [h1p['sysfs_path'], h2p['sysfs_path']] handover = factory.make_master('master', hsl_paths=[]) # droppable connection: client = RemoteBroker(handover.address, home=factory.HOME.path) share = factory.make_share(handover, 'share', autoshare=True, hsl_paths=hsl_paths) try: wait_equipment(handover, [h1p, h2p]) except Timeout: print('FAIL %s: handsets not found in handover' % pretty) return False # allocate handset and save a profile handset = client.get_resources({ 'type': 'handset', 'serial': h1p['serial'] }) profile = HandsetProfile(handset.get_profile()) # stop the handover adoption, config, fdtx_path = handover.begin_handover() # stops listening # disconnect the handset while neither broker is listening for updates, # then drop the allocation entirely (disconnect from the handover). the # handset should show up as available in power state "boot_completed" in # the takeover r1.set_circuit('usb.pc.vcc', False) try: handset.wait_power_state('offline', 5) except Exception, e: print('FAIL %s: wait for offline failed: %s' % (pretty, e)) return False
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
def oob_client(address): r = RemoteBroker(address, home=factory.HOME.path) h, w = r.get_resources({'type': 'handset'}, {'type': 'workspace'}) while True: time.sleep(1)
def oob_client(address): r = RemoteBroker(address, home=factory.HOME.path) h, w = r.get_resources({'type': 'handset'}, {'type': 'workspace'}) w.run('sleep 2') # right, extremely busy, but it prevents other action
def oob_client(address): r = RemoteBroker(address, home=factory.HOME.path) h, w = r.get_resources({'type': 'handset'}, {'type': 'workspace'}) w.run('sleep 3') # right, extremely busy, but it prevents other action while True: time.sleep(1) # don't let client die and loose all resources