def runTest(self): install_lighttpd(wan) wan.sendline('/etc/init.d/lighttpd start') wan.expect(prompt) # Wan device: Create small file in web dir fname = 'small.txt' cmd = '\nhead -c 10000 /dev/urandom > /var/www/%s' % fname wan.sendline(cmd) wan.expect(prompt) # Lan Device: download small file a lot # TODO: this is actually a 404 for lighthttpd config issues? url = 'http://%s/%s' % (wan.gw, fname) # Start CPU monitor board.collect_stats(stats=['mpstat']) # Lan Device: download small file a lot lan.sendline('\nab -dn %s -c %s %s' % (self.num_conn, self.concurrency, url)) lan.expect('Benchmarking', timeout=5) timeout = 0.05 * self.num_conn if 0 != lan.expect([ 'Requests per second:\s+(\d+)', 'apr_socket_recv: Connection reset by peer' ], timeout=timeout): raise Exception("ab failed to run") self.reqs_per_sec = int(lan.match.group(1)) lan.expect(prompt) self.recover()
def runTest(self): num_conn = 5000 # Wan device: Create small file in web dir fname = 'small.txt' cmd = '\nhead -c 10000 /dev/urandom > /var/www/%s' % fname wan.sendline(cmd) wan.expect(prompt) # Lan Device: download small file a lot concurrency = 25 url = 'http://192.168.0.1/%s' % fname # Start CPU monitor board.sendline('\nmpstat -P ALL 10000 1') # Lan Device: download small file a lot lan.sendline('\nab -dn %s -c %s %s' % (num_conn, concurrency, url)) lan.expect('Benchmarking', timeout=5) lan.expect('Requests per second:\s+(\d+)') reqs_per_sec = int(lan.match.group(1)) lan.expect(prompt) # Stop CPU monitor board.sendcontrol('c') board.expect('Average:\s+all(\s+[0-9]+.[0-9]+){10}\r\n') idle_cpu = float(board.match.group(1)) avg_cpu = 100 - float(idle_cpu) board.expect(prompt) msg = "ApacheBench measured %s connections/second, CPU use = %s%%." % ( reqs_per_sec, avg_cpu) self.result_message = msg time.sleep(5) # Give router a few seconds to recover
def wan_setup(self): super(NetperfTest, self).wan_setup() install_netperf(wan) lib.common.test_msg("Starting netserver on wan...") wan.sendline("kill -9 `pidof netserver`") wan.sendline('/usr/bin/netserver') wan.expect("Starting netserver with host")
def startSingleUDP(self, mintime=1, maxtime=60): while True: random_ip = fake_generator.ipv4() random_port = randint(1024, 65535) if ipaddress.ip_address(random_ip.decode()) not in self.bad_nets: if (ipaddress.ip_address(random_ip.decode()), random_port) not in self.all_ips: break else: print ("Skipping ip addr: %s" % random_ip) print("Connecting to %s:%s" % (random_ip, random_port)) self.all_ips.append((random_ip, random_port)) # start listners wan.sendline('ip addr add %s/32 dev eth1' % random_ip) wan.expect(prompt) random_rate = randint(1,1024) random_size = randint(int(1*random_rate*mintime), int(1024*random_rate*maxtime)) wan.sendline("nohup socat UDP4-RECVFROM:%s,bind=%s system:'(echo -n d1:ad2:id20:; head /dev/zero) | pv -L %sk' &" % (random_port, random_ip, random_rate)) wan.expect(prompt) args = (random_size, random_rate, random_ip, random_port) lan.sendline("nohup socat system:'(echo -n d1:ad2:id20:; head -c %s /dev/zero) | pv -L %sk' UDP4-SENDTO:%s:%s &" % args) lan.expect(prompt) self.all_conns.append(args) # size, rate, ip, port return args
def runTest(self): lib.common.test_msg("Starting netserver on wan...") wan.sendline('/usr/bin/netserver') wan.expect("Starting netserver with host") run_netperf_tcp(device=lan, run_time=15, pkt_size=1024) wan.sendline("kill -9 `pidof netserver`") wan.expect(prompt)
def recover(self): wan.sendcontrol('c') wan.expect(prompt) wan.sendline('killall -9 socat pv') wan.expect_exact('killall -9 socat pv') wan.expect(prompt) for d in [wan, lan]: d.sendcontrol('c') d.expect(prompt) d.sendline('pgrep -f d1:ad2:id20') d.expect_exact('pgrep -f d1:ad2:id20') d.expect(prompt) d.sendline('pkill -9 -f d1:ad2:id20') d.expect_exact('pkill -9 -f d1:ad2:id20') d.expect(prompt) d.sendline('killall -9 socat') d.expect_exact('killall -9 socat') d.expect(prompt) for ip, port in self.all_ips: self.cleanup_ip(ip) # this needs to be here because we need to make sure mpstat is cleaned up board.parse_stats(dict_to_log=self.logged) print("mpstat cpu usage = %s" % self.logged['mpstat']) self.result_message = "BitTorrent test with %s connections, cpu usage = %s" % ( self.conns, self.logged['mpstat'])
def runTest(self): num_conn = 5000 # Wan device: Create small file in web dir fname = "small.txt" cmd = "\nhead -c 10000 /dev/urandom > /var/www/%s" % fname wan.sendline(cmd) wan.expect(prompt) # Lan Device: download small file a lot concurrency = 25 url = "http://192.168.0.1/%s" % fname # Start CPU monitor board.sendline("\nmpstat -P ALL 10000 1") # Lan Device: download small file a lot lan.sendline("\nab -dn %s -c %s %s" % (num_conn, concurrency, url)) lan.expect("Benchmarking", timeout=5) lan.expect("Requests per second:\s+(\d+)") reqs_per_sec = int(lan.match.group(1)) lan.expect(prompt) # Stop CPU monitor board.sendcontrol("c") board.expect("Average:\s+all(\s+[0-9]+.[0-9]+){10}\r\n") idle_cpu = float(board.match.group(1)) avg_cpu = 100 - float(idle_cpu) board.expect(prompt) msg = "ApacheBench measured %s connections/second, CPU use = %s%%." % (reqs_per_sec, avg_cpu) self.result_message = msg time.sleep(5) # Give router a few seconds to recover
def cleanup_ip(self, ip): wan.sendline('ip addr del %s/32 dev %s' % (ip, wan.iface_dut)) wan.expect_exact('ip addr del %s/32 dev %s' % (ip, wan.iface_dut)) wan.expect(prompt) wan.sendline('pkill -9 -f socat.*bind=%s' % ip) wan.expect(prompt) lan.sendline('pkill -9 -f socat.*%s:%s' % (self.socat_send, ip)) lan.expect(prompt)
def cleanup_ip(self, ip): wan.sendline('ip addr del %s/32 dev eth1' % ip) wan.expect_exact('ip addr del %s/32 dev eth1' % ip) wan.expect(prompt) wan.sendline('pkill -9 -f socat.*bind=%s' % ip) wan.expect(prompt) lan.sendline('pkill -9 -f socat.*UDP4-SENDTO:%s' % ip) lan.expect(prompt)
def recover(self): for ip in self.all_ips: wan.sendline('ip addr del %s/32 dev eth1' % ip) wan.expect(prompt) wan.sendline('killall -9 nc') wan.expect(prompt) lan.sendline('killall -9 nc') lan.expect(prompt)
def runTest(self): # WAN Device: create large file in web directory fname = "/var/www/20mb.txt" wan.sendline('\n[ -e "%s" ] || head -c 20971520 /dev/urandom > %s' % (fname, fname)) wan.expect("/var") wan.expect(prompt) # LAN Device: download the file lan.sendline("\ncurl -m 57 -g -6 http://[5aaa::6]/20mb.txt > /dev/null") lan.expect("Total", timeout=5) i = lan.expect(["couldn't connect", "20.0M 100 20.0M"], timeout=60) if i == 0: assert False lan.expect(prompt)
def runTest(self): # WAN Device: create large file in web directory fname = "/var/www/20mb.txt" wan.sendline('\n[ -e "%s" ] || head -c 20971520 /dev/urandom > %s' % (fname, fname)) wan.expect('/var') wan.expect(prompt) # LAN Device: download the file lan.sendline( '\ncurl -m 57 -g -6 http://[5aaa::6]/20mb.txt > /dev/null') lan.expect('Total', timeout=5) i = lan.expect(["couldn't connect", '20.0M 100 20.0M'], timeout=60) if i == 0: assert False lan.expect(prompt)
def runTest(self): if not wan: msg = 'No WAN Device defined, skipping copy file to WAN test.' lib.common.test_msg(msg) self.skipTest(msg) if not hasattr(wan, 'ipaddr'): msg = 'WAN device is not running ssh server, can\'t copy with this function' lib.common.test_msg(msg) self.skipTest(msg) text_file = tempfile.NamedTemporaryFile() self.fname = fname = text_file.name letters = string.ascii_letters fcontent = ''.join(random.choice(letters) for i in range(50)) text_file.write(fcontent) text_file.flush() fmd5 = hashlib.md5(open(fname,'rb').read()).hexdigest() print("File orginal md5sum: %s"% fmd5) wan_ip = wan.get_interface_ipaddr("eth0") cmd = "cat %s | ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -x %s@%s \"cat - > %s\""\ % (fname, wan.username, wan_ip, fname) # this must fail as the command does not echo the filename try: common.copy_file_to_server(cmd, wan.password, "/tmp") except: print("Copy failed as expected") pass cmd = "cat %s | ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -x %s@%s \"cat - > %s; echo %s\""\ % (fname, wan.username, wan_ip, fname, fname) # this should pass try: common.copy_file_to_server(cmd, wan.password, "/tmp") except: assert 0,"copy_file_to_server failed, Test failed!!!!" # is the destination file identical to the source file wan.sendline("md5sum %s"% fname) wan.expect(fmd5) wan.expect(wan.prompt) print("Test passed")
def runTest(self): wan_ip = wan.get_interface_ipaddr(wan.iface_dut) wan.sendline('iperf -s -l 1M -w 1M') wan.expect('Server listening on ') board.collect_stats(stats=['mpstat']) time = 10 cmd = "iperf -R -c %s -P %s -t 10 -N -w 1M -l 1M | grep SUM" # prime the pipes... lan.sendline(cmd % (wan_ip, 4)) lan.expect(prompt) prev_con = 0 prev_failed = 0 for con_conn in range(32, 513, 16): try: tstart = datetime.now() lan.sendline(cmd % (wan_ip, con_conn)) failed_cons = 0 while (datetime.now() - tstart).seconds < (time * 2): timeout = (time * 2) - (datetime.now() - tstart).seconds if 0 == lan.expect( ['write failed: Connection reset by peer'] + prompt, timeout=timeout): failed_cons += 1 else: break print_bold("For iperf with %s connections, %s failed...." % (con_conn, failed_cons)) lan.expect('.*') wan.expect('.*') board.touch() prev_conn = con_conn prev_failed = failed_cons if con_conn == 512: self.result_message = "iPerf Concurrent passed 512 connections (failed conns = %s)" % failed_cons except: self.result_message = "iPerf Concurrent Connections failed entirely at %s (failed conns = %s)" % ( prev_conn, prev_failed) break print(self.result_message) self.recover()
def runTest(self): super(NetperfUdpTest, self).runTest() self.run_netperf(lan, "192.168.0.1 -c -C -l 30 -t UDP_STREAM -- -m 1460 -M 1460") # setup port forwarding to lan netperf server lan_priv_ip = lan.get_interface_ipaddr("eth1") board.uci_forward_traffic_redirect("tcp", "12865", lan_priv_ip) # setup port for data socket separate from control port board.uci_forward_traffic_redirect("udp", "12866", lan_priv_ip) wan_ip = board.get_interface_ipaddr(board.wan_iface) # send at router ip, which will forward to lan client wan.sendline('') wan.expect(prompt) self.run_netperf(wan, wan_ip, "-c -C -l 30 -t UDP_STREAM -- -P ,12866 -m 1460 -M 1460")
def recover(self): lan.sendcontrol('c') lan.expect(prompt) lan.sendline('pkill -9 -f hping3') lan.expect_exact('pkill -9 -f hping3') lan.expect(prompt) wan.sendcontrol('c') wan.expect(prompt) wan.sendline('pkill -9 -f nc ') wan.expect_exact('pkill -9 -f nc') wan.expect(prompt) board.parse_stats(dict_to_log=self.logged) args = (self.conn_rate, self.max_conns, self.logged['mpstat']) self.result_message = "hping3 udp firewall test, conn_rate = %s, max_conns = %s, cpu usage = %.2f" % args
def runTest(self): installers.install_iperf3(wan) installers.install_iperf3(self.client) wan.sendline('iperf3 -s -p %s' % self.server_port) wan.expect( '-----------------------------------------------------------') wan.expect( '-----------------------------------------------------------') if self.target_ip == None: self.target_ip = wan.gw board.collect_stats(stats=['mpstat']) self.client.sendline( 'iperf3 %s -c %s -P5 -t %s -i 0 -p %s' % (self.opts, self.target_ip, self.time, self.server_port)) self.client.expect(prompt, timeout=self.time + 10) sender = re.findall('SUM.*Bytes\s*(.*/sec).*sender', self.client.before)[-1] if 'Mbits' in sender: s_rate = float(sender.split()[0]) elif 'Kbits' in sender: s_rate = float(sender.split()[0]) / 1024 elif 'Gbits' in sender: s_rate = float(sender.split()[0]) * 1024 else: raise Exception("Unknown rate in sender results") recv = re.findall('SUM.*Bytes\s*(.*/sec).*receiver', self.client.before)[-1] if 'Mbits' in recv: r_rate = float(recv.split()[0]) elif 'Kbits' in recv: r_rate = float(recv.split()[0]) / 1024 elif 'Gbits' in recv: r_rate = float(recv.split()[0]) * 1024 else: raise Exception("Unknown rate in recv results") self.logged['s_rate'] = s_rate self.logged['r_rate'] = r_rate self.recovery()
def startSingleFlow(self, mintime=1, maxtime=60): while True: random_ip = fake_generator.ipv4() random_port = randint(1024, 65535) if not ipaddress.ip_address(random_ip.decode()).is_private: if (ipaddress.ip_address(random_ip.decode()), random_port) not in self.all_ips: break else: print("Skipping ip addr: %s" % random_ip) print("Connecting to %s:%s" % (random_ip, random_port)) self.all_ips.append((random_ip, random_port)) # start listners wan.sendline('ip addr add %s/32 dev %s' % (random_ip, wan.iface_dut)) wan.expect(prompt) random_rate = randint(1, 1024) random_size = randint(int(1 * random_rate * mintime), int(1024 * random_rate * maxtime)) args = (self.socat_recv, random_port, random_ip, self.payload, random_rate) wan.sendline( "nohup socat %s:%s,bind=%s system:'(echo -n %s; head /dev/zero) | pv -L %sk' &" % args) print( "nohup socat %s:%s,bind=%s system:'(echo -n %s; head /dev/zero) | pv -L %sk' &" % args) wan.expect(prompt) args = (self.payload, random_size, random_rate, self.socat_send, random_ip, random_port) lan.sendline( "nohup socat system:'(echo -n %s; head -c %s /dev/zero) | pv -L %sk' %s:%s:%s &" % args) print( "nohup socat system:'(echo -n %s; head -c %s /dev/zero) | pv -L %sk' %s:%s:%s &" % args) lan.expect(prompt) self.all_conns.append( (random_size, random_rate, random_ip, random_port)) return (random_size, random_rate, random_ip, random_port)
def runTest(self): # setup port forwarding to lan netperf server lan_priv_ip = lan.get_interface_ipaddr("eth1") board.uci_forward_traffic_redirect("tcp", "12865", lan_priv_ip) # setup port for data socket separate from control port board.uci_forward_traffic_redirect("tcp", "12866", lan_priv_ip) wan_ip = board.get_interface_ipaddr(board.wan_iface) # send at router ip, which will forward to lan client wan.sendline('') wan.expect(prompt) board.sendline('mpstat -P ALL 30 1') speed = self.run_netperf(wan, wan_ip, "-c -C -l 30 -t TCP_STREAM -- -P ,12866") board.expect('Average.*idle\r\nAverage:\s+all(\s+[0-9]+.[0-9]+){10}\r\n') idle_cpu = float(board.match.group(1)) avg_cpu = 100 - float(idle_cpu) lib.common.test_msg("Average cpu usage was %s" % avg_cpu) self.result_message = "Setup NetperfReverse and Ran Throughput (Speed = %s 10^6bits/sec, CPU = %s)" % (speed, avg_cpu)
def runTest(self): super(NetperfUdpTest, self).runTest() self.run_netperf( lan, "192.168.0.1 -c -C -l 30 -t UDP_STREAM -- -m 1460 -M 1460") # setup port forwarding to lan netperf server lan_priv_ip = lan.get_interface_ipaddr(lan.iface_dut) board.uci_forward_traffic_redirect("tcp", "12865", lan_priv_ip) # setup port for data socket separate from control port board.uci_forward_traffic_redirect("udp", "12866", lan_priv_ip) wan_ip = board.get_interface_ipaddr(board.wan_iface) # send at router ip, which will forward to lan client wan.sendline('') wan.expect(prompt) self.run_netperf( wan, wan_ip, "-c -C -l 30 -t UDP_STREAM -- -P ,12866 -m 1460 -M 1460")
def runTest(self): #lan.sendline('apt-get update && apt-get -o Dpkg::Options::="--force-confnew" -y install socat') #lan.expect(prompt) self.all_ips = [] # TODO: query interfaces but this is OK for now bad_nets = list(ipaddress.ip_network(u"192.168.0.0/24")) + \ list(ipaddress.ip_network(u"192.168.1.0/24")) + \ list(ipaddress.ip_network(u"10.200.150.0/24")) for i in range(1000): while True: random_ip = fake_generator.ipv4() if ipaddress.ip_address(random_ip.decode()) not in bad_nets: if ipaddress.ip_address( random_ip.decode()) not in self.all_ips: break else: print("Skipping ip addr: %s" % random_ip) random_port = random.randint(1024, 65535) print("Connecting to %s:%s" % (random_ip, random_port)) self.all_ips.append(random_ip) # start listners wan.sendline('ip addr add %s/32 dev eth1' % random_ip) wan.expect(prompt) # this listens on this port on all ips, so we probably want unique ports too wan.sendline('nc -w5 -ulp %s > /dev/null &' % random_port) args = (random.randint(64, 1073741824), random_ip, random_port) lan.sendline( '(echo d1:ad2:id20:; head -c %s < /dev/urandom) | nc -u %s %s &' % args) lan.expect(prompt) lan.sendline('wait', timeout=120) lan.expect(prompt) self.recover()
def runTest(self): installers.install_iperf3(wan) installers.install_iperf3(lan) wan.sendline('iperf3 -s -p %s' % self.server_port) wan.expect( '-----------------------------------------------------------') wan.expect( '-----------------------------------------------------------') lan.sendline('iperf3 %s -c %s -P5 -t %s -i 0 -p %s' % (self.opts, wan.gw, self.time, self.server_port)) lan.expect(prompt, timeout=self.time + 10) sender = re.findall('SUM.*Bytes\s*(.*/sec).*sender', lan.before)[-1] if 'Mbits' in sender: s_rate = float(sender.split()[0]) elif 'Kbits' in sender: s_rate = float(sender.split()[0]) / 1024 elif 'Gbits' in sender: s_rate = float(sender.split()[0]) * 1024 else: raise Exception("Unknown rate in sender results") recv = re.findall('SUM.*Bytes\s*(.*/sec).*receiver', lan.before)[-1] if 'Mbits' in recv: r_rate = float(recv.split()[0]) elif 'Kbits' in recv: r_rate = float(recv.split()[0]) / 1024 elif 'Gbits' in recv: r_rate = float(recv.split()[0]) * 1024 else: raise Exception("Unknown rate in recv results") self.result_message = "Sender rate = %s MBits/sec, Receiver rate = %s Mbits/sec\n" % ( s_rate, r_rate) self.logged['s_rate'] = s_rate self.logged['r_rate'] = r_rate self.recovery()
def recover(self): if board.has_cmts and wan.wan_cmts_provisioner: # TODO: there are more missing ones (see above) wan.sendline('ip route del 200.0.0.0/8 via 192.168.3.2') wan.expect(prompt) if hasattr(self, 'results'): r = self.results.get(self.job_id) if r.status == "running": self.results.stop(self.job_id) # TODO: full recovery... for d in [wan, lan]: d.sendline('ifconfig %s up' % d.iface_dut) d.expect(prompt) # make sure board is back in a sane state board.sendcontrol('c') board.sendline() if 0 != board.expect([pexpect.TIMEOUT] + board.uprompt, timeout=5): board.reset() board.wait_for_linux()
def recover(self): wan.sendcontrol('c') wan.expect(prompt) wan.sendline('killall -9 socat pv') wan.expect_exact('killall -9 socat pv') wan.expect(prompt) for d in [wan, lan]: d.sendcontrol('c') d.expect(prompt) d.sendline('pgrep -f d1:ad2:id20') d.expect_exact('pgrep -f d1:ad2:id20') d.expect(prompt) d.sendline('pkill -9 -f d1:ad2:id20') d.expect_exact('pkill -9 -f d1:ad2:id20') d.expect(prompt) d.sendline('killall -9 socat') d.expect_exact('killall -9 socat') d.expect(prompt) for ip, port in self.all_ips: self.cleanup_ip(ip)
def runTest(self): # setup port forwarding to lan netperf server lan_priv_ip = lan.get_interface_ipaddr(lan.iface_dut) board.uci_forward_traffic_redirect("tcp", "12865", lan_priv_ip) # setup port for data socket separate from control port board.uci_forward_traffic_redirect("tcp", "12866", lan_priv_ip) wan_ip = board.get_interface_ipaddr(board.wan_iface) # send at router ip, which will forward to lan client wan.sendline('') wan.expect(prompt) board.sendline('mpstat -P ALL 30 1') speed = self.run_netperf(wan, wan_ip, "-c -C -l 30 -t TCP_STREAM -- -P ,12866") board.expect( 'Average.*idle\r\nAverage:\s+all(\s+[0-9]+.[0-9]+){10}\r\n') idle_cpu = float(board.match.group(1)) avg_cpu = 100 - float(idle_cpu) lib.common.test_msg("Average cpu usage was %s" % avg_cpu) self.result_message = "Setup NetperfReverse and Ran Throughput (Speed = %s 10^6bits/sec, CPU = %s)" % ( speed, avg_cpu)
def runTest(self): installers.install_iperf3(wan) installers.install_iperf3(lan) wan.sendline('iperf3 -s') wan.expect( '-----------------------------------------------------------') wan.expect( '-----------------------------------------------------------') time = 60 lan.sendline('iperf3 -c 192.168.0.1 -P5 -t %s -i 0' % time) lan.expect(prompt, timeout=time + 5) sender = re.findall('SUM.*Bytes\s*(.*/sec).*sender', lan.before)[-1] if 'Mbits' in sender: s_rate = float(sender.split()[0]) elif 'Kbits' in sender: s_rate = float(sender.split()[0] / 1024) else: raise Exception("Unknown rate in sender results") recv = re.findall('SUM.*Bytes\s*(.*/sec).*receiver', lan.before)[-1] if 'Mbits' in recv: r_rate = float(recv.split()[0]) elif 'Kbits' in recv: r_rate = float(recv.split()[0] / 1024) else: raise Exception("Unknown rate in recv results") self.result_message = "Sender rate = %si MBits/sec, Receiver rate = %s Mbits/sec\n", ( s_rate, r_rate) self.logged['s_rate'] = s_rate self.logged['r_rate'] = r_rate self.recovery()
def runTest(self): wan_ip_addr = board.get_interface_ipaddr('eth0') wan.sendline('\nnmap -sS -A -v %s' % wan_ip_addr) wan.expect('Starting Nmap', timeout=5) wan.expect('Nmap scan report', timeout=120) wan.expect(prompt, timeout=60) open_ports = re.findall("(\d+)/tcp\s+open", wan.before) msg = "Found %s open TCP ports on WAN interface." % len(open_ports) self.result_message = msg assert len(open_ports) == 0
def runTest(self): wan.sendline( 'apt-get -o DPkg::Options::="--force-confnew" -y --force-yes install snmp' ) wan.expect(prompt) wan_ip = board.get_interface_ipaddr(board.wan_iface) wan.sendline('snmpget -v2c -c public %s 1.3.6.1.2.1.1.1.0' % wan_ip) wan.expect('iso.3.6.1.2.1.1.1.0 = STRING: ') wan.expect(prompt) self.result_message = wan.before
def runTest(self): wan_ip_addr = board.get_interface_ipaddr(board.wan_iface) wan.sendline('\nnmap -sS -A -v %s' % wan_ip_addr) wan.expect('Starting Nmap', timeout=5) wan.expect('Nmap scan report', timeout=240) wan.expect(prompt, timeout=60) open_ports = re.findall("(\d+)/tcp\s+open", wan.before) msg = "Found %s open TCP ports on WAN interface." % len(open_ports) self.result_message = msg print("open ports = %s" % open_ports) if hasattr(board, 'wan_open_ports'): print("allowing open ports %s" % board.wan_open_ports) open_ports = set(open_ports) - set(board.wan_open_ports) assert len(open_ports) == 0
def runTest(self): wan_ip_addr = board.get_interface_ipaddr(board.wan_iface) wan.sendline('\nnmap -sS -A -v %s' % wan_ip_addr) wan.expect('Starting Nmap', timeout=5) wan.expect('Nmap scan report', timeout=240) wan.expect(prompt, timeout=60) open_ports = re.findall("(\d+)/tcp\s+open", wan.before) msg = "Found %s open TCP ports on WAN interface." % len(open_ports) self.result_message = msg print("open ports = %s" % open_ports) if hasattr(board, 'wan_open_ports'): print ("allowing open ports %s" % board.wan_open_ports) open_ports = set(open_ports) - set(board.wan_open_ports) assert len(open_ports) == 0
def runTest(self): board.sendline('\nuci delete network.lan.ip6addr') board.expect('uci ') board.expect(prompt) board.sendline('uci delete network.wan.ip6addr') board.expect(prompt) board.sendline('ip -6 addr delete 5aaa::1/64 dev eth0') board.expect(prompt) board.sendline('uci commit network') board.expect(prompt) board.network_restart() # Lan-side Device lan.sendline('\nip -6 addr del 4aaa::6/64 dev eth1') lan.expect('ip -6') lan.expect(prompt) lan.sendline('ip -6 route del default') lan.expect(prompt) # Wan-side Device wan.sendline('\nip -6 addr del 5aaa::6/64 dev eth1') wan.expect('ip -6') wan.expect(prompt) wan.sendline('ip -6 route del default') wan.expect(prompt) time.sleep(10)
def boot(self, reflash=True): # start tftpd server on appropriate device tftp_servers = [ x['name'] for x in self.config.board['devices'] if 'tftpd-server' in x.get('options', "") ] tftp_device = None # start all tftp servers for now for tftp_server in tftp_servers: tftp_device = getattr(self.config, tftp_server) # start dhcp servers for device in self.config.board['devices']: if 'options' in device and 'dhcp-server' in device['options']: getattr(self.config, device['name']).setup_dhcp_server() if not wan and len(tftp_servers) == 0: msg = 'No WAN Device or tftp_server defined, skipping flash.' lib.common.test_msg(msg) self.skipTest(msg) # This still needs some clean up, the fall back is to assuming the # WAN provides the tftpd server, but it's not always the case if self.config.board.get('wan_device', None) is not None: wan.start_tftp_server() tftp_device = wan wan.configure(kind="wan_device", config=self.config.board) elif wan: wan.configure(kind="wan_device", config=self.config.board) if tftp_device is None: tftp_device = wan prov = getattr(self.config, 'provisioner', None) if prov is not None: prov.provision_board(self.config.board) if lan: lan.configure(kind="lan_device") tftp_device.start_tftp_server() board.reset() rootfs = None # Reflash only if at least one or more of these # variables are set, or else there is nothing to do in u-boot meta_interrupt = False if self.config.META_BUILD and not board.flash_meta_booted: meta_interrupt = True if reflash and (meta_interrupt or self.config.ROOTFS or\ self.config.KERNEL or self.config.UBOOT): # Break into U-Boot, set environment variables board.wait_for_boot() board.setup_uboot_network(tftp_device.gw) if self.config.META_BUILD: for attempt in range(3): try: board.flash_meta(self.config.META_BUILD, wan, lan) break except Exception as e: print(e) tftp_device.restart_tftp_server() board.reset(break_into_uboot=True) board.setup_uboot_network(tftp_device.gw) else: raise Exception('Error during flashing...') if self.config.UBOOT: board.flash_uboot(self.config.UBOOT) if self.config.ROOTFS: # save filename for cases where we didn't flash it # but will use it later to load from memory rootfs = board.flash_rootfs(self.config.ROOTFS) if self.config.NFSROOT: board.prepare_nfsroot(self.config.NFSROOT) if self.config.KERNEL: board.flash_linux(self.config.KERNEL) # Boot from U-Boot to Linux board.boot_linux(rootfs=rootfs, bootargs=self.config.bootargs) if hasattr(board, "pre_boot_linux"): board.pre_boot_linux(wan=wan, lan=lan) board.linux_booted = True board.wait_for_linux() if self.config.META_BUILD and board.flash_meta_booted: board.flash_meta(self.config.META_BUILD, wan, lan) linux_booted_seconds_up = board.get_seconds_uptime() # Retry setting up wan protocol if self.config.setup_device_networking: for i in range(2): time.sleep(10) try: if "pppoe" in self.config.WAN_PROTO: wan.turn_on_pppoe() board.config_wan_proto(self.config.WAN_PROTO) break except: print("\nFailed to check/set the router's WAN protocol.") pass board.wait_for_network() board.wait_for_mounts() if self.config.setup_device_networking: # Router mac addresses are likely to change, so flush arp if lan: lan.ip_neigh_flush() if wan: wan.ip_neigh_flush() # Clear default routes perhaps left over from prior use if lan: lan.sendline('\nip -6 route del default') lan.expect(prompt) if wan: wan.sendline('\nip -6 route del default') wan.expect(prompt) # Give other daemons time to boot and settle if self.config.setup_device_networking: for i in range(5): board.get_seconds_uptime() time.sleep(5) try: board.sendline("passwd") board.expect("password:"******"password") board.expect("password:"******"password") board.expect(prompt) except: print("WARNING: Unable to set root password on router.") board.sendline('cat /proc/cmdline') board.expect(prompt) board.sendline('uname -a') board.expect(prompt) # we can't have random messsages messages board.sendline("echo \"1 1 1 7\" > /proc/sys/kernel/printk") board.expect(prompt) if hasattr(self.config, 'INSTALL_PKGS') and self.config.INSTALL_PKGS != "": for pkg in self.config.INSTALL_PKGS.split(' '): if len(pkg) > 0: board.install_package(pkg) # Try to verify router has stayed up (and, say, not suddenly rebooted) end_seconds_up = board.get_seconds_uptime() print("\nThe router has been up %s seconds." % end_seconds_up) if self.config.setup_device_networking: assert end_seconds_up > linux_booted_seconds_up self.logged['boot_time'] = end_seconds_up if board.routing and lan and self.config.setup_device_networking: if wan is not None: lan.start_lan_client(wan_gw=wan.gw) else: lan.start_lan_client()
def runTest(self): # Router board.sendline('uci set network.lan6=interface') board.expect(prompt) board.sendline('uci set network.lan6.proto=static') board.expect(prompt) board.sendline('uci set network.lan6.ip6addr=4aaa::1/64') board.expect(prompt) board.sendline('uci set network.lan6.ifname=@lan') board.expect(prompt) board.sendline('uci set network.wan6=interface') board.expect(prompt) board.sendline('uci set network.wan6.proto=static') board.expect(prompt) board.sendline('uci set network.wan6.ip6addr=5aaa::1/64') board.expect(prompt) board.sendline('uci set network.wan6.ifname=@wan') board.expect(prompt) board.sendline('uci commit network') board.expect(prompt) board.network_restart() # Lan-side Device lan.sendline('\nip -6 addr add 4aaa::6/64 dev eth1') lan.expect('ip -6') lan.expect(prompt) lan.sendline('ip -6 route add 4aaa::1 dev eth1') lan.expect(prompt) lan.sendline('ip -6 route add default via 4aaa::1 dev eth1') lan.expect(prompt) if 'No route to host' in lan.before: raise Exception('Error setting ivp6 routes') # Wan-side Device wan.sendline('\nip -6 addr add 5aaa::6/64 dev eth1') wan.expect('ip -6') wan.expect(prompt) wan.sendline('ip -6 route add 5aaa::1 dev eth1') wan.expect(prompt) wan.sendline('ip -6 route add default via 5aaa::1 dev eth1') wan.expect(prompt) if 'No route to host' in wan.before: raise Exception('Error setting ivp6 routes') # Wlan-side Device if wlan: wlan.sendline('\nip -6 addr add 4aaa::7/64 dev wlan0') wlan.expect('ip -6') wlan.expect(prompt) wlan.sendline('ip -6 route add 4aaa::1 dev eth1') wlan.expect(prompt) wlan.sendline('ip -6 route add default via 4aaa::1 dev wlan0') wlan.expect(prompt) # Give things time to get ready time.sleep(20) # Check addresses board.sendline('\nifconfig | grep -B2 addr:') board.expect('ifconfig ') board.expect(prompt) lan.sendline('\nifconfig | grep -B2 addr:') lan.expect('ifconfig ') lan.expect(prompt) wan.sendline('\nifconfig | grep -B2 addr:') wan.expect('ifconfig ') wan.expect(prompt)
def boot(self, reflash=True): # start tftpd server on appropriate device tftp_servers = [ x['name'] for x in self.config.board['devices'] if 'tftpd-server' in x.get('options', "") ] tftp_device = None # start all tftp servers for now for tftp_server in tftp_servers: tftp_device = getattr(self.config, tftp_server) dhcp_started = False # start dhcp servers for device in self.config.board['devices']: if 'options' in device and 'dhcp-server' in device['options']: getattr(self.config, device['name']).setup_dhcp_server() dhcp_started = True if not wan and len(tftp_servers) == 0: msg = 'No WAN Device or tftp_server defined, skipping flash.' lib.common.test_msg(msg) self.skipTest(msg) # This still needs some clean up, the fall back is to assuming the # WAN provides the tftpd server, but it's not always the case if wan: wan.configure(kind="wan_device", config=self.config.board) if tftp_device is None: tftp_device = wan if wan and not dhcp_started: wan.setup_dhcp_server() tftp_device.start_tftp_server() prov = getattr(self.config, 'provisioner', None) if prov is not None: prov.tftp_device = tftp_device prov.provision_board(self.config.board) if hasattr(prov, 'prov_gateway'): gw = prov.prov_gateway if wan.gw in prov.prov_network else prov.prov_ip for nw in [prov.cm_network, prov.mta_network]: wan.sendline('ip route add %s via %s' % (nw, gw)) wan.expect(prompt) wan.sendline('ip route') wan.expect(prompt) if lan: lan.configure(kind="lan_device") # tftp_device is always None, so we can set it from config board.tftp_server = tftp_device.ipaddr # then these are just hard coded defaults board.tftp_port = 22 # but are user/password used for tftp, they are likely legacy and just need to go away board.tftp_username = "******" board.tftp_password = "******" board.reset() rootfs = None # Reflash only if at least one or more of these # variables are set, or else there is nothing to do in u-boot meta_interrupt = False if self.config.META_BUILD and not board.flash_meta_booted: meta_interrupt = True if reflash and (meta_interrupt or self.config.ROOTFS or\ self.config.KERNEL or self.config.UBOOT): # Break into U-Boot, set environment variables board.wait_for_boot() board.setup_uboot_network(tftp_device.gw) if self.config.META_BUILD: for attempt in range(3): try: board.flash_meta(self.config.META_BUILD, wan, lan) break except Exception as e: print(e) tftp_device.restart_tftp_server() board.reset(break_into_uboot=True) board.setup_uboot_network(tftp_device.gw) else: raise Exception('Error during flashing...') if self.config.UBOOT: board.flash_uboot(self.config.UBOOT) if self.config.ROOTFS: # save filename for cases where we didn't flash it # but will use it later to load from memory rootfs = board.flash_rootfs(self.config.ROOTFS) if self.config.NFSROOT: board.prepare_nfsroot(self.config.NFSROOT) if self.config.KERNEL: board.flash_linux(self.config.KERNEL) # Boot from U-Boot to Linux board.boot_linux(rootfs=rootfs, bootargs=self.config.bootargs) if hasattr(board, "pre_boot_linux"): board.pre_boot_linux(wan=wan, lan=lan) board.linux_booted = True board.wait_for_linux() if self.config.META_BUILD and board.flash_meta_booted: board.flash_meta(self.config.META_BUILD, wan, lan) linux_booted_seconds_up = board.get_seconds_uptime() # Retry setting up wan protocol if self.config.setup_device_networking: for i in range(2): time.sleep(10) try: if "pppoe" in self.config.WAN_PROTO: wan.turn_on_pppoe() board.config_wan_proto(self.config.WAN_PROTO) break except: print("\nFailed to check/set the router's WAN protocol.") pass board.wait_for_network() board.wait_for_mounts() if prov is not None and 'debian' in prov.model: table = self.config.board['station'] idx = wan.port # TODO: how to do this right...? for not_used in range(5): try: ips = [board.get_interface_ipaddr(board.wan_iface)] if hasattr(board, 'erouter_iface'): ips += [ board.get_interface_ipaddr(board.erouter_iface) ] if hasattr(board, 'mta_iface'): ips += [board.get_interface_ipaddr(board.mta_iface)] break except: continue # TODO: don't hard code 300 or mv1-1 prov.sendline('sed /^%s/d -i /etc/iproute2/rt_tables' % idx) prov.expect(prompt) prov.sendline('echo "%s %s" >> /etc/iproute2/rt_tables' % (idx, table)) prov.expect(prompt) for ip in ips: prov.sendline('ip rule del from %s' % ip) prov.expect(prompt) prov.sendline('ip rule add from %s lookup %s' % (ip, table)) prov.expect(prompt) wan_ip = wan.get_interface_ipaddr(wan.iface_dut) prov.sendline('ip route add default via %s dev eth1 table %s' % (wan_ip, table)) prov.expect(prompt) if self.config.setup_device_networking: # Router mac addresses are likely to change, so flush arp if lan: lan.ip_neigh_flush() if wan: wan.ip_neigh_flush() # Clear default routes perhaps left over from prior use if lan: lan.sendline('\nip -6 route del default') lan.expect(prompt) if wan: wan.sendline('\nip -6 route del default') wan.expect(prompt) # Give other daemons time to boot and settle if self.config.setup_device_networking: for i in range(5): board.get_seconds_uptime() time.sleep(5) try: board.sendline("passwd") board.expect("password:"******"password") board.expect("password:"******"password") board.expect(prompt) except: print("WARNING: Unable to set root password on router.") board.sendline('cat /proc/cmdline') board.expect(prompt) board.sendline('uname -a') board.expect(prompt) # we can't have random messsages messages board.sendline("echo \"1 1 1 7\" > /proc/sys/kernel/printk") board.expect(prompt) if hasattr(self.config, 'INSTALL_PKGS') and self.config.INSTALL_PKGS != "": for pkg in self.config.INSTALL_PKGS.split(' '): if len(pkg) > 0: board.install_package(pkg) # Try to verify router has stayed up (and, say, not suddenly rebooted) end_seconds_up = board.get_seconds_uptime() print("\nThe router has been up %s seconds." % end_seconds_up) if self.config.setup_device_networking: assert end_seconds_up > linux_booted_seconds_up self.logged['boot_time'] = end_seconds_up if board.routing and lan and self.config.setup_device_networking: if wan is not None: lan.start_lan_client(wan_gw=wan.gw) else: lan.start_lan_client()
def runTest(self): if 'cdrouter_server' in self.config.board: self.cdrouter_server = self.config.board['cdrouter_server'] elif self.config.cdrouter_server is not None: self.cdrouter_server = self.config.cdrouter_server if 'cdrouter_wan_iface' in self.config.board: self.cdrouter_wan_iface = self.config.board['cdrouter_wan_iface'] else: self.cdrouter_wan_iface = self.config.cdrouter_wan_iface if 'cdrouter_lan_iface' in self.config.board: self.cdrouter_lan_iface = self.config.board['cdrouter_lan_iface'] else: self.cdrouter_lan_iface = self.config.cdrouter_lan_iface if self.tests is None: self.skipTest("No tests defined!") if self.cdrouter_server is None: self.skipTest("No cdrouter server specified") lan.sendline('ifconfig %s down' % lan.iface_dut) lan.expect(prompt) if not board.has_cmts: wan.sendline('ifconfig %s down' % wan.iface_dut) wan.expect(prompt) c = CDRouter(self.cdrouter_server) try: board.sendcontrol('c') board.expect(prompt) board.sendline('reboot') board.expect('reboot: Restarting system') except: board.reset() board.wait_for_linux() board.wait_for_network() # Add extra board specific delay board.expect(pexpect.TIMEOUT, timeout=getattr(board, 'cdrouter_bootdelay', 0)) # If alt mac addr is specified in config, use that.. # CMTS = we route so no wan mac is used # if we route, we need to add routes wandutmac = None if board.has_cmts and wan.wan_cmts_provisioner: # TODO: there are more missing ones CDrouter expects wan.sendline('ip route add 200.0.0.0/8 via 192.168.3.2') wan.expect(prompt) elif not wan.static_ip: for device in self.config.board['devices']: if device['name'] == 'wan': if 'alt_macaddr' in device: wandutmac = device['alt_macaddr'] break # Otherwise grab this from the device interface if wandutmac is None: board.sendline('ifconfig %s' % board.wan_iface) board.expect('([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})') wandutmac = board.match.group() board.expect(prompt) print("Using %s for WAN mac address" % wandutmac) lan.vlan = wan.vlan = 0 for device in self.config.board['devices']: d = None if device['name'] == 'wan': d = wan elif device['name'] == 'lan': d = lan else: continue if d is not None: d.vlan = getattr(device, 'vlan', 0) if d.vlan == 0: d.sendline('cat /proc/net/vlan/config') d.expect_exact('cat /proc/net/vlan/config') if 0 == d.expect( [pexpect.TIMEOUT, '%s.*\|\s([0-9]+).*\|' % d.iface_dut], timeout=5): d.vlan = 0 else: d.vlan = d.match.group(1) d.expect(prompt) print("Using %s for WAN vlan" % wan.vlan) print("Using %s for LAN vlan" % lan.vlan) # TODO: move wan and lan interface to bft config? contents = """ testvar wanInterface """ + self.cdrouter_wan_iface if wandutmac is not None: contents = contents + """ testvar wanDutMac """ + wandutmac if wan.vlan != 0: contents = contents + """ testvar wanVlanId """ + wan.vlan contents = contents + """ testvar lanInterface """ + self.cdrouter_lan_iface if lan.vlan != 0: contents = contents + """ testvar lanVlanId """ + lan.vlan def add_cdrouter_config(config): cdr_conf = None # TODO: make a generic helper to search path and overlays if os.path.isfile(config): cdr_conf = open(config, 'r').readlines() elif 'BFT_OVERLAY' in os.environ: for p in os.environ['BFT_OVERLAY'].split(' '): p = os.path.realpath(p) try: cdr_conf = open(os.path.join(p, config), 'r').readlines() except: continue else: break return "\n" + "".join(cdr_conf) # Take config from overall config, but fallback to board config if self.config.cdrouter_config is not None: contents = contents + add_cdrouter_config( self.config.cdrouter_config) elif board.cdrouter_config is not None: contents = contents + add_cdrouter_config(board.cdrouter_config) if self.extra_config: contents = contents + "\n" + self.extra_config.replace(',', '\n') if board.has_cmts: for i in range(5): try: wan_ip = board.get_interface_ipaddr(board.erouter_iface) except: board.expect(pexpect.TIMEOUT, timeout=15) continue else: if i == 4: raise Exception("Failed to get erouter ip address") break # TODO: mask from config? wanNatIp vs. wanIspAssignGateway? contents=contents + """ testvar wanMode static testvar wanIspIp %s testvar wanIspGateway %s testvar wanIspMask 255.255.255.0 testvar wanIspAssignIp %s testvar wanNatIp %s testvar IPv4HopCount %s testvar lanDnsServer %s testvar wanDnsServer %s""" % (self.config.board['cdrouter_wanispip'], \ self.config.board['cdrouter_wanispgateway'], \ wan_ip, wan_ip, \ self.config.board['cdrouter_ipv4hopcount'], \ board.get_dns_server(), \ board.get_dns_server_upstream()) print("Using below for config:") print(contents) print("#######################") config_name = "bft-automated-job-%s" % str(time.time()).replace( '.', '') cfg = c.configs.create(Config(name=config_name, contents=contents)) p = c.packages.create( Package(name=config_name, testlist=self.tests, config_id=cfg.id)) self.start_time = time.time() j = c.jobs.launch(Job(package_id=p.id)) while j.result_id is None: if (time.time() - self.start_time) > 300: # delete job if it fails to start c.jobs.delete(j.id) raise Exception("Failed to start CDrouter job") board.expect(pexpect.TIMEOUT, timeout=1) j = c.jobs.get(j.id) print('Job Result-ID: {0}'.format(j.result_id)) self.job_id = j.result_id self.results = c.results unpaused = False end_of_start = False no_more_pausing = False while True: r = c.results.get(j.result_id) print(r.status) # we are ready to go from boardfarm reset above if r.status == "paused" and unpaused == False: c.results.unpause(j.result_id) unpaused = True board.expect(pexpect.TIMEOUT, timeout=1) c.results.pause(j.result_id, when="end-of-test") end_of_start = True continue if r.status == "paused" and end_of_start == True: end_of_start = False # TODO: do we need this anymore? we have board specific cdrouter_bootdelay board.expect(pexpect.TIMEOUT, timeout=60) c.results.unpause(j.result_id) board.expect(pexpect.TIMEOUT, timeout=1) no_more_pausing = True continue if no_more_pausing and r.status == "paused": print("Error: test is still paused") c.results.stop(j.result_id) break if r.status != "running" and r.status != "paused": break board.expect(pexpect.TIMEOUT, timeout=5) print(r.result) self.result_message = r.result.encode('ascii', 'ignore') # TODO: results URL? elapsed_time = time.time() - self.start_time print("Test took %s" % time.strftime("%H:%M:%S", time.gmtime(elapsed_time))) summary = c.results.summary_stats(j.result_id) self.result_message += " (Failed= %s, Passed = %s, Skipped = %s)" \ % (summary.result_breakdown.failed, \ summary.result_breakdown.passed, \ summary.result_breakdown.skipped) for test in summary.test_summaries: self.logged[test.name] = vars(test) if str(test.name) not in ["start", "final"]: from lib.common import TestResult try: grade_map = { "pass": "******", "fail": "FAIL", "skip": "SKIP" }[test.result] tr = TestResult(test.name, grade_map, test.description) if test.started is not None: tr.start_time = test.started tr.stop_time = test.started + test.duration else: tr.elapsed_time = test.duration self.subtests.append(tr) except: continue # TODO: handle skipped tests try: metric = c.results.get(result_id, test.name, "bandwidth") print(vars(metric)) # TODO: decide how to export data to kibana except: # Not all tests have this metric, no other way? pass assert (r.result == "The package completed successfully") self.recover()
def boot(self, reflash=True): if not wan: msg = 'No WAN Device defined, skipping flash.' lib.common.test_msg(msg) self.skipTest(msg) wan.configure(kind="wan_device") if lan: lan.configure(kind="lan_device") # start tftpd server on appropriate device if self.config.board.get('wan_device', None) is not None: wan.start_tftp_server() else: tftp_servers = [ x['name'] for x in self.config.board['devices'] if 'tftpd-server' in x.get('options', "") ] # start all tftp servers for now for tftp_server in tftp_servers: tftp_device = getattr(self.config, tftp_server) tftp_device.start_tftp_server() board.reset() rootfs = None # Reflash only if at least one or more of these # variables are set, or else there is nothing to do in u-boot if reflash and (self.config.META_BUILD or self.config.ROOTFS or\ self.config.KERNEL or self.config.UBOOT): # Break into U-Boot, set environment variables board.wait_for_boot() board.setup_uboot_network() if self.config.META_BUILD: for attempt in range(3): try: board.flash_meta(self.config.META_BUILD) break except Exception as e: print(e) wan.restart_tftp_server() board.reset(break_into_uboot=True) board.setup_uboot_network() else: raise Exception('Error during flashing...') if self.config.UBOOT: board.flash_uboot(self.config.UBOOT) if self.config.ROOTFS: # save filename for cases where we didn't flash it # but will use it later to load from memory rootfs = board.flash_rootfs(self.config.ROOTFS) if self.config.KERNEL: board.flash_linux(self.config.KERNEL) # Boot from U-Boot to Linux board.boot_linux(rootfs=rootfs) board.linux_booted = True board.wait_for_linux() linux_booted_seconds_up = board.get_seconds_uptime() # Retry setting up wan protocol for i in range(2): time.sleep(10) try: if "pppoe" in self.config.WAN_PROTO: wan.turn_on_pppoe() board.config_wan_proto(self.config.WAN_PROTO) break except: print("\nFailed to check/set the router's WAN protocol.") pass board.wait_for_network() # wait for overlay to finish mounting for i in range(5): try: board.sendline('mount') board.expect_exact('overlayfs:/overlay on / type overlay') board.expect(prompt) except: if i == 4: lib.common.test_msg("WARN: Overlay still not mounted") else: pass else: break # Router mac addresses are likely to change, so flush arp if lan: lan.ip_neigh_flush() wan.ip_neigh_flush() # Clear default routes perhaps left over from prior use if lan: lan.sendline('\nip -6 route del default') lan.expect(prompt) wan.sendline('\nip -6 route del default') wan.expect(prompt) # Give other daemons time to boot and settle for i in range(5): board.get_seconds_uptime() time.sleep(5) try: board.sendline("passwd") board.expect("New password:"******"password") board.expect("Retype password:"******"password") board.expect(prompt) except: print("WARNING: Unable to set root password on router.") board.sendline('cat /proc/cmdline') board.expect(prompt) board.sendline('uname -a') board.expect(prompt) # we can't have random messsages messages board.sendline("echo \"1 1 1 7\" > /proc/sys/kernel/printk") board.expect(prompt) if hasattr(self.config, 'INSTALL_PKGS') and self.config.INSTALL_PKGS != "": for pkg in self.config.INSTALL_PKGS.split(' '): if len(pkg) > 0: board.install_package(pkg) # Try to verify router has stayed up (and, say, not suddenly rebooted) end_seconds_up = board.get_seconds_uptime() print("\nThe router has been up %s seconds." % end_seconds_up) assert end_seconds_up > linux_booted_seconds_up assert end_seconds_up > 30 self.logged['boot_time'] = end_seconds_up if lan: lan.start_lan_client()