Ejemplo n.º 1
0
    def run_jobs(self):
        for job, tests in self.bf_args.jobs.items():

            j = None
            logger.info(
                f"Loading job with config : {job[0]} and package : {job[1]}")
            logger.info("#" * 80)
            try:
                # if a config does not exist bail out
                config = job[0]
                if not self.validate_config(config):
                    raise CDrouterDevice.InvalidCDRConfig(
                        f"Invalid config : {config}")

                package = job[1]
                testlist = list(zip(*tests))[1]
                if not self.validate_package(package, config, testlist):
                    pkg = self.create_package(package, config, testlist)
                else:
                    pkg = self.packages.get_by_name(package)

                self.bf_args.start_time = time.time()
                j = self.jobs.launch(Job(package_id=pkg.id))

                # if a result_id is attached to a job, it means it's running in CDRouter
                while j.result_id is None:
                    if (time.time() - self.bf_args.start_time) > 300:
                        # delete job if it fails to start
                        self.jobs.delete(j.id)
                        self.bf_args.results.append(None)
                        raise CDrouterDevice.InvalidCDRJob(
                            f"Failed to start CDrouter job for package : {package}"
                        )

                    j = self.jobs.get(j.id)

                logger.info(
                    f"Successfully created job. Result_id : {j.result_id}")

                result = self.results.get(j.result_id)
                self.bf_args.results.append(self.results.get(j.result_id))

                out = self.fetch_results(result)
                for _data in tests:
                    _data.append(out[_data[1]])

            except Exception as e:
                if j:
                    self.cleanup_jobs(j)
                logger.error(
                    f"\n\nFailed to load job with config : {job[0]} and package : {job[1]}"
                )
                for _data in tests:
                    _data.append("error")
                logger.debug(e)
                traceback.print_exc(file=sys.stdout)
            finally:
                logger.debug("#" * 80, end="\n\n")
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
    def runTest(self):
        board = self.dev.board
        wan = self.dev.wan
        lan = self.dev.lan

        from boardfarm.devices import cdrouter
        self.cdrouter_server = "http://" + cdrouter.ipaddr
        self.cdrouter_wan_iface = cdrouter.wan_iface
        self.cdrouter_lan_iface = 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)

        wandutmac = None
        if board.has_cmts:
            provisioner = self.dev.provisioner
            # TODO: there are more missing ones CDrouter expects
            provisioner.sendline('ip route add 200.0.0.0/8 via 192.168.3.2')
            provisioner.expect(prompt)
            provisioner.sendline('ip route add 3.3.3.3 via 192.168.3.2')
            provisioner.expect(prompt)
            provisioner.sendline(
                'ip route add 3001:cafe:1::/64 via 2001:dead:beef:1::2')
            provisioner.expect(prompt)
            provisioner.sendline(
                'ip route add 3001:51a:cafe::1 via 2001:dead:beef:1::2')
            provisioner.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)

        # TODO - WIP
        wan.vlan = "136"
        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

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

        def add_cdrouter_config(config):
            p = os.path.realpath(config)
            cdr_conf = open(os.path.join(p, config), 'r').readlines()

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

        if board.cdrouter_config is not None:
            contents = contents + add_cdrouter_config(board.cdrouter_config)

        if board.has_cmts:
            for i in range(5):
                exp = None
                try:
                    wan_ip = board.get_interface_ipaddr(board.erouter_iface)
                    # TODO: this breaks ipv6 only
                    wan_ip6 = board.get_interface_ip6addr(board.erouter_iface)

                    lan.start_lan_client()
                    lan_ip6 = lan.get_interface_ip6addr(lan.iface_dut)
                    ip6 = ipaddress.IPv6Network(six.text_type(lan_ip6))
                    fixed_prefix6 = str(
                        ip6.supernet(new_prefix=64).network_address)
                    break
                except Exception as e:
                    exp = e
                    board.expect(pexpect.TIMEOUT, timeout=15)
                    continue
            else:
                if i == 4:
                    raise exp

            # TODO: mask from config? wanNatIp vs. wanIspAssignGateway?
            contents=contents + """
testvar ipv6LanIp %s%%eui64%%
testvar ipv6LanPrefixLen 64
testvar healthCheckEnable yes
testvar supportsIPv6 yes
testvar ipv6WanMode static
testvar ipv6WanIspIp %s
testvar ipv6WanIspGateway %s
testvar ipv6WanIspAssignIp %s
testvar ipv6WanIspPrefixLen 64
testvar ipv6LanMode autoconf
testvar ipv6RemoteHost            3001:51a:cafe::1
testvar ipv6FreeNetworkStart      3001:cafe:1::
testvar ipv6FreeNetworkEnd        3001:cafe:ffff::
testvar ipv6FreeNetworkPrefixLen  64
testvar wanMode static
testvar wanIspIp %s
testvar wanIspGateway %s
testvar wanIspMask 255.255.255.128
testvar wanIspAssignIp %s
testvar wanNatIp %s
testvar remoteHostIp 3.3.3.3
testvar FreeNetworkStart 200.0.0.0
testvar FreeNetworkMask  255.255.255.0
testvar FreeNetworkStop  201.0.0.0
testvar IPv4HopCount %s
testvar lanDnsServer %s
testvar wanDnsServer %s
""" % (fixed_prefix6,
            cdrouter.wanispip_v6, \
       cdrouter.wanispgateway_v6, \
       wan_ip6, \
       cdrouter.wanispip, \
       cdrouter.wanispgateway, \
       wan_ip, wan_ip, \
       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 = six.text_type(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"]:
                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(j.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()
Ejemplo n.º 4
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()
#!/usr/bin/env python

import sys
import time

from cdrouter import CDRouter
from cdrouter.jobs import Job

if len(sys.argv) < 3:
    print('usage: <base_url> <token> [<tag>]')
    sys.exit(1)

base = sys.argv[1]
token = sys.argv[2]
tag_name = 'nightly'

if len(sys.argv) > 3:
    tag_name = sys.argv[3]

# create service
c = CDRouter(base, token=token)

packages = c.packages.iter_list(filter=['tags@>{' + tag_name + '}'])
jobs = [Job(package_id=p.id) for p in packages]

for j in c.jobs.bulk_launch(jobs=jobs):
    while j.result_id is None:
        time.sleep(1)
        j = c.jobs.get(j.id)
    print(j.result_id)
Ejemplo n.º 6
0
base = sys.argv[1]
token = sys.argv[2]
package_name = sys.argv[3]

# create service
c = CDRouter(base, token=token)

p = c.packages.get_by_name(package_name)
if not p:
    sys.exit("Package {0} not found.".format(package_name))

print('Running package "{0}"'.format(package_name))
print('')

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

# wait for job to be assigned a result ID
while j.result_id is None:
    time.sleep(1)
    j = c.jobs.get(j.id)

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

print('Waiting for job to complete...')
u = c.results.updates(j.result_id, None)
while u:
    r = c.results.get(j.result_id)
    if r.status in ['completed', 'stopped', 'error']:
Ejemplo n.º 7
0
import sys

from cdrouter import CDRouter
from cdrouter.jobs import Job

if len(sys.argv) < 6:
    print('usage: <base_url> <token> <device-name> <software-version> <software>')
    sys.exit(1)

base = sys.argv[1]
token = sys.argv[2]
device_name = sys.argv[3]
software_version = sys.argv[4]
software = sys.argv[5]

c = CDRouter(base, token=token)

d = c.devices.list(filter=['name='+device_name], limit='1').data[0]

d.software_version = software_version
d = c.devices.edit(d)

a = c.attachments.create(d.id, software)
a.description = 'Firmware for {}'.format(software_version)
a = c.attachments.edit(a)

packages = c.packages.iter_list(filter=['device_id='+d.id])
jobs = [Job(package_id=p.id, tags=[software_version]) for p in packages]

c.jobs.bulk_launch(jobs)
Ejemplo n.º 8
0
        '       <result-tag>  Results will be tagged with this tag or tags in a comma separated list'
    )
    sys.exit(1)

base = sys.argv[1]
token = sys.argv[2]
tag_name = sys.argv[3]
result_tags = sys.argv[4]

result_tags_list = result_tags.split(",")
# create service
c = CDRouter(base, token=token)

packages = c.packages.iter_list(filter=['tags@>{' + tag_name + '}'])
jobs = [
    Job(package_id=p.id, options=Options(tags=result_tags_list))
    for p in packages
]

fails = 0
# launch all packages
for j in c.jobs.bulk_launch(jobs=jobs):
    while j.result_id is None:
        time.sleep(1)
        j = c.jobs.get(j.id)
    print('Test package launched. Result-ID: {0}'.format(j.result_id))
    print('Waiting for job to complete...')

    u = c.results.updates(j.result_id, None)
    while u:
        r = c.results.get(j.result_id)
Ejemplo n.º 9
0
        # See if a package with that name already exists.  If so, leave it alone and move on.
        try:
            cdr.packages.get_by_name(package_name)
        except CDRouterError as ce:
            pass
        else:
            print('A package with this name already exists.  Skipping...')
            continue

        # Create the new package.
        kwargs = {'name': package_name, 'description': 'Created by addpackage', 'testlist': tests, 'user_id': user_id, 'config_id': config_id}
        if args.tags != None:
            kwargs['tags'] = re.split(',', args.tags)
        try:
            package = cdr.packages.create(Package(**kwargs))
        except CDRouterError as ce:
            print('Cannot create package, {}'.format(ce))
            continue

        # Run the package if requested.
        if args.run:
            kwargs = {'package_id': package.id, 'user_id': user_id}
            try:
                job = cdr.jobs.launch(Job(**kwargs))
            except CDRouterError as ce:
                print('Cannot launch package, {}'.format(ce))
                continue

            print('job_id = {}'.format(job.id))