コード例 #1
0
def ubus_call_raw(payload, ipaddr="192.168.1.1"):
    curl_cmd = "curl -d '%s' http://%s/ubus" % (json.dumps(payload), ipaddr)
    lan.sendline(curl_cmd)
    lan.expect("\r\n")
    lan.expect(prompt)

    return json.loads(lan.before)
コード例 #2
0
    def runTest(self):
        install_lighttpd(wan)
        wan.sendline('/etc/init.d/lighttpd start')
        wan.expect(prompt)
        # Wan device: Create small file in web dir
        fname = 'small.txt'
        cmd = '\nhead -c 10000 /dev/urandom > /var/www/%s' % fname
        wan.sendline(cmd)
        wan.expect(prompt)
        # Lan Device: download small file a lot
        # TODO: this is actually a 404 for lighthttpd config issues?
        url = 'http://%s/%s' % (wan.gw, fname)
        # Start CPU monitor
        board.collect_stats(stats=['mpstat'])
        # Lan Device: download small file a lot
        lan.sendline('\nab -dn %s -c %s %s' %
                     (self.num_conn, self.concurrency, url))
        lan.expect('Benchmarking', timeout=5)
        timeout = 0.05 * self.num_conn
        if 0 != lan.expect([
                'Requests per second:\s+(\d+)',
                'apr_socket_recv: Connection reset by peer'
        ],
                           timeout=timeout):
            raise Exception("ab failed to run")
        self.reqs_per_sec = int(lan.match.group(1))
        lan.expect(prompt)

        self.recover()
コード例 #3
0
    def recover(self):
        board.touch()
        lan.sendcontrol('c')
        lan.expect(prompt)
        board.touch()

        print "Copying files from lan to dir = %s" % self.config.output_dir
        lan.sendline('readlink -f $HOME/%s/' % self.dir)
        lan.expect_exact('$HOME/%s/' % self.dir)
        board.touch()
        lan.expect(prompt)
        board.touch()
        fname = lan.before.replace('\n', '').replace('\r', '')
        board.touch()
        rm_r(os.path.join(self.config.output_dir, self.dir))
        scp_from(fname, lan.ipaddr, lan.username, lan.password, lan.port,
                 self.config.output_dir)

        # let board settle down
        board.expect(pexpect.TIMEOUT, timeout=30)
        board.touch()

        board.parse_stats(dict_to_log=self.logged)
        board.touch()
        self.result_message = 'JMeter: DONE, name = %s cpu usage = %s' % (
            self.shortname, self.logged['mpstat'])
コード例 #4
0
 def runTest(self):
     start_port = random.randint(1, 11000)
     lan.sendline('\nnmap --min-rate 100 -sU -p %s-%s 192.168.0.1' %
                  (start_port, start_port + 200))
     lan.expect('Starting Nmap', timeout=5)
     lan.expect('Nmap scan report', timeout=30)
     lan.expect(prompt)
コード例 #5
0
ファイル: ping6.py プロジェクト: RyanLindemanCAE/boardfarm
 def runTest(self):
     lan.sendline("\nping6 -i 0.2 -c 20 4aaa::1")
     lan.expect("PING ")
     lan.expect(" ([0-9]+) received")
     n = int(lan.match.group(1))
     lan.expect(prompt)
     assert n > 0
コード例 #6
0
 def runTest(self):
     lan.sendline('\nping6 -c 20 4aaa::1')
     lan.expect('PING ')
     lan.expect(' ([0-9]+) (packets )?received')
     n = int(lan.match.group(1))
     lan.expect(prompt)
     assert n > 0
コード例 #7
0
 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
コード例 #8
0
    def startSingleUDP(self, mintime=1, maxtime=60):
        while True:
            random_ip = fake_generator.ipv4()
            random_port = randint(1024, 65535)
            if ipaddress.ip_address(random_ip.decode()) not in self.bad_nets:
                if (ipaddress.ip_address(random_ip.decode()), random_port) not in self.all_ips:
                    break
            else:
                print ("Skipping ip addr: %s" % random_ip)
        print("Connecting to %s:%s" % (random_ip, random_port))

        self.all_ips.append((random_ip, random_port))

        # start listners
        wan.sendline('ip addr add %s/32 dev eth1' % random_ip)
        wan.expect(prompt)

        random_rate = randint(1,1024)
        random_size = randint(int(1*random_rate*mintime), int(1024*random_rate*maxtime))

        wan.sendline("nohup socat UDP4-RECVFROM:%s,bind=%s system:'(echo -n d1:ad2:id20:;  head /dev/zero) | pv -L %sk' &" % (random_port, random_ip, random_rate))
        wan.expect(prompt)

        args = (random_size, random_rate, random_ip, random_port)
        lan.sendline("nohup socat system:'(echo -n d1:ad2:id20:;  head -c %s /dev/zero) | pv -L %sk' UDP4-SENDTO:%s:%s &" % args)
        lan.expect(prompt)

        self.all_conns.append(args)
        # size, rate, ip, port
        return args
コード例 #9
0
    def runTest(self):
        #for d in [wan, lan]:
            #d.sendline('apt-get update && apt-get -o Dpkg::Options::="--force-confnew" -y install socat pv')
            #d.expect(prompt)

        max_time = 0
        single_max = 45

        # TODO: query interfaces but this is OK for now
        for i in range(1000):
            # keep long running test alive
            board.sendline()
            board.expect(prompt)
            print ("Starting connection %s" % i)
            sz, rate, ip, port = self.startSingleUDP(maxtime=single_max)
            print ("started UDP to %s:%s sz = %s, rate = %sk" % (ip, port, sz, rate))

            max_time = max(max_time, sz / ( rate * 1024))
            self.check_and_clean_ips()

        print ("waiting max time of %ss" % max_time)

        start = time.time()
        while time.time() - start < max_time + 5:
            lan.sendline('wait')
            lan.expect_exact('wait')
            if 0 != lan.expect([pexpect.TIMEOUT] + prompt, timeout=max_time + 5):
                lan.sendcontrol('c')
                lan.expect(prompt)
                self.check_and_clean_ips()

        self.recover()
コード例 #10
0
ファイル: bittorrent.py プロジェクト: jenkins-ams/boardfarm
    def runTest(self):
        #for d in [wan, lan]:
        #d.sendline('apt-get update && apt-get -o Dpkg::Options::="--force-confnew" -y install socat pv')
        #d.expect(prompt)

        maxtime = 5

        board.get_nf_conntrack_conn_count()

        for i in range(10000):
            sz, rate, ip, port = self.startSingleFlow(maxtime=maxtime)
            print("started UDP to %s:%s sz = %s, rate = %sk" %
                  (ip, port, sz, rate))
            time = sz / (rate * 1024)
            print("time should be ~%s" % time)
            self.check_and_clean_ips()
            lan.sendline('fg')
            lan.expect(prompt, timeout=5)

            board.get_pp_dev().sendline(
                'cat /proc/net/nf_conntrack | grep dst=%s.*dport=%s' %
                (ip, port))
            board.get_pp_dev().expect(prompt)

        board.get_nf_conntrack_conn_count()

        self.recover()
コード例 #11
0
ファイル: ubus.py プロジェクト: fasolens/boardfarm
def ubus_call_raw(payload, ipaddr="192.168.1.1"):
    curl_cmd = "curl -d '%s' http://%s/ubus" % (json.dumps(payload), ipaddr)
    lan.sendline(curl_cmd)
    lan.expect("\r\n")
    lan.expect(prompt)

    return json.loads(lan.before)
コード例 #12
0
 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
コード例 #13
0
    def runTest(self):
        try:
            x, y = config.get_display_backend_size()
            # try to start vnc server
            self.display = Display(backend=config.default_display_backend,
                                   rfbport=config.default_display_backend_port,
                                   visible=0,
                                   size=(x, y))
            self.display.start()

            if "BFT_DEBUG" in os.environ:
                print("Connect to VNC display running on localhost:" +
                      config.default_display_backend_port)
                raw_input("Press any key after connecting to display....")
        except:
            # fallback xvfb
            self.display = Display(visible=0, size=(1366, 768))
            self.display.start()

        try:
            if lan.http_proxy is not None:
                proxy = lan.http_proxy
            elif lan.ipaddr is not None:
                ip = lan.ipaddr
                lan.sendline('cat /proc/net/vlan/config')
                lan.expect('eth1.*\|\s([0-9]+).*\|')
                port = 8000 + int(lan.match.group(1))
                lan.expect(prompt)
                proxy = "%s:%s" % (ip, port)
            else:
                # no proxy, use message below
                assert False
        except Exception as e:
            print e
            raise Exception(
                "No reasonable http proxy found, please add one to the board config"
            )

        print("Using proxy %s" % proxy)
        driver = lib.common.get_webproxy_driver(proxy)
        print("taking ss of http://%s" % board.lan_gateway)
        driver.get("http://%s" % board.lan_gateway)

        # wait for possible redirects to settle down
        url = driver.current_url
        for i in range(10):
            board.expect(pexpect.TIMEOUT, timeout=5)
            if url == driver.current_url:
                break
            url = driver.current_url
        board.expect(pexpect.TIMEOUT, timeout=10)

        # take screenshot
        driver.save_screenshot(self.config.output_dir + os.sep +
                               'lan_portal.png')

        driver.close()

        self.recover()
コード例 #14
0
ファイル: ping6.py プロジェクト: RyanLindemanCAE/boardfarm
 def runTest(self):
     # Make Lan-device ping Wan-Device
     lan.sendline("\nping6 -i 0.2 -c 20 5aaa::6")
     lan.expect("PING ")
     lan.expect(" ([0-9]+) received")
     n = int(lan.match.group(1))
     lan.expect(prompt)
     assert n > 0
コード例 #15
0
ファイル: webgui.py プロジェクト: vburhanov/boardfarm
 def runTest(self):
     url = 'http://192.168.1.1/'
     lan.sendline('\ncurl -v %s' % url)
     lan.expect('<html')
     lan.expect('<body')
     lan.expect('</body>')
     lan.expect('</html>')
     lan.expect(prompt)
コード例 #16
0
ファイル: ping.py プロジェクト: madhavishinde2318/boardfarm
 def runTest(self):
     if not lan:
         msg = 'No LAN Device defined, skipping ping test from LAN.'
         lib.common.test_msg(msg)
         self.skipTest(msg)
     lan.sendline('\nping -c2 8.8.8.8')
     lan.expect('2 received', timeout=10)
     lan.expect(prompt)
コード例 #17
0
 def cleanup_ip(self, ip):
     wan.sendline('ip addr del %s/32 dev eth1' % ip)
     wan.expect_exact('ip addr del %s/32 dev eth1' % ip)
     wan.expect(prompt)
     wan.sendline('pkill -9 -f socat.*bind=%s' % ip)
     wan.expect(prompt)
     lan.sendline('pkill -9 -f socat.*UDP4-SENDTO:%s' % ip)
     lan.expect(prompt)
コード例 #18
0
 def runTest(self):
     if not lan:
         msg = 'No LAN Device defined, skipping ping test from LAN.'
         lib.common.test_msg(msg)
         self.skipTest(msg)
     lan.sendline('\nping -c2 8.8.8.8')
     lan.expect('2 received', timeout=10)
     lan.expect(prompt)
コード例 #19
0
ファイル: webgui.py プロジェクト: RyanLindemanCAE/boardfarm
 def runTest(self):
     url = 'http://192.168.1.1/'
     lan.sendline('\ncurl -v %s' % url)
     lan.expect('<html')
     lan.expect('<body')
     lan.expect('</body>')
     lan.expect('</html>')
     lan.expect(prompt)
コード例 #20
0
 def cleanup_ip(self, ip):
     wan.sendline('ip addr del %s/32 dev %s' % (ip, wan.iface_dut))
     wan.expect_exact('ip addr del %s/32 dev %s' % (ip, wan.iface_dut))
     wan.expect(prompt)
     wan.sendline('pkill -9 -f socat.*bind=%s' % ip)
     wan.expect(prompt)
     lan.sendline('pkill -9 -f socat.*%s:%s' % (self.socat_send, ip))
     lan.expect(prompt)
コード例 #21
0
 def runTest(self):
     # Make Lan-device ping Wan-Device
     lan.sendline('\nping6 -c 20 5aaa::6')
     lan.expect('PING ')
     lan.expect(' ([0-9]+) (packets )?received')
     n = int(lan.match.group(1))
     lan.expect(prompt)
     assert n > 0
コード例 #22
0
 def runTest(self):
     if not lan:
         msg = 'No LAN Device defined, skipping ping test from LAN.'
         lib.common.test_msg(msg)
         self.skipTest(msg)
     lan.sendline('\nping -c 5 192.168.1.1')
     lan.expect('PING ')
     lan.expect('5 packets received', timeout=15)
     lan.expect(prompt)
コード例 #23
0
    def recover(self):
        for ip in self.all_ips:
            wan.sendline('ip addr del %s/32 dev eth1' % ip)
            wan.expect(prompt)

        wan.sendline('killall -9 nc')
        wan.expect(prompt)
        lan.sendline('killall -9 nc')
        lan.expect(prompt)
コード例 #24
0
    def check_and_clean_ips(self):
        lan.sendline("echo SYNC; ps aux | grep  socat | sed -e 's/.*UDP/UDP/g' | tr '\n' ' '")
        lan.expect_exact("SYNC\r\n")
        lan.expect(prompt)
        seen_ips = re.findall('UDP4-SENDTO:([^:]*):', lan.before)

        for done_ip in set(zip(*self.all_ips)[0]) - set(seen_ips):
            self.cleanup_ip(done_ip)
            self.all_ips = [e for e in self.all_ips if e[0] != done_ip ]
コード例 #25
0
 def runTest(self):
     ip = "192.168.1.1"
     url = 'http://%s/' % ip
     lan.sendline('\ncurl -v %s' % url)
     lan.expect('<html')
     lan.expect('<body')
     lan.expect('</body>')
     lan.expect('</html>')
     lan.expect(prompt)
コード例 #26
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)
コード例 #27
0
ファイル: nmap.py プロジェクト: vburhanov/boardfarm
 def runTest(self):
     lan.sendline('nmap -sS -A -v -p 1-10000 192.168.1.1')
     lan.expect('Starting Nmap')
     lan.expect('Nmap scan report', timeout=660)
     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
コード例 #28
0
ファイル: nmap.py プロジェクト: fasolens/boardfarm
 def runTest(self):
     lan.sendline('nmap -sS -A -v -p 1-10000 %s' % board.get_interface_ipaddr(board.lan_iface))
     lan.expect('Starting Nmap')
     lan.expect('Nmap scan report', timeout=1200)
     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
コード例 #29
0
ファイル: ping.py プロジェクト: madhavishinde2318/boardfarm
 def runTest(self):
     if not lan:
         msg = 'No LAN Device defined, skipping ping test from LAN.'
         lib.common.test_msg(msg)
         self.skipTest(msg)
     lan.sendline('\nping -i 0.2 -c 5 192.168.1.1')
     lan.expect('PING ')
     lan.expect('5 received', timeout=15)
     lan.expect(prompt)
コード例 #30
0
 def runTest(self):
     if not lan:
         msg = 'No LAN Device defined, skipping ping test from LAN.'
         lib.common.test_msg(msg)
         self.skipTest(msg)
     router_ip = board.get_interface_ipaddr(board.lan_iface)
     lan.sendline('\nping -i 0.2 -c 5 %s' % router_ip)
     lan.expect('PING ')
     lan.expect('5 (packets )?received', timeout=15)
     lan.expect(prompt)
コード例 #31
0
ファイル: bittorrent.py プロジェクト: jenkins-ams/boardfarm
 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)
コード例 #32
0
ファイル: webgui.py プロジェクト: RyanLindemanCAE/boardfarm
 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)
コード例 #33
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)
コード例 #34
0
 def runTest(self):
     ip = "192.168.1.1"
     board.sendline('\nhead -c 1000000 /dev/urandom > /www/deleteme.txt')
     board.expect('head ', timeout=5)
     board.expect(prompt)
     lan.sendline('\ncurl -m 25 http://%s/deleteme.txt > /dev/null' % ip)
     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)
コード例 #35
0
ファイル: nmap.py プロジェクト: premandfriends/boardfarm-1
 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.touch()
     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
コード例 #36
0
 def runTest(self):
     if not lan:
         msg = 'No LAN Device defined, skipping ping test from LAN.'
         lib.common.test_msg(msg)
         self.skipTest(msg)
     if not wan:
         msg = 'No WAN Device defined, skipping ping WAN test.'
         lib.common.test_msg(msg)
         self.skipTest(msg)
     lan.sendline('\nping -i 0.2 -c 5 %s' % wan.gw)
     lan.expect('PING ')
     lan.expect('5 (packets )?received', timeout=15)
     lan.expect(prompt)
コード例 #37
0
 def runTest(self):
     # WAN Device: create large file in web directory
     fname = "/var/www/20mb.txt"
     wan.sendline('\n[ -e "%s" ] || head -c 20971520 /dev/urandom > %s' % (fname, fname))
     wan.expect("/var")
     wan.expect(prompt)
     # LAN Device: download the file
     lan.sendline("\ncurl -m 57 -g -6 http://[5aaa::6]/20mb.txt > /dev/null")
     lan.expect("Total", timeout=5)
     i = lan.expect(["couldn't connect", "20.0M  100 20.0M"], timeout=60)
     if i == 0:
         assert False
     lan.expect(prompt)
コード例 #38
0
    def runTest(self):

        from lib.installers import install_snmp, install_snmpd
        from lib.common import snmp_mib_get

        wrong_mibs = ['PsysDescr', 'sys123ObjectID', 'sysServiceS']
        linux_mibs = ['sysDescr',\
                      'sysObjectID',\
                      'sysServices',\
                      'sysName',\
                      'sysServices',\
                      'sysUpTime']

        test_mibs = [linux_mibs[0], wrong_mibs[0],\
                     linux_mibs[1], wrong_mibs[1],\
                     linux_mibs[2], wrong_mibs[2]]


        unit_test = SnmpMibsUnitTest(mibs_location = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                                                     os.pardir,
                                                                     'resources',
                                                                     'mibs')),
                                     files = ['SNMPv2-MIB'],
                                     mibs = test_mibs,
                                     err_mibs = wrong_mibs)
        assert (unit_test.unitTest())

        install_snmpd(wan)

        lan.sendline('echo "nameserver 8.8.8.8" >> /etc/resolv.conf')
        lan.expect(lan.prompt)

        install_snmp(lan)
        wan_iface_ip = wan.get_interface_ipaddr(wan.iface_dut)

        for mib in linux_mibs:
            try:
                result = snmp_mib_get(lan,
                                      unit_test.snmp_obj,
                                      str(wan_iface_ip),
                                      mib,
                                      '0',
                                      community='public')

                print('snmpget({})@{}={}'.format(mib, wan_iface_ip, result))
            except Exception as e:
                print('Failed on snmpget {} '.format(mib))
                print(e)
                raise e

        print("Test passed")
コード例 #39
0
ファイル: samba.py プロジェクト: vburhanov/boardfarm
 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 192.168.1.1')
     lan.expect('boardfarm-test')
     lan.expect(prompt)
     lan.sendline(
         'mkdir -p /mnt/samba; mount -o guest //192.168.1.1/boardfarm-test /mnt/samba'
     )
     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)
コード例 #40
0
 def runTest(self):
     # WAN Device: create large file in web directory
     fname = "/var/www/20mb.txt"
     wan.sendline('\n[ -e "%s" ] || head -c 20971520 /dev/urandom > %s' %
                  (fname, fname))
     wan.expect('/var')
     wan.expect(prompt)
     # LAN Device: download the file
     lan.sendline(
         '\ncurl -m 57 -g -6 http://[5aaa::6]/20mb.txt > /dev/null')
     lan.expect('Total', timeout=5)
     i = lan.expect(["couldn't connect", '20.0M  100 20.0M'], timeout=60)
     if i == 0:
         assert False
     lan.expect(prompt)
コード例 #41
0
    def runTest(self):
        wan_ip = wan.get_interface_ipaddr(wan.iface_dut)
        wan.sendline('iperf -s -l 1M -w 1M')
        wan.expect('Server listening on ')

        board.collect_stats(stats=['mpstat'])

        time = 10
        cmd = "iperf -R -c %s -P %s -t 10 -N -w 1M -l 1M | grep SUM"
        # prime the pipes...
        lan.sendline(cmd % (wan_ip, 4))
        lan.expect(prompt)

        prev_con = 0
        prev_failed = 0
        for con_conn in range(32, 513, 16):
            try:
                tstart = datetime.now()
                lan.sendline(cmd % (wan_ip, con_conn))
                failed_cons = 0
                while (datetime.now() - tstart).seconds < (time * 2):
                    timeout = (time * 2) - (datetime.now() - tstart).seconds
                    if 0 == lan.expect(
                        ['write failed: Connection reset by peer'] + prompt,
                            timeout=timeout):
                        failed_cons += 1
                    else:
                        break
                print_bold("For iperf with %s connections, %s failed...." %
                           (con_conn, failed_cons))
                lan.expect('.*')
                wan.expect('.*')

                board.touch()
                prev_conn = con_conn
                prev_failed = failed_cons

                if con_conn == 512:
                    self.result_message = "iPerf Concurrent passed 512 connections (failed conns = %s)" % failed_cons
            except:
                self.result_message = "iPerf Concurrent Connections failed entirely at %s (failed conns = %s)" % (
                    prev_conn, prev_failed)
                break

        print(self.result_message)

        self.recover()
コード例 #42
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)
コード例 #43
0
 def runTest(self):
     urls = ['www.amazon.com',
             'www.apple.com',
             'www.baidu.com',
             'www.bing.com',
             'www.cnn.com',
             'www.ebay.com',
             'www.facebook.com',
             'www.google.com',
             'www.imdb.com',
             'www.imgur.com',
             'www.instagram.com',
             'www.linkedin.com',
             'www.microsoft.com',
             'www.nbcnews.com',
             'www.netflix.com',
             'www.pinterest.com',
             'www.reddit.com',
             'www.twitter.com',
             'www.wikipedia.org',
             'www.yahoo.com',
             ]
     #urls = 2 * urls  # browse more
     random.shuffle(urls)
     user = '******'
     cmd = "wget -Hp http://%(url)s " + \
           "-e robots=off " + \
           "-P /tmp/ " + \
           "-T 10 " + \
           "--header='Accept: text/html' " + \
           "-U '%(user)s' " + \
           "2>&1 | tail -1"
     for url in urls:
         print("\n%s" % url)
         tmp = cmd % {'url': url, 'user': user}
         lan.sendline(tmp)
         try:
             lan.expect('Downloaded:', timeout=20)
         except Exception:
             lan.sendcontrol('c')
         lan.expect(prompt)
         lan.sendline("rm -rf /tmp/*")
         lan.expect(prompt)
コード例 #44
0
ファイル: ipv6_setup.py プロジェクト: fasolens/boardfarm
 def runTest(self):
     board.sendline('\nuci delete network.lan.ip6addr')
     board.expect('uci ')
     board.expect(prompt)
     board.sendline('uci delete network.wan.ip6addr')
     board.expect(prompt)
     board.sendline('ip -6 addr delete 5aaa::1/64 dev eth0')
     board.expect(prompt)
     board.sendline('uci commit network')
     board.expect(prompt)
     board.network_restart()
     # Lan-side Device
     lan.sendline('\nip -6 addr del 4aaa::6/64 dev eth1')
     lan.expect('ip -6')
     lan.expect(prompt)
     lan.sendline('ip -6 route del default')
     lan.expect(prompt)
     # Wan-side Device
     wan.sendline('\nip -6 addr del 5aaa::6/64 dev eth1')
     wan.expect('ip -6')
     wan.expect(prompt)
     wan.sendline('ip -6 route del default')
     wan.expect(prompt)
     time.sleep(10)
コード例 #45
0
ファイル: samba.py プロジェクト: fasolens/boardfarm
 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)
コード例 #46
0
ファイル: nmap.py プロジェクト: fasolens/boardfarm
 def runTest(self):
     start_port = random.randint(1, 11000)
     lan.sendline('\nnmap --min-rate 100 -sU -p %s-%s 192.168.0.1' % (start_port, start_port+200))
     lan.expect('Starting Nmap', timeout=5)
     lan.expect('Nmap scan report', timeout=30)
     lan.expect(prompt)
コード例 #47
0
    def runTest(self):
        # Record number of bytes and packets sent through interfaces
        board.sendline("\nifconfig | grep 'encap\|packets\|bytes'")
        board.expect('br-lan')
        board.expect(prompt)

        # Start netperf tests
        num_conn = 200
        run_time = 30
        pkt_size = 256

        board.sendline('mpstat -P ALL %s 1' % run_time)
        print("\nStarting %s netperf tests in parallel." % num_conn)
        opts = '192.168.0.1 -c -C -l %s -- -m %s -M %s -D' % (run_time, pkt_size, pkt_size)
        for i in range(0, num_conn):
            self.run_netperf_cmd_nowait(lan, opts)
        # Let netperf tests run
        time.sleep(run_time*1.5)

        board.expect('Average:\s+all.*\s+([0-9]+.[0-9]+)\r\n')
        idle_cpu = board.match.group(1)
        avg_cpu = 100 - float(idle_cpu)
        print("Average cpu usage was %s" % avg_cpu)

        # try to flush out backlog of buffer from above, we try b/c not all might start
        # correctly
        try:
            for i in range(0, num_conn):
                lan.exepct('TEST')
        except:
            pass

        # add up as many netperf connections results that were established
        try:
            bandwidth = 0.0
            conns_parsed = 0
            for i in range(0, num_conn):
                bandwidth += self.run_netperf_parse(lan, timeout=1) * run_time
                conns_parsed += 1
        except Exception as e:
            # print the exception for logging reasons
            print(e)
            pass

        # make sure at least one netperf was run
        assert (conns_parsed > 0)

        board.sendline('pgrep logger | wc -l')
        board.expect('([0-9]+)\r\n')
        n = board.match.group(1)

        print("Stopped with %s connections, %s netperf's still running" % (conns_parsed, n))
        print("Mbits passed was %s" % bandwidth)

        # Record number of bytes and packets sent through interfaces
        board.sendline("ifconfig | grep 'encap\|packets\|bytes'")
        board.expect('br-lan')
        board.expect(prompt)

        lan.sendline('killall netperf')
        lan.expect(prompt)
        lan.sendline("")
        lan.expect(prompt)
        lib.common.clear_buffer(lan)

        self.result_message = "Ran %s/%s for %s seconds (Pkt Size = %s, Mbits = %s, CPU = %s)" \
                                    % (conns_parsed, num_conn, run_time, pkt_size, bandwidth, avg_cpu)
コード例 #48
0
ファイル: ipv6_setup.py プロジェクト: fasolens/boardfarm
 def runTest(self):
     # Router
     board.sendline('uci set network.lan6=interface')
     board.expect(prompt)
     board.sendline('uci set network.lan6.proto=static')
     board.expect(prompt)
     board.sendline('uci set network.lan6.ip6addr=4aaa::1/64')
     board.expect(prompt)
     board.sendline('uci set network.lan6.ifname=@lan')
     board.expect(prompt)
     board.sendline('uci set network.wan6=interface')
     board.expect(prompt)
     board.sendline('uci set network.wan6.proto=static')
     board.expect(prompt)
     board.sendline('uci set network.wan6.ip6addr=5aaa::1/64')
     board.expect(prompt)
     board.sendline('uci set network.wan6.ifname=@wan')
     board.expect(prompt)
     board.sendline('uci commit network')
     board.expect(prompt)
     board.network_restart()
     # Lan-side Device
     lan.sendline('\nip -6 addr add 4aaa::6/64 dev eth1')
     lan.expect('ip -6')
     lan.expect(prompt)
     lan.sendline('ip -6 route add 4aaa::1 dev eth1')
     lan.expect(prompt)
     lan.sendline('ip -6 route add default via 4aaa::1 dev eth1')
     lan.expect(prompt)
     if 'No route to host' in lan.before:
         raise Exception('Error setting ivp6 routes')
     # Wan-side Device
     wan.sendline('\nip -6 addr add 5aaa::6/64 dev eth1')
     wan.expect('ip -6')
     wan.expect(prompt)
     wan.sendline('ip -6 route add 5aaa::1 dev eth1')
     wan.expect(prompt)
     wan.sendline('ip -6 route add default via 5aaa::1 dev eth1')
     wan.expect(prompt)
     if 'No route to host' in wan.before:
         raise Exception('Error setting ivp6 routes')
     # Wlan-side Device
     if wlan:
         wlan.sendline('\nip -6 addr add 4aaa::7/64 dev wlan0')
         wlan.expect('ip -6')
         wlan.expect(prompt)
         wlan.sendline('ip -6 route add 4aaa::1 dev eth1')
         wlan.expect(prompt)
         wlan.sendline('ip -6 route add default via 4aaa::1 dev wlan0')
         wlan.expect(prompt)
     # Give things time to get ready
     time.sleep(20)
     # Check addresses
     board.sendline('\nifconfig | grep -B2 addr:')
     board.expect('ifconfig ')
     board.expect(prompt)
     lan.sendline('\nifconfig | grep -B2 addr:')
     lan.expect('ifconfig ')
     lan.expect(prompt)
     wan.sendline('\nifconfig | grep -B2 addr:')
     wan.expect('ifconfig ')
     wan.expect(prompt)
コード例 #49
0
ファイル: rootfs_boot.py プロジェクト: mtusnio/boardfarm
    def boot(self, reflash=True):
        if not wan:
            msg = 'No WAN Device defined, skipping flash.'
            lib.common.test_msg(msg)
            self.skipTest(msg)

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

        # start tftpd server on appropriate device
        if self.config.board.get('wan_device', None) is not None:
            wan.start_tftp_server()
        else:
            tftp_servers = [ x['name'] for x in self.config.board['devices'] if 'tftpd-server' in x.get('options', "") ]
            # start all tftp servers for now
            for tftp_server in tftp_servers:
                tftp_device = getattr(self.config, tftp_server)
                tftp_device.start_tftp_server()


        board.reset()
        rootfs = None

        # Reflash only if at least one or more of these
        # variables are set, or else there is nothing to do in u-boot
        if reflash and (self.config.META_BUILD or self.config.ROOTFS or\
                            self.config.KERNEL or self.config.UBOOT):
            # Break into U-Boot, set environment variables
            board.wait_for_boot()
            board.setup_uboot_network()
            if self.config.META_BUILD:
                for attempt in range(3):
                    try:
                        board.flash_meta(self.config.META_BUILD)
                        break
                    except Exception as e:
                        print(e)
                        wan.restart_tftp_server()
                        board.reset(break_into_uboot=True)
                        board.setup_uboot_network()
                else:
                    raise Exception('Error during flashing...')
            if self.config.UBOOT:
                board.flash_uboot(self.config.UBOOT)
            if self.config.ROOTFS:
                # save filename for cases where we didn't flash it
                # but will use it later to load from memory
                rootfs = board.flash_rootfs(self.config.ROOTFS)
            if self.config.KERNEL:
                board.flash_linux(self.config.KERNEL)
            # Boot from U-Boot to Linux
            board.boot_linux(rootfs=rootfs)
        board.linux_booted = True
        board.wait_for_linux()
        linux_booted_seconds_up = board.get_seconds_uptime()
        # Retry setting up wan protocol
        for i in range(2):
            time.sleep(10)
            try:
                if "pppoe" in self.config.WAN_PROTO:
                    wan.turn_on_pppoe()
                board.config_wan_proto(self.config.WAN_PROTO)
                break
            except:
                print("\nFailed to check/set the router's WAN protocol.")
                pass
        board.wait_for_network()

        # wait for overlay to finish mounting
        for i in range(5):
            try:
                board.sendline('mount')
                board.expect_exact('overlayfs:/overlay on / type overlay')
                board.expect(prompt)
            except:
                if i == 4:
                    lib.common.test_msg("WARN: Overlay still not mounted")
                else:
                    pass
            else:
                break

        # Router mac addresses are likely to change, so flush arp
        if lan:
            lan.ip_neigh_flush()
        wan.ip_neigh_flush()

        # Clear default routes perhaps left over from prior use
        if lan:
            lan.sendline('\nip -6 route del default')
            lan.expect(prompt)
        wan.sendline('\nip -6 route del default')
        wan.expect(prompt)

        # Give other daemons time to boot and settle
        for i in range(5):
            board.get_seconds_uptime()
            time.sleep(5)

        try:
            board.sendline("passwd")
            board.expect("New password:"******"password")
            board.expect("Retype password:"******"password")
            board.expect(prompt)
        except:
            print("WARNING: Unable to set root password on router.")

        board.sendline('cat /proc/cmdline')
        board.expect(prompt)
        board.sendline('uname -a')
        board.expect(prompt)

        # we can't have random messsages messages
        board.sendline("echo \"1 1 1 7\" > /proc/sys/kernel/printk")
        board.expect(prompt)

        if hasattr(self.config, 'INSTALL_PKGS') and self.config.INSTALL_PKGS != "":
            for pkg in self.config.INSTALL_PKGS.split(' '):
                if len(pkg) > 0:
                    board.install_package(pkg)

        # Try to verify router has stayed up (and, say, not suddenly rebooted)
        end_seconds_up = board.get_seconds_uptime()
        print("\nThe router has been up %s seconds." % end_seconds_up)
        assert end_seconds_up > linux_booted_seconds_up
        assert end_seconds_up > 30

        self.logged['boot_time'] = end_seconds_up

        if lan:
            lan.start_lan_client()
コード例 #50
0
ファイル: ping.py プロジェクト: RyanLindemanCAE/boardfarm
 def runTest(self):
     lan.sendline("\nping -c2 8.8.8.8")
     lan.expect("2 received", timeout=10)
     lan.expect(prompt)
コード例 #51
0
ファイル: ping.py プロジェクト: RyanLindemanCAE/boardfarm
 def runTest(self):
     lan.sendline("\nping -i 0.2 -c 5 192.168.0.1")
     lan.expect("PING ")
     lan.expect("5 received", timeout=15)
     lan.expect(prompt)