def t15(factory): pretty = '%s t15' % __file__ print(pretty) ws_config = { 'root' : factory.HOME.path, 'env' : [], 'tools' : {}, 'flocker': { "ftp": { "password": "******", "store": "/srv/www/flocker", "port": 21, "timeout": 30, "user": "******" }, "host": "cnbjlx20050", "enable" : True, "http": { "doc-root": "/srv/www", "port": 80 } } } factory.write_config('workspace.json', json.dumps(ws_config)) sock, port = find_free_port() # set remote explicitly to avoid reading config from disk broker = Broker( ('',port), sock, remote={}, authkeys={'admin':None}, hsl_paths=[], home=factory.HOME.path ) broker.start() proc = psutil.Process(broker.pid) remote = RemoteBroker(address=('',port), home=factory.HOME.path) l = remote.list_available() # just to make sure the connection is up del remote # client disconnects itself # check the CPU utilization of the broker through it's PID result = True for i in range(10): if 'get_cpu_percent' in dir(proc): load = proc.get_cpu_percent() * psutil.NUM_CPUS else: load = proc.cpu_percent() * psutil.cpu_count() if load > 90.0: print('FAIL %s: runaway CPU load: %f' % (pretty, load)) result = False break time.sleep(0.3) broker.terminate() broker.join() return result
def t3(pretty, factory): factory.write_config('authkeys.json', setup.AUTHKEYS) b = factory.make_broker() client = RemoteBroker(b.address) admin = RemoteBroker(b.address,authkey='admin') # create a server with a couple of boards handover = factory.make_server() handover.set_boards([setup.BOARD_1,setup.BOARD_2,setup.BOARD_3]) # wait for added boards to become available in the broker ok = False wanted = RelayProfile(setup.RELAY_3) for i in range(10): if wanted in admin.list_available(): ok = True break time.sleep(0.3) if not ok: print('FAIL %s: boards not available' % pretty) return False # let the client allocate a relay and manipulate it to make sure it has # connected to the relay server relay = client.get({ 'type':'relay','circuits':['usb.pc.vcc','handset.battery'] }) relay.set_circuit('usb.pc.vcc', False) # hand over to the replacement server state = handover.begin_handover() takeover = factory.make_server(state['boards'], make_socket=False) takeover.set_boards([setup.BOARD_1,setup.BOARD_2,setup.BOARD_3]) handover.end_handover(__async__=True) try: relay.set_circuit('handset.battery', False) except AveException, e: print e.format_trace() print('FAIL %s: could not set battery circuit: %s' % (pretty, e)) return False
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
except Exception, e: print('FAIL %s: wait for boot_completed failed: %s' % (pretty, e)) return False if profile1 in master.list_available(): print('FAIL %s: handset available after reconnect' % pretty) return False # reconnect to master and verify the handsets become available again # (because they are reclaimed when the job drops the master) master = RemoteBroker(master.address, authkey=master.authkey, home=factory.HOME.path) ok = False for i in range(10): if profile1 not in master.list_available(): time.sleep(0.3) continue if profile2 not in master.list_available(): time.sleep(0.3) continue ok = True break if not ok: print('FAIL %s: yielded handset not listed as available' % pretty) return False return True # restart the master broker during ongoing state discovery.