def sendControlMessage(stage, s_conf, msg): drainSocketIncoming(s_conf) ntries = 8 while True: if ntries <= 0: sys.stderr.write('%s: cannot configure tested process\n' \ % (stage,)) raise ControlTimeoutError('timeout waiting for control response') ntries -= 1 s_conf.sendto(msg, ('127.0.0.1', NMON_CTL_PORT)) s_conf.settimeout(1.0) try: resp, respaddr = s_conf.recvfrom(65535) print 'resplen =', len(resp) print 'respaddr =', respaddr hexdump(resp) if resp[0:8] != 'MMCS.ACR': print 'Weird response (bad signature), ignoring' continue if resp[8:50] != msg[8:50]: print 'Weird response (not to my request), ignoring' continue break except Exception, e: print 'Exception', e
def waitForDataMessage(stage, s_data, cookie): drainSocketIncoming(s_data) ntries = 8 while True: if ntries <= 0: sys.stderr.write('%s: timeout' % (stage,)) raise RuntimeError('test failed') ntries -= 1 s_data.settimeout(5.0) msg, msgaddr = s_data.recvfrom(65535) print 'msglen = ', len(msg) print 'msgaddr =', msgaddr hexdump(msg[0:54]) if not msg.startswith('MMCS.NAG'): print 'Unknown message, retrying' continue if len(msg) < 54: print 'Too short message, retrying' continue rck = struct.unpack('>L', msg[38:42])[0] if rck != cookie: print 'Invalid cookie (wanted %s, see %s), retrying' \ % (cookie, rck,) continue return msg
def sendControlMessage(stage, s_conf, msg): drainSocketIncoming(s_conf) ntries = 5 while True: if ntries <= 0: sys.stderr.write('FATAL: %s: cannot configure tested process\n' \ % (stage,)) raise RuntimeError('test failed') ntries -= 1 s_conf.sendto(msg, ('127.0.0.1', NMON_CTL_PORT)) s_conf.settimeout(2.0) try: resp, respaddr = s_conf.recvfrom(65535) print 'resplen =', len(resp) print 'respaddr =', respaddr hexdump(resp) if resp[0:8] != 'MMCS.ACR': print 'Weird response, ignoring' continue break except Exception, e: print 'Exception', e