Esempio n. 1
0
    def runTest(self):
        board.sendline('cat /etc/os-release')
        # PRETTY_NAME=RDK (A Yocto Project 1.6 based Distro) 2.0 (krogoth)
        board.expect('PRETTY_NAME=([^\s]*) \(A Yocto Project (?:[^\s]*?)\s?based Distro\) ([^\s]*) \(([^\)]*)\)')

        index = 1
        bsp_type = board.match.group(index)
        index += 1
        if len(board.match.groups()) == 4:
            oe_version = board.match.group(index)
            index += 1
        else:
            oe_version = "Unknown"
        bsp_version = board.match.group(index)
        index += 1
        oe_version_string = board.match.group(index)
        index += 1

        board.expect(prompt)

        print("#########################################")
        print("bsp-type = %s" % bsp_type)
        print("oe-version = %s" % oe_version)
        print("bsp-version = %s" % bsp_version)
        print("oe-version-string = %s" % oe_version_string)
        print("#########################################")

        self.result_message="BSP = %s, BSP version = %s, OE version = %s, OE version string = %s" % \
                (bsp_type, bsp_version, oe_version, oe_version_string)
        self.logged['bsp-type'] = bsp_type
        self.logged['oe-version'] =  oe_version
        self.logged['bsp-version'] =  bsp_version
        self.logged['oe-version-string'] = oe_version_string
Esempio n. 2
0
    def runTest(self, client=lan, server=wan):
        mpstat_present = self.mpstat_ok()

        # this is running an arbitrary time, we will ctrl-c and get results
        self.run_iperf_server(server, opts=self.server_opts_forward())
        if mpstat_present:
            board.sendline('mpstat -P ALL 10000 1')
            board.expect('Linux')
        self.run_iperf(client, opts=opts)
        rate = self.parse_iperf(client)

        if mpstat_present:
            board.sendcontrol('c')
            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)
            self.logged['avg_cpu'] = float(avg_cpu)
        else:
            avg_cpu = "N/A"

        self.kill_iperf(server)
        msg = '%s (%s Mbps, CPU=%s)' % (self.__doc__, rate, avg_cpu)
        lib.common.test_msg("\n%s" % msg)

        self.logged['rate'] = float(rate)
        self.result_message = msg
Esempio n. 3
0
 def runTest(self):
     board.sendline('\nopkg list-installed | grep qos-scripts')
     try:
         board.expect('qos-scripts - ', timeout=4)
     except:
         return   # pass if not installed
     assert False # fail if installed
Esempio n. 4
0
    def runTest(self, node1=lan, node2=wan):
        mpstat_present = self.mpstat_ok()

        self.run_iperf_server(node1, opts=self.server_opts_reverse(node1))
        self.run_iperf_server(node2, opts=self.server_opts_forward())
        # this is running an arbitrary time, we will ctrl-c and get results
        if mpstat_present:
            board.sendline('mpstat -P ALL 10000 1')
            board.expect('Linux')
        self.run_iperf(node2, opts=opts, target=self.reverse_ip())
        self.run_iperf(node1, opts=opts)
        rate = 0.0
        rate += float(self.parse_iperf(node1))
        rate += float(self.parse_iperf(node2))
        if mpstat_present:
            board.sendcontrol('c')
            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)
            self.logged['avg_cpu'] = float(avg_cpu)
        else:
            avg_cpu = "N/A"

        self.kill_iperf(node1)
        self.kill_iperf(node2)
        msg = 'iPerf bidir  WAN to LAN (%s Mbps, CPU=%s)' % (rate, avg_cpu)
        lib.common.test_msg("\n%s" % msg)

        self.logged['rate'] = float(rate)
        self.result_message = msg
 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
Esempio n. 6
0
 def runTest(self):
     wlan_iface = lib.wifi.wifi_interface(board)
     lib.wifi.enable_wifi(board)
     lib.wifi.wait_wifi_up(board, wlan_iface=wlan_iface)
     board.sendline("\nifconfig")
     board.expect("HWaddr")
     board.expect(prompt)
Esempio n. 7
0
 def runTest(self):
     if not wan:
         msg = 'No WAN Device defined, skipping ping WAN test.'
         lib.common.test_msg(msg)
         self.skipTest(msg)
     board.sendline('\nping -c5 192.168.0.1')
     board.expect('5 packets received', timeout=10)
     board.expect(prompt)
Esempio n. 8
0
 def runTest(self):
     board.sendline('\ncat /etc/device_info')
     board.expect('cat /etc/device_info', timeout=6)
     board.expect('DEVICE_MANUFACTURER=\'Imagination Technologies\'')
     board.expect('DEVICE_MANUFACTURER_URL=\'www.imgtec.com\'')
     board.expect('DEVICE_PRODUCT=\'Creator Ci40\\(marduk\\)\'')
     board.expect('DEVICE_REVISION=\'v0\'') # Until CreatorDev/openwrt#293 is fixed
     board.expect(prompt)
Esempio n. 9
0
 def runTest(self):
     if not wan:
         msg = 'No WAN Device defined, skipping ping WAN test.'
         lib.common.test_msg(msg)
         self.skipTest(msg)
     board.sendline('\nping -c5 %s' % wan.gw)
     board.expect('5 (packets )?received', timeout=15)
     board.expect(prompt)
Esempio n. 10
0
    def mpstat_ok(self):
        board.sendline('mpstat -V')
        if board.expect(['sysstat version', 'BusyBox', 'not found'], timeout=5) == 0:
            mpstat_present = True
        else:
            mpstat_present = False
        board.expect(prompt)

        return mpstat_present
Esempio n. 11
0
 def runTest(self):
     board.sendline('\nifconfig')
     board.expect('ifconfig')
     board.expect(prompt)
     results = re.findall('([A-Za-z0-9-\.]+)\s+Link.*\n.*addr:([^ ]+)', board.before)
     tmp = ', '.join(["%s %s" % (x, y) for x, y in results])
     board.sendline('route -n')
     board.expect(prompt)
     self.result_message = 'ifconfig shows ip addresses: %s' % tmp
Esempio n. 12
0
 def runTest(self):
     board.sendline('\ntop -b -n 1')
     board.expect('Mem:', timeout=5)
     try:
         board.expect(prompt, timeout=2)
     except:
         # some versions of top do not support '-n'
         # must CTRL-C to kill top
         board.sendcontrol('c')
Esempio n. 13
0
 def runTest(self):
     for sz in ["74", "128", "256", "512", "1024", "1280", "1518" ]:
         print("running %s UDP test" % sz)
         lan.sendline('netperf -H 192.168.0.1 -t UDP_STREAM -l 60 -- -m %s' % sz)
         lan.expect_exact('netperf -H 192.168.0.1 -t UDP_STREAM -l 60 -- -m %s' % sz)
         lan.expect('UDP UNIDIRECTIONAL')
         lan.expect(prompt, timeout=90)
         board.sendline()
         board.expect(prompt)
Esempio n. 14
0
 def runTest(self):
     board.sendline('\nopkg list-installed | wc -l')
     board.expect('opkg list')
     board.expect('(\d+)\r\n')
     num_pkgs = int(board.match.group(1))
     board.expect(prompt)
     board.sendline('opkg list-installed')
     board.expect(prompt)
     self.result_message = '%s OpenWrt packages are installed.' % num_pkgs
     self.logged['num_installed'] = num_pkgs
Esempio n. 15
0
 def runTest(self):
     board.sendline('\nlsmod | wc -l')
     board.expect('lsmod ')
     board.expect('(\d+)\r\n')
     num = int(board.match.group(1)) - 1 # subtract header line
     board.expect(prompt)
     board.sendline('lsmod | sort')
     board.expect(prompt)
     self.result_message = '%s kernel modules are loaded.' % num
     self.logged['num_loaded'] = num
Esempio n. 16
0
 def runTest(self):
     board.sendline("\nuci show mcproxy")
     board.expect_exact("mcproxy.config=mcproxy", timeout=5)
     board.expect_exact("mcproxy.config.protocol=IGMPv3", timeout=5)
     board.expect_exact("mcproxy.@pinstance[0]=pinstance", timeout=5)
     board.expect_exact("mcproxy.@pinstance[0].name=mcproxy1", timeout=5)
     board.expect(prompt)
     board.sendline("cat /etc/mcproxy.conf")
     board.expect("protocol IGMPv3;", timeout=5)
     board.expect('pinstance mcproxy1: "eth0" ==> "br-lan";')
     board.expect(prompt)
Esempio n. 17
0
    def runTest(self):
        super(NetperfTest, self).runTest()

        board.sendline('mpstat -P ALL 30 1')
        speed = self.run_netperf(lan, "192.168.0.1 -c -C -l 30")
        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 Netperf and Ran Throughput (Speed = %s 10^6bits/sec, CPU = %s)" % (speed, avg_cpu)
Esempio n. 18
0
 def runTest(self):
     board.sendline('\nhead -c 1000000 /dev/urandom > /www/deleteme.txt')
     board.expect('head ', timeout=5)
     board.expect(prompt)
     lan.sendline('\ncurl -m 25 http://192.168.1.1/deleteme.txt > /dev/null')
     lan.expect('Total', timeout=5)
     lan.expect('100 ', timeout=10)
     lan.expect(prompt, timeout=10)
     board.sendline('\nrm -f /www/deleteme.txt')
     board.expect('deleteme.txt')
     board.expect(prompt)
Esempio n. 19
0
    def runTest(self):
        wlan_iface = wifi_interface(board)
        if wlan_iface is None:
            self.skipTest("No wifi interfaces detected, skipping..")

        board.sendline('\nuci show wireless')
        board.expect('uci show wireless')
        board.expect(prompt)
        wifi_interfaces = re.findall('wireless.*=wifi-device', board.before)
        self.result_message = "UCI shows %s wifi interface(s)." % (len(wifi_interfaces))
        self.logged['num_ifaces'] = len(wifi_interfaces)
        # Require that at least one wifi interface is present
        assert len(wifi_interfaces) > 0
Esempio n. 20
0
 def runTest(self):
     # One package per feed: packages, openwrt-routing, openwrt-managements,
     # ci40-platform-feed, telephony, luci
     packages = [ "nano", "mrd6", "libssh", "glog", "miax", "luci-mod-rpc" ]
     for pkg in packages:
         board.sendline("\nopkg install {}".format(pkg))
         board.expect("Configuring {}".format(pkg))
         board.expect(prompt)
         board.sendline('\nopkg list-installed | grep {}'.format(pkg))
         try:
             board.expect('{} - '.format(pkg)) # pass if installed
         except:
             assert False # fail if not installed
Esempio n. 21
0
 def runTest(self):
     board.sendline('\nuci set firewall.@defaults[0].forward=REJECT')
     board.expect('uci set firewall')
     board.expect(prompt)
     board.sendline('uci set firewall.@zone[0].forward=REJECT')
     board.expect(prompt)
     board.sendline('uci set firewall.@zone[1].input=REJECT')
     board.expect(prompt)
     board.sendline('uci set firewall.@zone[1].forward=REJECT')
     board.expect(prompt)
     board.sendline('uci commit firewall')
     board.expect(prompt)
     board.firewall_restart()
Esempio n. 22
0
    def recover(self):
        if self.__class__.__name__ == "RootFSBootTest":
            try:
                if board.linux_booted:
                    board.sendline('ps auxfw || ps w')
                    board.expect(prompt)
                    board.sendline('iptables -S')
                    board.expect(prompt)
            except:
                pass

            board.close()
            lib.common.test_msg("Unable to boot, skipping remaining tests...")
            return
        try:
            # let user interact with console if test failed
            try:
                board.sendline()
                board.sendline()
                if not self.config.batch:
                    board.interact()
            except:
                pass
            if self.reboot == True and self.reset_after_fail:
                self.boot(self.reflash)
            self.reboot = True
        except Exception as e:
            print("Unable to recover, %s" % e)
            self.assertEqual(1, 0, e)
Esempio n. 23
0
    def recover(self):
        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 eth1 up')
            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()
Esempio n. 24
0
 def runTest(self):
     board.sendline('\nip link show')
     board.expect('ip link show')
     board.expect(prompt)
     if "ip: not found" not in board.before:
         up_interfaces = re.findall('\d: ([A-Za-z0-9-\.]+)[:@].*state UP ', board.before)
     else:
         board.sendline('ifconfig')
         board.expect(prompt)
         up_interfaces = re.findall('([A-Za-z0-9-\.]+)\s+Link', board.before)
     num_up = len(up_interfaces)
     if num_up >= 1:
         msg = "%s interfaces are UP: %s." % (num_up, ", ".join(sorted(up_interfaces)))
     else:
         msg = "0 interfaces are UP."
     self.result_message = msg
     assert num_up >= 1
Esempio n. 25
0
 def runTest(self):
     board.sendline("\n/etc/init.d/mcproxy stop")
     board.expect(prompt)
     board.sendline("ps | grep mcproxy")
     board.expect(prompt)
     assert "/usr/sbin/mcproxy" not in board.before
     board.sendline("/etc/init.d/mcproxy start")
     board.sendline("ps | grep mcproxy")
     board.expect("/usr/sbin/mcproxy -f /etc/mcproxy.conf", timeout=5)
     board.expect(prompt)
Esempio n. 26
0
 def recover(self):
     if self.__class__.__name__ == "RootFSBootTest":
         board.close()
         lib.common.test_msg("Unable to boot, skipping remaining tests...")
         return
     try:
         # let user interact with console if test failed
         try:
             board.sendline()
             board.sendline()
             board.interact()
         except:
             pass
         if self.reboot == True and self.reset_after_fail:
             self.boot(self.reflash)
         self.reboot = True
     except Exception as e:
         print("Unable to recover, %s" % e)
         self.assertEqual(1, 0, e)
Esempio n. 27
0
    def runTest(self):
        wlan_iface = wifi_interface(board)
        wlan_security = "wpa2-psk"
        vap_iface = "0"
        if wlan_iface is None:
            self.skipTest("No wifi interfaces detected, skipping..")

        self.config.ssid = randomSSIDName()

        disable_wifi(board)
        uciSetWifiSecurity(board, vap_iface, wlan_security)
        uciSetChannel(board, "0", "153")
        uciSetWifiSSID(board, self.config.ssid)
        enable_wifi(board)

        # verfiy we have an interface here
        if wlan_iface == "ath0":
            board.sendline('iwconfig %s' % wlan_iface)
            board.expect('%s.*IEEE 802.11.*ESSID.*%s' % (wlan_iface, self.config.ssid))
        else:
            board.sendline('iwinfo %s info' % wlan_iface)
            board.expect('%s.*ESSID.*%s' % (wlan_iface, self.config.ssid))
        board.expect(prompt)

        # wait for AP to set rate, which means it's done coming up
        for i in range(20):
            try:
                essid, channel, rate, freq = wifi_get_info(board, wlan_iface)
                info = "Rate = %s Mb/s, Freq = %s Ghz" % (rate, freq)
                time.sleep(5)
                if wlan_iface == "ath0":
                    assert float(rate) > 0
                elif wlan_iface == "wlan0":
                    assert channel > 0
                lib.common.test_msg("%s\n" % info)
                self.result_message = self.__doc__ + " (%s)" % info
            except Exception as e:
                traceback.print_exc(file=sys.stdout)
                if i < 10:
                    pass
            else:
                break
Esempio n. 28
0
    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)
Esempio n. 29
0
def wifi_cycle(board, num_times=5, wlan_iface="ath0"):
    '''Enable and disable wifi some number of times.'''
    if wifi_on(board):
        disable_wifi(board, wlan_iface)
    wifi_name = randomSSIDName()
    board.sendline('uci set wireless.@wifi-iface[0].ssid=%s' % wifi_name)
    board.expect(prompt)
    board.sendline('uci set wireless.@wifi-iface[0].encryption=psk2')
    board.expect(prompt)
    board.sendline('uci set wireless.@wifi-iface[0].key=%s' % randomSSIDName())
    board.expect(prompt)
    board.sendline('echo "7 7 7 7" > /proc/sys/kernel/printk')
    board.expect(prompt)
    for i in range(1, num_times+1):
        enable_wifi(board)
        wait_wifi_up(board, wlan_iface=wlan_iface)
        disable_wifi(board, wlan_iface=wlan_iface)
        print("\n\nEnabled and disabled WiFi %s times." % i)
    board.sendline('echo "1 1 1 7" > /proc/sys/kernel/printk')
    board.expect(prompt)
Esempio n. 30
0
 def runTest(self):
     board.sendline('\nsync; echo 3 > /proc/sys/vm/drop_caches')
     board.expect('echo 3')
     board.expect(prompt, timeout=5)
     # There appears to be a tiny, tiny chance that
     # /proc/meminfo won't exist, so try one more time.
     for i in range(2):
         try:
             board.sendline('cat /proc/meminfo')
             board.expect('MemTotal:\s+(\d+) kB', timeout=5)
             break
         except:
             pass
     mem_total = int(board.match.group(1))
     board.expect('MemFree:\s+(\d+) kB')
     mem_free = int(board.match.group(1))
     board.expect(prompt)
     mem_used = mem_total - mem_free
     self.result_message = 'Used memory: %s MB. Free memory: %s MB.' % (mem_used/1000, mem_free/1000)
     self.logged['mem_used'] = mem_used/1000
Esempio n. 31
0
 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)
Esempio n. 32
0
 def runTest(self):
     board.sendline(
         'rm -f /etc/config/samba; opkg update; opkg install --force-reinstall samba36-server samba36-client kmod-fs-cifs'
     )
     board.expect('Configuring samba36-server')
     board.expect(prompt)
     board.sendline(
         'mkdir -p /tmp/samba; chmod a+rwx /tmp/samba; rm -rf /tmp/samba/*')
     board.expect(prompt)
     board.sendline(
         'uci set samba.@samba[0].homes=0; uci delete samba.@sambashare[0]; uci add samba sambashare; uci set samba.@sambashare[0]=sambashare; uci set samba.@sambashare[0].name="boardfarm-test"; uci set samba.@sambashare[0].path="/tmp/samba"; uci set samba.@sambashare[0].read_only="no"; uci set samba.@sambashare[0].guest_ok="yes"; uci commit samba'
     )
     board.expect(prompt)
     board.sendline('/etc/init.d/samba restart')
     board.sendline('smbclient -N -L 127.0.0.1')
     board.expect('boardfarm-test')
     board.expect(prompt)
     lan.sendline('smbclient -N -L %s' %
                  board.get_interface_ipaddr(board.lan_iface))
     lan.expect('boardfarm-test')
     lan.expect(prompt)
     lan.sendline(
         'mkdir -p /mnt/samba; mount -o guest //%s/boardfarm-test /mnt/samba'
         % board.get_interface_ipaddr(board.lan_iface))
     lan.expect(prompt)
     lan.sendline('echo boardafarm-testing-string > /mnt/samba/test')
     lan.expect(prompt)
     lan.sendline('umount /mnt/samba')
     lan.expect(prompt)
     board.sendline('cat /tmp/samba/test')
     board.expect('boardafarm-testing-string')
     board.expect(prompt)
    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 eth1 down')
        lan.expect(prompt)

        if not board.has_cmts:
            wan.sendline('ifconfig eth1 down')
            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, 'eth1.*\|\s([0-9]+).*\|'],
                                 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(' '):
                    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()
Esempio n. 34
0
 def recover(self):
     board.sendline('\nmv /etc/config/ulogd.bak /etc/config/ulogd')
     board.expect(prompt)
Esempio n. 35
0
 def recover(self):
     board.sendcontrol('c')
     lan.sendcontrol('c')
     board.sendline('rm -f /www/deleteme.txt')
     board.expect(prompt)
Esempio n. 36
0
 def runTest(self):
     board.sendline('\nping -c2 8.8.8.8')
     board.expect('2 packets received', timeout=10)
     board.expect(prompt)
Esempio n. 37
0
 def runTest(self):
     board.sendline('\ndf -k')
     board.expect('Filesystem', timeout=5)
     board.expect(prompt)
     board.sendline('du -k | grep -v ^0 | sort -n | tail -20')
     board.expect(prompt)
Esempio n. 38
0
 def runTest(self):
     board.sendline('\ncat /tmp/dhcp.leases')
     board.expect('leases')
     board.expect(prompt)
Esempio n. 39
0
 def runTest(self):
     board.sendline('\ncp /etc/config/ulogd /etc/config/ulogd.bak')
     board.expect(prompt)
     board.sendline('echo boardfarmteststring > /etc/config/ulogd')
     board.expect(prompt)
     board.sendline('touch -r /etc/config/ulogd.bak /etc/config/ulogd')
     board.expect(prompt)
     board.sendline(
         'sed -i "s|/etc/config/ulogd .*|/etc/config/ulogd 48b1215c8d419a33818fc1f42c118aed|" /usr/lib/opkg/status'
     )
     board.expect(prompt)
     board.sendline('opkg install --force-reinstall ulogd')
     board.expect(prompt)
     board.sendline('grep boardfarmteststring /etc/config/ulogd || uname')
     board.expect('Linux')
     board.sendline('\nmv /etc/config/ulogd.bak /etc/config/ulogd')
     board.expect(prompt)
Esempio n. 40
0
    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 self.tests is None:
            self.skipTest("No tests defined!")

        if self.cdrouter_server is None:
            self.skipTest("No cdrouter server specified")

        for d in [wan, lan]:
            d.sendline('ifconfig eth1 down')
            d.expect(prompt)

        board.sendcontrol('c')
        board.expect(prompt)

        # TODO: make host configurable in bft config?
        c = CDRouter(self.cdrouter_server)

        # If alt mac addr is specified in config, use that..
        # This is used when a CMTS for example is placed between
        # the device under test and the WAN
        wandutmac = None
        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

            if d is not None:
                d.vlan = getattr(device, 'vlan', 0)
            if d.vlan == 0:
                d.sendline('cat /proc/net/vlan/config')
                d.expect('eth1.*\|\s([0-9]+).*\|')
                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.config.cdrouter_wan_iface
        contents=contents +"""
testvar wanDutMac """ + wandutmac

        if wan.vlan != 0:
            contents=contents + """
testvar wanVlanId """ + wan.vlan

        contents=contents + """
testvar lanInterface """ + self.config.cdrouter_lan_iface

        if lan.vlan != 0:
            contents=contents + """
testvar lanVlanId """ + lan.vlan

        if self.config.cdrouter_config is not None:
            contents=contents + "\n" + "".join(open(self.config.cdrouter_config, 'r').readlines())

        if self.extra_config:
            contents=contents + "\n" + self.extra_config.replace(',', '\n')

        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))

        try:
            board.sendline('reboot')
            board.expect('reboot: Restarting system')
        except:
            board.reset()

        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: make this board specific?
                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)
                    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()
Esempio n. 41
0
 def recover(self):
     board.sendline('\nrm -f uboot_vars')
     board.expect(prompt)
Esempio n. 42
0
 def runTest(self):
     board.sendline('\ncurl -s http://127.0.0.1/cgi-bin/luci | head -15')
     board.expect('cgi-bin/luci')
     board.expect(prompt)
     assert 'traceback' not in board.before
Esempio n. 43
0
 def runTest(self):
     board.sendline('tc qdisc del dev eth0 root')
     i = board.expect(['RTNETLINK answers: No such file or directory'] +
                      board.prompt)
     if i == 0:
         raise Exception("Failed to delete all qdiscs")
Esempio n. 44
0
    def runTest(self):
        board.sendline('uci set network.lan.ifname="%s %s"' %
                       (board.wan_iface, board.lan_iface))
        board.expect(prompt)
        board.sendline('uci set firewall.@defaults[0]=defaults')
        board.expect(prompt)
        board.sendline('uci set firewall.@defaults[0].input=ACCEPT')
        board.expect(prompt)
        board.sendline('uci set firewall.@defaults[0].output=ACCEPT')
        board.expect(prompt)
        board.sendline('uci set firewall.@defaults[0].syn_flood=1')
        board.expect(prompt)
        board.sendline('uci set firewall.@defaults[0].forward=ACCEPT')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[0]=zone')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[0].name=lan')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[0].network=lan')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[0].input=ACCEPT')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[0].output=ACCEPT')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[0].forward=ACCEPT')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[1]=zone')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[1].name=wan')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[1].network=wan')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[1].output=ACCEPT')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[1].mtu_fix=1')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[1].input=ACCEPT')
        board.expect(prompt)
        board.sendline('uci set firewall.@zone[1].forward=ACCEPT')
        board.expect(prompt)
        board.sendline('uci commit')
        board.expect(prompt)
        board.network_restart()
        board.firewall_restart()

        lan.sendline('ifconfig eth1 192.168.0.2')
        lan.expect(prompt)
Esempio n. 45
0
 def runTest(self):
     board.sendline('\nping -c2 www.google.com')
     board.expect('2 packets received', timeout=10)
     board.expect(prompt)
Esempio n. 46
0
 def runTest(self):
     board.sendline('\nlogread')
     board.expect('logread')
     board.expect('OpenWrt', timeout=5)
     board.expect(prompt)
Esempio n. 47
0
    def runTest(self):
        legacy = hasattr(self.config, "wan_device")
        lib.common.test_msg(
            "Press Ctrl-] to stop interaction and return to menu")
        board.sendline()
        try:
            board.interact()
        except:
            return

        while True:
            print("\n\nCurrent station")
            print("  Board console: %s" % self.config.board.get('conn_cmd'))
            if legacy:
                self.print_legacy_devices()
            self.print_dynamic_devices()
            print('Pro-tip: Increase kernel message verbosity with\n'
                  '    echo "7 7 7 7" > /proc/sys/kernel/printk')
            print("Menu")
            i = 2
            if board.consoles is None:
                print("  1: Enter console")
                i += 1
            else:
                i = 1
                for c in board.consoles:
                    print("  %s: Enter console" % i)
                    i += 1
            if legacy:
                print("  %s: Enter wan console" % i)
                i += 1
                print("  %s: Enter lan console" % i)
                i += 1
                print("  %s: Enter wlan console" % i)
                i += 1

            print("  %s: List all tests" % i)
            i += 1
            print("  %s: Run test" % i)
            i += 1
            print("  %s: Reset board" % i)
            i += 1
            print("  %s: Enter interactive python shell" % i)
            i += 1
            if len(self.config.devices) > 0:
                print("  Type a device name to connect: %s" %
                      self.config.devices)
            print("  x: Exit")
            key = raw_input("Please select: ")

            if key in self.config.devices:
                d = getattr(self.config, key)
                d.interact()

            i = 1
            for c in board.consoles:
                if key == str(i):
                    c.interact()
                i += 1

            if legacy:
                if key == str(i):
                    wan.interact()
                    continue
                i += 1

                if key == str(i):
                    lan.interact()
                    continue
                i += 1

                if key == str(i):
                    wlan.interact()
                    continue
                i += 1

            if key == str(i):
                try:
                    # re import the tests
                    test_files = glob.glob(os.path.dirname(__file__) + "/*.py")
                    for x in sorted([
                            os.path.basename(f)[:-3] for f in test_files
                            if not "__" in f
                    ]):
                        exec("from %s import *" % x)

                    if 'BFT_OVERLAY' in os.environ:
                        for o in os.environ['BFT_OVERLAY'].split(' '):
                            o = os.path.realpath(o)
                            test_files = glob.glob(o + "/tests/*.py")
                            for x in sorted([
                                    os.path.basename(f)[:-3]
                                    for f in test_files if not "__" in f
                            ]):
                                exec("from %s import *" % x)
                except:
                    print("Unable to re-import tests!")
                else:
                    # list what we can re-run
                    rfs_boot = rootfs_boot.RootFSBootTest
                    print("Available tests:")
                    print_subclasses(rfs_boot)
                continue
            i += 1

            if key == str(i):
                try:
                    # re import the tests
                    test_files = glob.glob(os.path.dirname(__file__) + "/*.py")
                    for x in sorted([
                            os.path.basename(f)[:-3] for f in test_files
                            if not "__" in f
                    ]):
                        exec("from %s import *" % x)

                    if 'BFT_OVERLAY' in os.environ:
                        for o in os.environ['BFT_OVERLAY'].split(' '):
                            overlay = os.path.realpath(overlay)
                            test_files = glob.glob(o + "/tests/*.py")
                            for x in sorted([
                                    os.path.basename(f)[:-3]
                                    for f in test_files if not "__" in f
                            ]):
                                exec("from %s import *" % x)
                except:
                    print("Unable to re-import tests!")
                else:
                    # TODO: use an index instead of test name
                    print("Type test to run: ")
                    test = sys.stdin.readline()

                    #try:
                    board.sendline()
                    # default are 1 1 1 7
                    board.set_printk()
                    board.expect(prompt)
                    try:
                        t = eval(test)
                        reload(sys.modules[t.__module__])
                        cls = t(self.config)
                        lib.common.test_msg(
                            "\n==================== Begin %s ===================="
                            % cls.__class__.__name__)
                        cls.testWrapper()
                        lib.common.test_msg(
                            "\n==================== End %s ======================"
                            % cls.__class__.__name__)
                        board.sendline()
                    except:
                        lib.common.test_msg(
                            "Failed to find and/or run test, continuing..")
                        continue
                    #except:
                    #    print("Unable to (re-)run specified test")

                continue
            i += 1

            if key == str(i):
                board.reset()
                print("Press Ctrl-] to stop interaction and return to menu")
                board.interact()
                continue
            i += 1

            if key == str(i):
                print("Enter python shell, press Ctrl-D to exit")
                try:
                    from IPython import embed
                    embed()
                except:
                    try:
                        import readline  # optional, will allow Up/Down/History in the console
                        import code
                        vars = globals().copy()
                        vars.update(locals())
                        shell = code.InteractiveConsole(vars)
                        shell.interact()
                    except:
                        print("Unable to spawn interactive shell!")
                continue
            i += 1

            if key == "x":
                break
Esempio n. 48
0
    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)

        tftp_device.start_tftp_server()

        if lan:
            lan.configure(kind="lan_device")

        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()
Esempio n. 49
0
    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)

        dhcp_started = False

        # 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()
                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, 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)

        # TODO: we should do some of this for other types of provisioners
        # TODO: this should probably move into a DEVICE specific helper function
        # so all the correct logic can be encoded there
        if prov is not None and 'debian-isc-provisioner' in prov.model:
            start_time = time.time()
            time_for_provisioning = 120

            wan_ipv4 = False
            wan_ipv6 = False
            erouter_ipv4 = False
            erouter_ipv6 = False
            mta_ipv4 = False
            mta_ipv6 = False # Never possible on any boards?

            cm_configmode = board.cm_cfg.cm_configmode

            if cm_configmode == 'bridge':
                # TODO
                pass
            if cm_configmode == 'ipv4':
                wan_ipv4 = erouter_ipv4 = True
                # TODO: this fails if we have dhcp6 running, why?
                #mta_ipv4 = True # TODO: is this true?
            if cm_configmode == 'dslite':
                # TODO
                pass
            if cm_configmode == 'dual-stack':
                wan_ipv4 = erouter_ipv4 = True
                wan_ipv6 = erouter_ipv6 = True
                # TODO: mta does not come up in this mode now, to b e fixed
            # TODO: no ipv6 only TLV?!?

            while (time.time() - start_time < time_for_provisioning):
                try:
                    if wan_ipv4:
                        valid_ipv4(board.get_interface_ipaddr(board.wan_iface))
                    if wan_ipv6:
                        valid_ipv6(board.get_interface_ip6addr(board.wan_iface))

                    if hasattr(board, 'erouter_iface'):
                        if erouter_ipv4:
                            valid_ipv4(board.get_interface_ipaddr(board.erouter_iface))
                        if erouter_ipv6:
                            valid_ipv6(board.get_interface_ip6addr(board.erouter_iface))

                    if hasattr(board, 'mta_iface'):
                        if mta_ipv4:
                            valid_ipv4(board.get_interface_ipaddr(board.mta_iface))
                        if mta_ipv6:
                            valid_ipv6(board.get_interface_ip6addr(board.mta_iface))

                    # if we get this far, we have all IPs and can exit while loop
                    break
                except KeyboardInterrupt:
                    raise
                except:
                    if time.time() - start_time < time_for_provisioning:
                        raise

        # 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, client=lan, client_name="br-lan"):
        if not board.check_perf():
            self.result_message = 'perf not in image. skipping test.'
            self.skipTest('perf not installed, skipping test')

        wan_iface = board.get_wan_iface()

        # TODO: remove these and run separate tests
        board.sendline('streamboost disable')
        board.expect(prompt)
        board.sendline('rmmod ecm')
        board.expect(prompt)

        self.pkt_size = 200
        self.conns = 5
        self.test_time = 60

        # work around so we can call from connect testsuite (without reboot)
        board.get_wan_iface()

        self.run_iperf_server(wan)
        self.run_iperf(client,
                       opts="-t %s -P %s -N -m -M %s" %
                       (self.test_time + 10, self.conns, self.pkt_size))

        # run perf wrapper command
        board.check_output_perf("sar -u -n DEV 100000 1", self.perf_events())

        speed = self.parse_iperf(client,
                                 connections=self.conns,
                                 t=self.test_time)
        self.kill_iperf(wan)
        lib.common.test_msg("\n speed was %s Mbit/s" % speed)

        # extract cpu and packet info
        board.sendcontrol('c')
        idle, wan_pps, client_pps = board.parse_sar_iface_pkts(
            wan_iface, client_name)
        lib.common.test_msg("\n idle cpu: %s" % idle)
        lib.common.test_msg("client pps = %s" % client_pps)
        lib.common.test_msg("wan pps = %s" % wan_pps)

        if client_name is not None:
            total_pps = min(wan_pps, client_pps)
        else:
            total_pps = wan_pps
        lib.common.test_msg("\n using total pps = %s" % total_pps)

        wan_pkts = wan_pps * self.test_time

        if client_name is not None:
            client_pkts = client_pps * self.test_time
        else:
            client_pkts = 'n/a'

        lib.common.test_msg("\n client pkts = %s wan pkts = %s" %
                            (client_pkts, wan_pkts))

        if client_name is not None:
            total_pkts = min(client_pkts, wan_pkts)
        else:
            total_pkts = wan_pkts

        lib.common.test_msg("\n using total packets = %s" % total_pkts)
        self.logged['total_pkts'] = total_pkts

        # extract perf info
        perf_msg = ""

        results = board.parse_perf(self.perf_events())
        for p in results:
            p['value_per_pkt'] = p['value'] / total_pkts
            lib.common.test_msg("\n %s = %s (per pkt = %s)" % \
                    (p['name'], p['value'], p['value_per_pkt']))
            perf_msg += ", %s=%.2f" % (p['sname'], p['value_per_pkt'])

            # restore legacy names
            if p['name'] == "instructions":
                name = "insn_per_pkt"
            elif p['name'] == "cycles":
                name = "cycles_per_pkt"
            elif p['name'] == "dcache_misses":
                name = "dcache_miss_per_pkt"
            elif p['name'] == "icache_misses":
                name = "icache_miss_per_pkt"

            self.logged[name] = float(p['value_per_pkt'])

        extra_msg = self.extra(results)

        self.result_message = "TP=%.2f Mbits/s IDLE=%.2f, PPS=%.2f%s%s" % \
            (speed, idle, total_pps, perf_msg, extra_msg)

        self.logged['test_time'] = self.test_time
Esempio n. 51
0
 def runTest(self):
     board.sendline('\ncp /etc/config/ulogd /etc/config/ulogd.bak')
     board.expect(prompt)
     board.sendline('echo boardfarmteststring > /etc/config/ulogd')
     board.expect(prompt)
     board.sendline('touch -r /etc/config/ulogd.bak /etc/config/ulogd')
     board.expect(prompt)
     board.sendline(
         'sed -i "s|/etc/config/ulogd .*|/etc/config/ulogd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|" /usr/lib/opkg/status'
     )
     board.expect(prompt)
     board.sendline('opkg install --force-reinstall ulogd')
     board.expect(
         'Existing conffile /etc/config/ulogd is different from the conffile in the new package'
     )
     board.expect(prompt)
     board.sendline('grep boardfarmteststring /etc/config/ulogd && uname')
     board.expect('Linux')
     board.sendline('\nmv /etc/config/ulogd.bak /etc/config/ulogd')
     board.expect(prompt)
Esempio n. 52
0
 def runTest(self):
     board.sendline('\nps | grep -v grep | grep http')
     board.expect('uhttpd')
     board.expect(prompt)