def runTest(self):
     num_conn = 5000
     # Wan device: Create small file in web dir
     fname = 'small.txt'
     cmd = '\nhead -c 10000 /dev/urandom > /var/www/%s' % fname
     wan.sendline(cmd)
     wan.expect(prompt)
     # Lan Device: download small file a lot
     concurrency = 25
     url = 'http://192.168.0.1/%s' % fname
     # Start CPU monitor
     board.sendline('\nmpstat -P ALL 10000 1')
     # Lan Device: download small file a lot
     lan.sendline('\nab -dn %s -c %s %s' % (num_conn, concurrency, url))
     lan.expect('Benchmarking', timeout=5)
     lan.expect('Requests per second:\s+(\d+)')
     reqs_per_sec = int(lan.match.group(1))
     lan.expect(prompt)
     # Stop CPU monitor
     board.sendcontrol('c')
     board.expect('Average:\s+all(\s+[0-9]+.[0-9]+){10}\r\n')
     idle_cpu = float(board.match.group(1))
     avg_cpu = 100 - float(idle_cpu)
     board.expect(prompt)
     msg = "ApacheBench measured %s connections/second, CPU use = %s%%." % (
         reqs_per_sec, avg_cpu)
     self.result_message = msg
     time.sleep(5)  # Give router a few seconds to recover
 def 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
Пример #3
0
 def recover(self, client=wan, server=lan):
     board.sendcontrol('c')
     board.sendcontrol('c')
     client.sendcontrol('c')
     client.sendcontrol('c')
     client.expect(prompt)
     self.kill_iperf(server)
Пример #4
0
    def runTest(self):
        board.sendcontrol('c')
        board.expect(board.prompt)
        board.sendline('logread -f &')
        board.expect(board.prompt)

        lan.sendline('rm -rf Fedora*')
        lan.expect(lan.prompt)
        # TODO: apt-get install bittornado
        for i in range(10):
            lan.sendline(
                "btdownloadheadless 'https://torrent.fedoraproject.org/torrents/Fedora-Games-Live-x86_64-28_Beta.torrent'"
            )
            lan.expect('saving:')
            done = False
            while not done:
                lan.expect(pexpect.TIMEOUT, timeout=1)  # flush buffer
                if 0 == lan.expect(
                    ['time left:      Download Succeeded!', pexpect.TIMEOUT],
                        timeout=10):
                    print("Finished, restarting....")
                    done = True
                board.expect(pexpect.TIMEOUT, timeout=5)
                board.sendline()  # keepalive
            lan.sendcontrol('c')
            lan.sendcontrol('c')
            lan.sendcontrol('c')
            lan.expect(lan.prompt)
            lan.sendline('rm -rf Fedora*')
            lan.expect(lan.prompt)
Пример #5
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
Пример #6
0
    def runTest(self, client=wan, server=lan):
        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_reverse(node=server))
        if mpstat_present:
            board.sendline('mpstat -P ALL 10000 1')
            board.expect('Linux')
        self.run_iperf(client, opts=opts, target=self.reverse_ip())
        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 = 'iPerf from 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
Пример #7
0
 def recover(self, client=wan, server=lan):
     board.sendcontrol('c')
     board.sendcontrol('c')
     client.sendcontrol('c')
     client.sendcontrol('c')
     client.expect(prompt)
     self.kill_iperf(server)
Пример #8
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
Пример #9
0
 def runTest(self):
     board.sendline('\ntop -b -n 1')
     board.expect(pexpect.TIMEOUT, timeout=2)
     try:
         board.expect(prompt, timeout=2)
     except:
         # some versions of top do not support '-n'
         # must CTRL-C to kill top
         board.sendcontrol('c')
Пример #10
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')
Пример #11
0
 def recover(self):
     lan.sendcontrol('c')
     lan.expect(lan.prompt)
     lan.sendline('rm -rf Fedora*')
     lan.expect(lan.prompt)
     board.sendcontrol('c')
     board.expect(board.prompt)
     board.sendline('fg')
     board.sendcontrol('c')
     board.expect(board.prompt)
Пример #12
0
 def recover(self, node1=lan, node2=wan):
     board.sendcontrol('c')
     board.sendcontrol('c')
     node1.sendcontrol('c')
     node1.sendcontrol('c')
     node1.expect(prompt)
     node2.sendcontrol('c')
     node2.sendcontrol('c')
     node2.expect(prompt)
     self.kill_iperf(node1)
     self.kill_iperf(node2)
Пример #13
0
 def recover(self, node1=lan, node2=wan):
     board.sendcontrol('c')
     board.sendcontrol('c')
     node1.sendcontrol('c')
     node1.sendcontrol('c')
     node1.expect(prompt)
     node2.sendcontrol('c')
     node2.sendcontrol('c')
     node2.expect(prompt)
     self.kill_iperf(node1)
     self.kill_iperf(node2)
Пример #14
0
 def runTest(self):
     lan.sendline('nmap -sS -A -v -p 1-10000 %s' %
                  board.get_interface_ipaddr(board.lan_iface))
     lan.expect('Starting Nmap')
     for i in range(12):
         if 0 == lan.expect(['Nmap scan report', pexpect.TIMEOUT],
                            timeout=100):
             break
         board.sendcontrol('c')
         board.expect(prompt)
     lan.expect(prompt, timeout=60)
     open_ports = re.findall("(\d+)/tcp\s+open", lan.before)
     msg = "Found %s open TCP ports on LAN interface: %s." % \
         (len(open_ports), ", ".join(open_ports))
     self.result_message = msg
Пример #15
0
    def runTest(self):
        super(NetperfTest, self).runTest()

        board.arm.sendline('mpstat -P ALL 30 1')
        board.arm.expect('Linux')

        speed = self.run_netperf(lan, "%s -c -C -l 30" % wan.gw)

        board.sendcontrol('c')
        board.expect('Average.*idle\r\nAverage:\s+all(\s+[0-9]+.[0-9]+){9}\r\n',timeout=60)
        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.kill_netserver(wan)

        self.result_message = "Setup Netperf and Ran Throughput (Speed = %s 10^6bits/sec, CPU = %s)" % (speed, avg_cpu)
Пример #16
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()
Пример #17
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()
Пример #18
0
    def recover(self, node1=lan, node2=wan):
        lib.common.test_msg("sending board ctrl-c")
        board.sendcontrol('c')
        board.sendcontrol('c')
        board.expect(prompt)
        lib.common.test_msg("sending node1 ctrl-c")
        node1.sendcontrol('c')
        node1.sendcontrol('c')
        node1.expect(prompt)
        lib.common.test_msg("sending node2ctrl-c")
        node2.sendcontrol('c')
        node2.sendcontrol('c')
        node2.expect(prompt)
        lib.common.test_msg("killing iperf on node1")
        self.kill_iperf(node1)
        lib.common.test_msg("killing iperf on node2")
        self.kill_iperf(node2)

        board.sendline('cat /proc/net/nf_conntrack | wc -l')
        board.expect(prompt)
        try:
            board.sendline('cat /proc/devices | grep sfe')
            board.expect('cat /proc/devices | grep sfe')
            board.expect('([0-9]+) sfe_ipv4')
            char_dev = board.match.group(1).strip()
            board.expect(prompt)
            board.sendline('mknod /dev/sfe c %s 0' % char_dev)
            board.expect(prompt)
            board.sendline('cat /dev/sfe')
            board.expect(prompt)
        except:
            pass
        board.sendline('ifconfig; route')
        board.expect_exact('ifconfig; route')
        board.expect(prompt)
        node1.sendline('ifconfig; route')
        node1.expect_exact('ifconfig; route')
        node1.expect(prompt)
        node2.sendline('ifconfig; route')
        node2.expect_exact('ifconfig; route')
        node2.expect(prompt)
Пример #19
0
    def recover(self, node1=lan, node2=wan):
        lib.common.test_msg("sending board ctrl-c")
        board.sendcontrol('c')
        board.sendcontrol('c')
        board.expect(prompt)
        lib.common.test_msg("sending node1 ctrl-c")
        node1.sendcontrol('c')
        node1.sendcontrol('c')
        node1.expect(prompt)
        lib.common.test_msg("sending node2ctrl-c")
        node2.sendcontrol('c')
        node2.sendcontrol('c')
        node2.expect(prompt)
        lib.common.test_msg("killing iperf on node1")
        self.kill_iperf(node1)
        lib.common.test_msg("killing iperf on node2")
        self.kill_iperf(node2)

        board.sendline('cat /proc/net/nf_conntrack | wc -l')
        board.expect(prompt)
        try:
            board.sendline('cat /proc/devices | grep sfe')
            board.expect('cat /proc/devices | grep sfe')
            board.expect('([0-9]+) sfe_ipv4')
            char_dev = board.match.group(1).strip()
            board.expect(prompt)
            board.sendline('mknod /dev/sfe c %s 0' % char_dev)
            board.expect(prompt)
            board.sendline('cat /dev/sfe')
            board.expect(prompt)
        except:
            pass
        board.sendline('ifconfig; route')
        board.expect_exact('ifconfig; route')
        board.expect(prompt)
        node1.sendline('ifconfig; route')
        node1.expect_exact('ifconfig; route')
        node1.expect(prompt)
        node2.sendline('ifconfig; route')
        node2.expect_exact('ifconfig; route')
        node2.expect(prompt)
Пример #20
0
    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()
Пример #21
0
    def runTest(self, node1=lan, node2=wan, firewall=True):
        mpstat_present = self.mpstat_ok()

        if firewall:
            self.run_iperf_server(node1, opts=self.server_opts_reverse(node1))
        else:
            self.run_iperf_server(node1, opts=self.server_opts_forward())
        self.run_iperf_server(node2, opts=self.server_opts_forward())
        board.sendline('cat /proc/net/nf_conntrack | wc -l')
        board.expect(prompt)
        # 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 recover(self):
     board.sendcontrol('c')
     board.expect(prompt)
     lan.sendcontrol('c')
     time.sleep(2)  # Give router a few seconds to recover
Пример #23
0
    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
Пример #24
0
 def recover(self):
     board.sendcontrol('c')
     lan.sendcontrol('c')
     board.sendline('rm -f /www/deleteme.txt')
     board.expect(prompt)
Пример #25
0
    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
Пример #26
0
 def recover(self):
     board.sendcontrol('c')
Пример #27
0
 def recover(self):
     board.sendcontrol('c')
     lan.sendcontrol('c')
     board.sendline('rm -f /www/deleteme.txt')
     board.expect(prompt)
Пример #28
0
 def recover(self):
     board.sendcontrol('c')
Пример #29
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 'cdrouter_wan_iface' in self.config.board:
            self.cdrouter_wan_iface = self.config.board['cdrouter_wan_iface']
        else:
            self.cdrouter_wan_iface = self.config.cdrouter_wan_iface

        if 'cdrouter_lan_iface' in self.config.board:
            self.cdrouter_lan_iface = self.config.board['cdrouter_lan_iface']
        else:
            self.cdrouter_lan_iface = self.config.cdrouter_lan_iface

        if self.tests is None:
            self.skipTest("No tests defined!")

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

        lan.sendline('ifconfig %s down' % lan.iface_dut)
        lan.expect(prompt)

        if not board.has_cmts:
            wan.sendline('ifconfig %s down' % wan.iface_dut)
            wan.expect(prompt)

        c = CDRouter(self.cdrouter_server)

        try:
            board.sendcontrol('c')
            board.expect(prompt)
            board.sendline('reboot')
            board.expect('reboot: Restarting system')
        except:
            board.reset()
        board.wait_for_linux()
        board.wait_for_network()

        # Add extra board specific delay
        board.expect(pexpect.TIMEOUT,
                     timeout=getattr(board, 'cdrouter_bootdelay', 0))

        # If alt mac addr is specified in config, use that..
        # CMTS = we route so no wan mac is used
        # if we route, we need to add routes
        wandutmac = None
        if board.has_cmts and wan.wan_cmts_provisioner:
            # TODO: there are more missing ones CDrouter expects
            wan.sendline('ip route add 200.0.0.0/8 via 192.168.3.2')
            wan.expect(prompt)
        elif not wan.static_ip:
            for device in self.config.board['devices']:
                if device['name'] == 'wan':
                    if 'alt_macaddr' in device:
                        wandutmac = device['alt_macaddr']
                    break

            # Otherwise grab this from the device interface
            if wandutmac is None:
                board.sendline('ifconfig %s' % board.wan_iface)
                board.expect('([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})')
                wandutmac = board.match.group()
                board.expect(prompt)

            print("Using %s for WAN mac address" % wandutmac)

        lan.vlan = wan.vlan = 0
        for device in self.config.board['devices']:
            d = None
            if device['name'] == 'wan':
                d = wan
            elif device['name'] == 'lan':
                d = lan
            else:
                continue

            if d is not None:
                d.vlan = getattr(device, 'vlan', 0)
            if d.vlan == 0:
                d.sendline('cat /proc/net/vlan/config')
                d.expect_exact('cat /proc/net/vlan/config')
                if 0 == d.expect(
                    [pexpect.TIMEOUT,
                     '%s.*\|\s([0-9]+).*\|' % d.iface_dut],
                        timeout=5):
                    d.vlan = 0
                else:
                    d.vlan = d.match.group(1)
                d.expect(prompt)

        print("Using %s for WAN vlan" % wan.vlan)
        print("Using %s for LAN vlan" % lan.vlan)

        # TODO: move wan and lan interface to bft config?
        contents = """
testvar wanInterface """ + self.cdrouter_wan_iface
        if wandutmac is not None:
            contents = contents + """
testvar wanDutMac """ + wandutmac

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

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

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

        def add_cdrouter_config(config):
            cdr_conf = None

            # TODO: make a generic helper to search path and overlays
            if os.path.isfile(config):
                cdr_conf = open(config, 'r').readlines()
            elif 'BFT_OVERLAY' in os.environ:
                for p in os.environ['BFT_OVERLAY'].split(' '):
                    p = os.path.realpath(p)
                    try:
                        cdr_conf = open(os.path.join(p, config),
                                        'r').readlines()
                    except:
                        continue
                    else:
                        break

            return "\n" + "".join(cdr_conf)

        # Take config from overall config, but fallback to board config
        if self.config.cdrouter_config is not None:
            contents = contents + add_cdrouter_config(
                self.config.cdrouter_config)
        elif board.cdrouter_config is not None:
            contents = contents + add_cdrouter_config(board.cdrouter_config)

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

        if board.has_cmts:
            for i in range(5):
                try:
                    wan_ip = board.get_interface_ipaddr(board.erouter_iface)
                except:
                    board.expect(pexpect.TIMEOUT, timeout=15)
                    continue
                else:
                    if i == 4:
                        raise Exception("Failed to get erouter ip address")
                    break

            # TODO: mask from config? wanNatIp vs. wanIspAssignGateway?
            contents=contents + """
testvar wanMode static
testvar wanIspIp %s
testvar wanIspGateway %s
testvar wanIspMask 255.255.255.0
testvar wanIspAssignIp %s
testvar wanNatIp %s
testvar IPv4HopCount %s
testvar lanDnsServer %s
testvar wanDnsServer %s""" % (self.config.board['cdrouter_wanispip'], \
                              self.config.board['cdrouter_wanispgateway'], \
                              wan_ip, wan_ip, \
                              self.config.board['cdrouter_ipv4hopcount'], \
                              board.get_dns_server(), \
                              board.get_dns_server_upstream())

        print("Using below for config:")
        print(contents)
        print("#######################")

        config_name = "bft-automated-job-%s" % str(time.time()).replace(
            '.', '')
        cfg = c.configs.create(Config(name=config_name, contents=contents))

        p = c.packages.create(
            Package(name=config_name, testlist=self.tests, config_id=cfg.id))

        self.start_time = time.time()
        j = c.jobs.launch(Job(package_id=p.id))

        while j.result_id is None:
            if (time.time() - self.start_time) > 300:
                # delete job if it fails to start
                c.jobs.delete(j.id)
                raise Exception("Failed to start CDrouter job")

            board.expect(pexpect.TIMEOUT, timeout=1)
            j = c.jobs.get(j.id)

        print('Job Result-ID: {0}'.format(j.result_id))

        self.job_id = j.result_id
        self.results = c.results
        unpaused = False
        end_of_start = False
        no_more_pausing = False
        while True:
            r = c.results.get(j.result_id)
            print(r.status)

            # we are ready to go from boardfarm reset above
            if r.status == "paused" and unpaused == False:
                c.results.unpause(j.result_id)
                unpaused = True
                board.expect(pexpect.TIMEOUT, timeout=1)
                c.results.pause(j.result_id, when="end-of-test")
                end_of_start = True
                continue

            if r.status == "paused" and end_of_start == True:
                end_of_start = False
                # TODO: do we need this anymore? we have board specific cdrouter_bootdelay
                board.expect(pexpect.TIMEOUT, timeout=60)
                c.results.unpause(j.result_id)
                board.expect(pexpect.TIMEOUT, timeout=1)
                no_more_pausing = True
                continue

            if no_more_pausing and r.status == "paused":
                print("Error: test is still paused")
                c.results.stop(j.result_id)
                break

            if r.status != "running" and r.status != "paused":
                break

            board.expect(pexpect.TIMEOUT, timeout=5)

        print(r.result)
        self.result_message = r.result.encode('ascii', 'ignore')
        # TODO: results URL?
        elapsed_time = time.time() - self.start_time
        print("Test took %s" %
              time.strftime("%H:%M:%S", time.gmtime(elapsed_time)))

        summary = c.results.summary_stats(j.result_id)

        self.result_message += " (Failed= %s, Passed = %s, Skipped = %s)" \
                % (summary.result_breakdown.failed, \
                   summary.result_breakdown.passed, \
                   summary.result_breakdown.skipped)

        for test in summary.test_summaries:
            self.logged[test.name] = vars(test)

            if str(test.name) not in ["start", "final"]:
                from lib.common import TestResult
                try:
                    grade_map = {
                        "pass": "******",
                        "fail": "FAIL",
                        "skip": "SKIP"
                    }[test.result]
                    tr = TestResult(test.name, grade_map, test.description)
                    if test.started is not None:
                        tr.start_time = test.started
                        tr.stop_time = test.started + test.duration
                    else:
                        tr.elapsed_time = test.duration
                    self.subtests.append(tr)
                except:
                    continue

            # TODO: handle skipped tests

            try:
                metric = c.results.get(result_id, test.name, "bandwidth")
                print(vars(metric))
                # TODO: decide how to export data to kibana
            except:
                # Not all tests have this metric, no other way?
                pass

        assert (r.result == "The package completed successfully")

        self.recover()
Пример #30
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)
                    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()
Пример #31
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()
Пример #32
0
 def recover(self):
     board.sendcontrol("c")
     board.expect(prompt)
     lan.sendcontrol("c")
     time.sleep(2)  # Give router a few seconds to recover