Example #1
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")
Example #2
0
    def runTest(self):
        if not wan:
            msg = 'No WAN Device defined, skipping copy file to WAN test.'
            lib.common.test_msg(msg)
            self.skipTest(msg)

        if not hasattr(wan, 'ipaddr'):
            msg = 'WAN device is not running ssh server, can\'t copy with this function'
            lib.common.test_msg(msg)
            self.skipTest(msg)

        text_file = tempfile.NamedTemporaryFile()
        self.fname = fname = text_file.name

        letters = string.ascii_letters
        fcontent = ''.join(random.choice(letters) for i in range(50))

        text_file.write(fcontent)
        text_file.flush()

        fmd5 = hashlib.md5(open(fname,'rb').read()).hexdigest()
        print("File orginal md5sum: %s"% fmd5)

        wan_ip = wan.get_interface_ipaddr("eth0")

        cmd = "cat %s | ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -x %s@%s \"cat - > %s\""\
              % (fname, wan.username, wan_ip, fname)
        # this must fail as the command does not echo the filename
        try:
            common.copy_file_to_server(cmd, wan.password, "/tmp")
        except:
            print("Copy failed as expected")
            pass

        cmd = "cat %s | ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -x %s@%s \"cat - > %s; echo %s\""\
              % (fname, wan.username, wan_ip, fname, fname)
        # this should pass
        try:
            common.copy_file_to_server(cmd, wan.password, "/tmp")
        except:
            assert 0,"copy_file_to_server failed, Test failed!!!!"

        # is the destination file identical to the source file
        wan.sendline("md5sum %s"% fname)
        wan.expect(fmd5)
        wan.expect(wan.prompt)

        print("Test passed")
    def runTest(self):
        wan_ip = wan.get_interface_ipaddr(wan.iface_dut)
        wan.sendline('iperf -s -l 1M -w 1M')
        wan.expect('Server listening on ')

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

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

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

                board.touch()
                prev_conn = con_conn
                prev_failed = failed_cons

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

        print(self.result_message)

        self.recover()
Example #4
0
    def runTest(self):
        install_hping3(lan)
        wan_ip = wan.get_interface_ipaddr(wan.iface_dut)
        wan.sendline('nc -lvu %s 565' % wan_ip)
        wan.expect_exact('nc -lvu %s 565' % wan_ip)

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

        # dest ip and port are fixed, random src port, fixed src ip, 100 us between
        lan.sendline('hping3 -2 -c %s -d 120 -S -w 64 -p 445 -i %s %s' %
                     (self.conns, self.conn_rate, wan_ip))
        lan.expect('HPING')

        self.max_conns = 0
        for not_used in range(10):
            self.max_conns = max(self.max_conns,
                                 board.get_nf_conntrack_conn_count())
            board.get_proc_vmstat()
            lan.expect(pexpect.TIMEOUT, timeout=3)
            board.expect(pexpect.TIMEOUT, timeout=3)
            board.touch()

        self.recover()
Example #5
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)

        dhcp_started = False

        # start dhcp servers
        for device in self.config.board['devices']:
            if 'options' in device and 'dhcp-server' in device['options']:
                getattr(self.config, device['name']).setup_dhcp_server()
                dhcp_started = True

        if not wan and len(tftp_servers) == 0:
            msg = 'No WAN Device or tftp_server defined, skipping flash.'
            lib.common.test_msg(msg)
            self.skipTest(msg)

        # This still needs some clean up, the fall back is to assuming the
        # WAN provides the tftpd server, but it's not always the case
        if wan:
            wan.configure(kind="wan_device", config=self.config.board)
            if tftp_device is None:
                tftp_device = wan

        if wan and not dhcp_started:
            wan.setup_dhcp_server()

        tftp_device.start_tftp_server()

        prov = getattr(self.config, 'provisioner', None)
        if prov is not None:
            prov.tftp_device = tftp_device
            prov.provision_board(self.config.board)

            if hasattr(prov, 'prov_gateway'):
                gw = prov.prov_gateway if wan.gw in prov.prov_network else prov.prov_ip

                for nw in [prov.cm_network, prov.mta_network]:
                    wan.sendline('ip route add %s via %s' % (nw, gw))
                    wan.expect(prompt)

            wan.sendline('ip route')
            wan.expect(prompt)

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

        # tftp_device is always None, so we can set it from config
        board.tftp_server = tftp_device.ipaddr
        # then these are just hard coded defaults
        board.tftp_port = 22
        # but are user/password used for tftp, they are likely legacy and just need to go away
        board.tftp_username = "******"
        board.tftp_password = "******"

        board.reset()
        rootfs = None

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

        if prov is not None and 'debian' in prov.model:
            table = self.config.board['station']
            idx = wan.port  # TODO: how to do this right...?

            for not_used in range(5):
                try:
                    ips = [board.get_interface_ipaddr(board.wan_iface)]
                    if hasattr(board, 'erouter_iface'):
                        ips += [
                            board.get_interface_ipaddr(board.erouter_iface)
                        ]
                    if hasattr(board, 'mta_iface'):
                        ips += [board.get_interface_ipaddr(board.mta_iface)]
                    break
                except:
                    continue

            # TODO: don't hard code 300 or mv1-1
            prov.sendline('sed /^%s/d -i /etc/iproute2/rt_tables' % idx)
            prov.expect(prompt)
            prov.sendline('echo "%s     %s" >> /etc/iproute2/rt_tables' %
                          (idx, table))
            prov.expect(prompt)

            for ip in ips:
                prov.sendline('ip rule del from %s' % ip)
                prov.expect(prompt)
                prov.sendline('ip rule add from %s lookup %s' % (ip, table))
                prov.expect(prompt)

            wan_ip = wan.get_interface_ipaddr(wan.iface_dut)
            prov.sendline('ip route add default via %s dev eth1 table %s' %
                          (wan_ip, table))
            prov.expect(prompt)

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

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

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

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

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

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

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

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

        self.logged['boot_time'] = end_seconds_up

        if board.routing and lan and self.config.setup_device_networking:
            if wan is not None:
                lan.start_lan_client(wan_gw=wan.gw)
            else:
                lan.start_lan_client()
Example #6
0
    def runTest(self):
        if not wan:
            msg = 'No WAN Device defined, skipping test_create_session.'
            lib.common.test_msg(msg)
            self.skipTest(msg)

        wan_ip = wan.get_interface_ipaddr("eth0")

        import devices
        # this should fail, as "DebianBoxNonExistent" is not (yet) a device
        try:
            kwargs ={
                    'name':"wan_test_calls_fail",
                    'ipaddr':wan_ip,
                    'port':22,
                    'color': 'magenta'
                    }
            self.session = devices.get_device("DebianBoxNonExistent", **kwargs)
        except:
            pass
        else:
            assert self.session is None,"Test Failed on wrong class name"
            print("Failed to create session on wrong class name (expected) PASS")

        # this must fail, as "169.254.12.18" is not a valid ip
        try:
            kwargs ={
                    'name':"wan_test_ip_fail",
                    'ipaddr':"169.254.12.18",
                    'port':22,
                    'color': 'cyan'
                    }
            self.session = devices.get_device("DebianBox", **kwargs)
        except:
            pass
        else:
            assert self.session is None,"Test Failed on wrong IP"
            print("Failed to create session on wrong IP (expected) PASS")

        # this must fail, as 50 is not a valid port
        try:
            kwargs ={
                    'name':"wan_test_port_fail",
                    'ipaddr':wan_ip,
                    'port':50,
                    'color': 'red'
                    }
            self.session = devices.get_device("DebianBox", **kwargs)
        except:
            pass
        else:
            assert self.session is None,"Test Failed on wrong port"
            print("Failed to create session on wrong port (expected) PASS")

        # this must fail, close but no cigar
        try:
            kwargs ={
                    'name':"wan_test_type_fail",
                    'ipaddr':wan_ip,
                    'port':50,
                    'color': 'red'
                    }
            self.session = devices.get_device("debina", **kwargs)
        except:
            pass
        else:
            assert self.session is None,"Test Failed on misspelled class name"
            print("Failed to create session on misspelled class name (expected) PASS")

        # this should pass
        try:
            kwargs ={
                    'name':"correct_wan_parms",
                    'ipaddr':wan_ip,
                    'port':'22',
                    'color': 'yellow'
                    }
            self.session = devices.get_device("debian", **kwargs)
        except:
            assert 0, "Failed to create session, Test FAILED!"
        else:
            assert self.session is not None,"Test Failed on correct paramters!!"

        print("Session created successfully")

        # is the session really logged onto the wan?

        wan.sendline()
        wan.expect(wan.prompt)
        wan.sendline("ip a")
        wan.expect_exact("ip a")
        wan.expect(wan.prompt)
        w = wan.before

        self.session.sendline()
        self.session.expect(self.session.prompt)
        self.session.sendline("ip a")
        self.session.expect_exact("ip a")
        self.session.expect(self.session.prompt)
        s = self.session.before

        assert w == s, "Interfaces differ!!! Test Failed"

        self.session.sendline("exit")

        print("Test passed")