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 = 0.05 * self.num_conn if 0 != lan.expect([ r'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): 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 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 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 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 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 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 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): 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): 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 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 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): 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): 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: # This is a mess, just taking the last tftpd-server? tftp_device = getattr(self.config, tftp_server) # start dhcp servers for device in self.config.board['devices']: if 'options' in device and 'no-dhcp-sever' in device['options']: continue 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 wan: wan.configure(kind="wan_device", config=self.config.board) if tftp_device is None: tftp_device = wan tftp_device.start_tftp_server() prov = getattr(self.config, 'provisioner', None) if prov is not None: prov.tftp_device = tftp_device board.reprovision(prov) 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, prov.open_network ]: wan.sendline('ip route add %s via %s' % (nw, gw)) wan.expect(prompt) # TODO: don't do this and sort out two interfaces with ipv6 wan.disable_ipv6('eth0') if hasattr(prov, 'prov_gateway_v6'): wan.sendline('ip -6 route add default via %s' % str(prov.prov_gateway_v6)) wan.expect(prompt) wan.sendline('ip route') wan.expect(prompt) wan.sendline('ip -6 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() # 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.set_printk() 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) if board.has_cmts: board.check_valid_docsis_ip_networking() # 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 %s' % lan.iface_dut) lan.expect('ip -6') lan.expect(prompt) lan.sendline('ip -6 route add 4aaa::1 dev %s' % lan.iface_dut) lan.expect(prompt) lan.sendline('ip -6 route add default via 4aaa::1 dev %s' % lan.iface_dut) 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 %s' % wan.iface_dut) wan.expect('ip -6') wan.expect(prompt) wan.sendline('ip -6 route add 5aaa::1 dev %s' % wan.iface_dut) wan.expect(prompt) wan.sendline('ip -6 route add default via 5aaa::1 dev %s' % wan.iface_dut) 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 runTest(self): if not wan: msg = 'No WAN Device defined, skipping test_create_session.' lib.common.test_msg(msg) self.skipTest(msg) from boardfarm import devices # this should fail, as "DebianBoxNonExistent" is not (yet) a device try: kwargs = { 'name': "wan_test_calls_fail", 'ipaddr': wan.ipaddr, 'port': 22, 'color': 'magenta' } self.session = devices.get_device("DebianBoxNonExistent", **kwargs) except: pass else: assert self.session is None, "Test Failed on wrong class name" print( "Failed to create session on wrong class name (expected) PASS") # this must fail, as "169.254.12.18" is not a valid ip try: kwargs = { 'name': "wan_test_ip_fail", 'ipaddr': "169.254.12.18", 'port': 22, 'color': 'cyan' } self.session = devices.get_device("DebianBox", **kwargs) except: pass else: assert self.session is None, "Test Failed on wrong IP" print("Failed to create session on wrong IP (expected) PASS") # this must fail, as 50 is not a valid port try: kwargs = { 'name': "wan_test_port_fail", 'ipaddr': wan.ipaddr, 'port': 50, 'color': 'red' } self.session = devices.get_device("DebianBox", **kwargs) except: pass else: assert self.session is None, "Test Failed on wrong port" print("Failed to create session on wrong port (expected) PASS") # this must fail, close but no cigar try: kwargs = { 'name': "wan_test_type_fail", 'ipaddr': wan.ipaddr, 'port': 50, 'color': 'red' } self.session = devices.get_device("debina", **kwargs) except: pass else: assert self.session is None, "Test Failed on misspelled class name" print( "Failed to create session on misspelled class name (expected) PASS" ) # this should pass try: kwargs = { 'name': "correct_wan_parms", 'ipaddr': wan.ipaddr, 'port': wan.port, 'color': 'yellow' } self.session = devices.get_device("debian", **kwargs) except: assert 0, "Failed to create session, Test FAILED!" else: assert self.session is not None, "Test Failed on correct paramters!!" print("Session created successfully") # is the session really logged onto the wan? wan.sendline() wan.expect(wan.prompt) wan.sendline("ip a") wan.expect_exact("ip a") wan.expect(wan.prompt) w = wan.before self.session.sendline() self.session.expect(self.session.prompt) self.session.sendline("ip a") self.session.expect_exact("ip a") self.session.expect(self.session.prompt) s = self.session.before assert w == s, "Interfaces differ!!! Test Failed" self.session.sendline("exit") print("Test passed")
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(pexpect.TIMEOUT, timeout=60) board.touch() wan.expect(pexpect.TIMEOUT, timeout=60) board.touch() wan.expect(pexpect.TIMEOUT, timeout=60) board.touch() wan.expect('Nmap scan report', timeout=60) 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(map(int, open_ports)) - set(board.wan_open_ports) assert len(open_ports) == 0
def runTest(self): from boardfarm.devices import cdrouter self.cdrouter_server = "http://" + cdrouter.ipaddr self.cdrouter_wan_iface = cdrouter.wan_iface self.cdrouter_lan_iface = 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: from boardfarm.devices import provisioner # TODO: there are more missing ones CDrouter expects provisioner.sendline('ip route add 200.0.0.0/8 via 192.168.3.2') provisioner.expect(prompt) provisioner.sendline('ip route add 3.3.3.3 via 192.168.3.2') provisioner.expect(prompt) provisioner.sendline( 'ip route add 3001:cafe:1::/64 via 2001:dead:beef:1::2') provisioner.expect(prompt) provisioner.sendline( 'ip route add 3001:51a:cafe::1 via 2001:dead:beef:1::2') provisioner.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) # TODO: WIP wan.vlan = "136" 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 if self.extra_config: contents = contents + "\n" + self.extra_config.replace(',', '\n') def add_cdrouter_config(config): p = os.path.realpath(config) cdr_conf = open(os.path.join(p, config), 'r').readlines() return "\n" + "".join(cdr_conf) if board.cdrouter_config is not None: contents = contents + add_cdrouter_config(board.cdrouter_config) if board.has_cmts: for i in range(5): exp = None try: wan_ip = board.get_interface_ipaddr(board.erouter_iface) # TODO: this breaks ipv6 only wan_ip6 = board.get_interface_ip6addr(board.erouter_iface) lan.start_lan_client() lan_ip6 = lan.get_interface_ip6addr(lan.iface_dut) ip6 = ipaddress.IPv6Network(six.text_type(lan_ip6)) fixed_prefix6 = str( ip6.supernet(new_prefix=64).network_address) break except Exception as e: exp = e board.expect(pexpect.TIMEOUT, timeout=15) continue else: if i == 4: raise exp # TODO: mask from config? wanNatIp vs. wanIspAssignGateway? contents=contents + """ testvar ipv6LanIp %s%%eui64%% testvar ipv6LanPrefixLen 64 testvar healthCheckEnable yes testvar supportsIPv6 yes testvar ipv6WanMode static testvar ipv6WanIspIp %s testvar ipv6WanIspGateway %s testvar ipv6WanIspAssignIp %s testvar ipv6WanIspPrefixLen 64 testvar ipv6LanMode autoconf testvar ipv6RemoteHost 3001:51a:cafe::1 testvar ipv6FreeNetworkStart 3001:cafe:1:: testvar ipv6FreeNetworkEnd 3001:cafe:ffff:: testvar ipv6FreeNetworkPrefixLen 64 testvar wanMode static testvar wanIspIp %s testvar wanIspGateway %s testvar wanIspMask 255.255.255.128 testvar wanIspAssignIp %s testvar wanNatIp %s testvar remoteHostIp 3.3.3.3 testvar FreeNetworkStart 200.0.0.0 testvar FreeNetworkMask 255.255.255.0 testvar FreeNetworkStop 201.0.0.0 testvar IPv4HopCount %s testvar lanDnsServer %s testvar wanDnsServer %s """ % (fixed_prefix6, cdrouter.wanispip_v6, \ cdrouter.wanispgateway_v6, \ wan_ip6, \ cdrouter.wanispip, \ cdrouter.wanispgateway, \ wan_ip, wan_ip, \ 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 = six.text_type(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"]: 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(j.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 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 boardfarm.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(j.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()