예제 #1
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()
예제 #2
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()
예제 #3
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()
예제 #4
0
    def runTest(self):
        legacy = hasattr(self.config, "wan_device")
        lib.common.test_msg(
            "Press Ctrl-] to stop interaction and return to menu")
        board.sendline()
        try:
            board.interact()
        except:
            return

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

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

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

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

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

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

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

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

            if key == str(i):
                try:
                    # re import the tests
                    test_files = glob.glob(os.path.dirname(__file__) + "/*.py")
                    for x in sorted([
                            os.path.basename(f)[:-3] for f in test_files
                            if not "__" in f
                    ]):
                        exec("from %s import *" % x)
                except:
                    print("Unable to re-import tests!")
                else:
                    # TODO: use an index instead of test name
                    print("Type test to run: ")
                    test = sys.stdin.readline()

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

                continue
            i += 1

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

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

            if key == "x":
                break
예제 #5
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()
예제 #6
0
    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()
예제 #7
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()
예제 #8
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()
예제 #9
0
    def boot(self, reflash=True):
        # start tftpd server on appropriate device
        tftp_servers = [
            x['name'] for x in self.config.board['devices']
            if 'tftpd-server' in x.get('options', "")
        ]
        tftp_device = None
        # start all tftp servers for now
        for tftp_server in tftp_servers:
            tftp_device = getattr(self.config, tftp_server)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.logged['boot_time'] = end_seconds_up

        if board.routing and lan and self.config.setup_device_networking:
            if wan is not None:
                lan.start_lan_client(wan_gw=wan.gw)
            else:
                lan.start_lan_client()
예제 #10
0
    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")
        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()
예제 #11
0
    def runTest(self):

        lib.common.test_msg("Press Ctrl-] to stop interaction and return to menu")
        board.sendline()
        try:
            board.interact()
        except:
            return

        while True:
            print("\n\nCurrent station")
            print("  Board console: %s" % self.config.board.get('conn_cmd'))
            print("  LAN device:    ssh root@%s" % self.config.board.get('lan_device'))
            print("  WAN device:    ssh root@%s" % self.config.board.get('wan_device'))
            print('Pro-tip: Increase kernel message verbosity with\n'
                  '    echo "7 7 7 7" > /proc/sys/kernel/printk')
            print("Menu")
            print("  1: Enter console")
            print("  2: Enter wan console")
            print("  3: Enter lan console")
            print("  4: Enter wlan console")
            print("  5: List all tests")
            print("  6: Run test")
            print("  7: Reset board")
            print("  8: Enter interactive python shell")
            print("  x: Exit")
            key = raw_input("Please select: ")

            if key == "1":
                board.interact()
            elif key == "2":
                wan.interact()
            elif key == "3":
                lan.interact()
            elif key == "4":
                wlan.interact()
            elif key == "5":
                try:
                    # re import the tests
                    test_files = glob.glob(os.path.dirname(__file__)+"/*.py")
                    for x in sorted([os.path.basename(f)[:-3] for f in test_files if not "__" in f]):
                        exec("from %s import *" % x)
                except:
                    print("Unable to re-import tests!")
                else:
                    # list what we can re-run
                    rfs_boot = rootfs_boot.RootFSBootTest
                    print("Available tests:")
                    print_subclasses(rfs_boot)
            elif key == "6":
                try:
                    # re import the tests
                    test_files = glob.glob(os.path.dirname(__file__)+"/*.py")
                    for x in sorted([os.path.basename(f)[:-3] for f in test_files if not "__" in f]):
                        exec("from %s import *" % x)
                except:
                    print("Unable to re-import tests!")
                else:
                    # TODO: use an index instead of test name
                    print("Type test to run: ")
                    test = sys.stdin.readline()

                    try:
                        board.sendline()
                        board.sendline('echo \"1 1 1 7\" > /proc/sys/kernel/printk')
                        board.expect(prompt)
                        t = eval(test)
                        cls = t(self.config)
                        lib.common.test_msg("\n==================== Begin %s ====================" % cls.__class__.__name__)
                        cls.testWrapper()
                        lib.common.test_msg("\n==================== End %s ======================" % cls.__class__.__name__)
                        board.sendline()
                    except:
                        print("Unable to (re-)run specified test")

            elif key == "7":
                board.reset()
                print("Press Ctrl-] to stop interaction and return to menu")
                board.interact()
            elif key == "8":
                print "Enter python shell, press Ctrl-D to exit"
                try:
                    from IPython import embed
                    embed()
                except:
                    try:
                        import readline # optional, will allow Up/Down/History in the console
                        import code
                        vars = globals().copy()
                        vars.update(locals())
                        shell = code.InteractiveConsole(vars)
                        shell.interact()
                    except:
                        print "Unable to spawn interactive shell!"
            elif key == "x":
                break
예제 #12
0
    def runTest(self):
        legacy = hasattr(self.config, "wan_device")
        lib.common.test_msg("Press Ctrl-] to stop interaction and return to menu")
        board.sendline()
        try:
            board.interact()
        except:
            return

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

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

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

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

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

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

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

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

            if key == str(i):
                try:
                    # re import the tests
                    test_files = glob.glob(os.path.dirname(__file__)+"/*.py")
                    for x in sorted([os.path.basename(f)[:-3] for f in test_files if not "__" in f]):
                        exec("from %s import *" % x)
                except:
                    print("Unable to re-import tests!")
                else:
                    # TODO: use an index instead of test name
                    print("Type test to run: ")
                    test = sys.stdin.readline()

                    #try:
                    board.sendline()
                    board.sendline('echo \"1 1 1 7\" > /proc/sys/kernel/printk')
                    board.expect(prompt)
                    t = eval(test)
                    cls = t(self.config)
                    lib.common.test_msg("\n==================== Begin %s ====================" % cls.__class__.__name__)
                    cls.testWrapper()
                    lib.common.test_msg("\n==================== End %s ======================" % cls.__class__.__name__)
                    board.sendline()
                    #except:
                    #    print("Unable to (re-)run specified test")

                continue
            i += 1

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

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

            if key == "x":
                break
예제 #13
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()
예제 #14
0
    def boot(self, reflash=True):
        # start tftpd server on appropriate device
        tftp_servers = [ x['name'] for x in self.config.board['devices'] if 'tftpd-server' in x.get('options', "") ]
        tftp_device = None
        # start all tftp servers for now
        for tftp_server in tftp_servers:
            # This is a mess, just taking the last tftpd-server?
            tftp_device = getattr(self.config, tftp_server)

        dhcp_started = False

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

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

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

        if wan and not dhcp_started:
            wan.setup_dhcp_server()

        tftp_device.start_tftp_server()

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

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

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

            # TODO: don't do this and sort out two interfaces with ipv6
            wan.disable_ipv6('eth0')

            if hasattr(prov, 'prov_gateway_v6'):
                wan.sendline('ip -6 route add default via %s' % str(prov.prov_gateway_v6))
                wan.expect(prompt)

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

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

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

        board.reset()
        rootfs = None

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

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

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

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

        # we can't have random messsages messages
        board.set_printk()

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

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

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

            cm_configmode = board.cm_cfg.cm_configmode

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

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

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

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

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

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

        self.logged['boot_time'] = end_seconds_up

        if board.routing and lan and self.config.setup_device_networking:
            if wan is not None:
                lan.start_lan_client(wan_gw=wan.gw)
            else:
                lan.start_lan_client()