Exemplo n.º 1
0
def dut_links_status(dut):
    local_list = []
    for local, partner, remote in st.get_dut_links(dut):
        local_list.append(local)
    for local, partner, remote in st.get_tg_links(dut):
        local_list.append(local)
    output = portapi.get_status(dut, ",".join(local_list))

    results = dict()
    for local, partner, remote in st.get_dut_links(dut):
        match = {"interface": local}
        entries = utils.filter_and_select(output, ["admin", "oper"], match)
        name = "{}--{}".format(dut, local)
        if entries:
            results[name] = "{}/{}".format(entries[0]["admin"],
                                           entries[0]["oper"])
        else:
            results[name] = "----"
    for local, partner, remote in st.get_tg_links(dut):
        match = {"interface": local}
        entries = utils.filter_and_select(output, ["admin", "oper"], match)
        name = "{}--{}".format(dut, local)
        if entries:
            results[name] = "{}/{}".format(entries[0]["admin"],
                                           entries[0]["oper"])
        else:
            results[name] = "----"
    return results
Exemplo n.º 2
0
def tg_links_status_using_hltapi():
    results = dict()
    for dut in st.get_dut_names():
        for _, partner, remote in st.get_tg_links(dut, native=use_native):
            (tg, ph) = tgapi.get_handle_byname(None, tg=partner, port=remote)
            name = "{}--{}".format(partner, remote)
            results[name] = get_tg_link_status(tg, ph)
    return results
Exemplo n.º 3
0
def tg_links_status_1():
    results = dict()
    for dut in st.get_dut_names():
        for local, partner, remote in st.get_tg_links(dut):
            (tg, ph) = tgapi.get_handle_byname(None, tg=partner, port=remote)
            name = "{}--{}".format(partner, remote)
            results[name] = get_link_status(tg, ph)
    return results
Exemplo n.º 4
0
def tg_links_status_using_native_calls():
    # build port list per tgen
    tg_port_dict = {}
    for dut in st.get_dut_names():
        for _, partner, remote in st.get_tg_links(dut, native=use_native):
            tg_port_dict.setdefault(partner, []).append(remote)

    results = dict()
    for partner, port_list in tg_port_dict.items():
        # get tgen handle using first port
        (tg, _) = tgapi.get_handle_byname(None, tg=partner, port=port_list[0])
        # get all ports status
        rv = tg.get_port_status(port_list)
        # fill the results
        for port in port_list:
            name = "{}--{}".format(partner, port)
            results[name] = rv[port]

    return results
Exemplo n.º 5
0
def dut_links_status(dut, hooks):
    results, local_list = {}, []
    for local, _, _ in st.get_dut_links(dut, native=use_native):
        local_list.append(local)
    for local, _, _ in st.get_tg_links(dut, native=use_native):
        local_list.append(local)

    output = hooks.get_status(dut, ",".join(local_list))

    for local in local_list:
        match = {"interface": local}
        entries = utils.filter_and_select(output, ["admin", "oper"], match)
        name = "{}--{}".format(dut, local)
        if simulate_link_fail():
            results[name] = "up/down"
        elif entries:
            results[name] = "{}/{}".format(entries[0]["admin"],
                                           entries[0]["oper"])
        else:
            results[name] = "----"
    return results
Exemplo n.º 6
0
def links_status(threads, check_type):
    header = [
        'DUT', 'Local', "LStatus (A/O)", "Partner", "Remote", "RStatus (A/O)"
    ]
    funcs = [[tg_links_status, check_type], [duts_links_status, threads]]
    [[v1, v2], [e1, e2]] = utils.exec_all(threads, funcs, True)
    if v1 is None or v2 is None or e1 is not None or e2 is not None:
        print(v1, v2, e1, e2)
        return [True, header, []]

    v1_default = "?2?" if v1 else "NA"
    (results, exclude, alias) = ([], [], fill_alias())
    for dut in st.get_dut_names():
        for local, partner, remote in st.get_tg_links(dut):
            res = []
            res.append(alias.get(dut, "?"))
            res.append(local)
            res.append(v2.get("{}--{}".format(dut, local), "?1?"))
            res.append(alias.get(partner, "?"))
            res.append(remote)
            res.append(v1.get("{}--{}".format(partner, remote), v1_default))
            results.append(res)
        for local, partner, remote in st.get_dut_links(dut):
            name = "{}--{}".format(dut, local)
            if name in exclude:
                continue
            res = []
            res.append(alias.get(dut, "?"))
            res.append(local)
            res.append(v2.get("{}--{}".format(dut, local), "?3?"))
            res.append(alias.get(partner, "?"))
            res.append(remote)
            res.append(v2.get("{}--{}".format(partner, remote), "?4?"))
            exclude.append("{}--{}".format(partner, remote))
            results.append(res)
    return [True, header, results]
Exemplo n.º 7
0
def verify_topology(hooks, check_type, threads=True):
    if check_type in ["module", "function"]:
        return links_status(hooks, threads, check_type)

    retval = True
    results, exclude = [], []
    header = ['DUT', 'DId', 'Local', "Partner", "PDId", "Remote", "Status"]
    dids, _ = fill_dev_ids()
    for dut in st.get_dut_names():
        did = dids[dut]
        for local, partner, remote in st.get_dut_links(dut, native=use_native):
            pdid = dids[dut]

            # check if the port is verified from other direction
            skip = False
            for ex in exclude:
                #print("CMP", dut, local, ex[0], ex[1])
                if dut == ex[0] and local == ex[1]:
                    skip = True
                    break
            if skip:
                log_info("{}({})/{} is already verified".format(
                    dut, did, local))
                continue

            result = [dut, did, local, partner, pdid, remote, "Fail"]

            # shutdown local link and get remote link stats in partner
            hooks.shutdown(dut, [local])
            wait()
            status1 = hooks.get_interface_status(partner, remote)
            trace(dut, did, local, partner, pdid, remote, status1)

            # noshutdown local link and get remote link stats in partner
            hooks.noshutdown(dut, [local])
            wait()
            status2 = hooks.get_interface_status(partner, remote)
            trace(dut, did, local, partner, pdid, remote, status2)

            # log the result on fail
            if not check_status(status1, "down", status2, "up"):
                warn("1. port %s(%s)/%s is not connected to %s(%s)/%s\n", dut,
                     did, local, partner, pdid, remote)
                results.append(result)
                exclude.append([partner, remote])
                retval = False
                continue

            if not check_oneway:
                # shutdown remote link and get local link status
                hooks.shutdown(partner, [remote])
                wait()
                status3 = hooks.get_interface_status(dut, local)
                trace(dut, did, local, partner, pdid, remote, status3)

                # noshutdown remote link and get local link status
                hooks.noshutdown(partner, [remote])
                wait()
                status4 = hooks.get_interface_status(dut, local)
                trace(dut, did, local, partner, pdid, remote, status4)

                # log the result on fail
                if not check_status(status3, "down", status4, "up"):
                    warn("2. port %s(%s)/%s is not connected to %s(%s)/%s\n",
                         dut, did, local, partner, pdid, remote)
                    results.append(result)
                    retval = False
                    continue

            # log the result on pass
            result[6] = "OK"
            results.append(result)
            exclude.append([partner, remote])

        for local, partner, remote in st.get_tg_links(dut, native=use_native):
            pdid = dids[partner]
            (tg, ph) = tgapi.get_handle_byname(None, tg=partner, port=remote)

            result = [dut, did, local, partner, pdid, remote, "Fail"]

            if tg.tg_type in ["scapy"]:
                result[6] = "OK"
                results.append(result)
                continue

            if tgen_link_status_supported:
                # shutdown local link and get remote link stats in partner
                hooks.shutdown(dut, [local])
                wait()
                status1 = get_tg_link_status(tg, ph)
                trace(dut, did, local, partner, pdid, remote, status1)

                # no shutdown local link and get remote link stats in partner
                hooks.noshutdown(dut, [local])
                wait()
                status2 = get_tg_link_status(tg, ph)
                trace(dut, did, local, partner, pdid, remote, status2)

                # log the result on fail
                if tgen_link_status_supported and (status1 or not status2):
                    warn("3. port %s(%s)/%s is not connected to %s/%s(%s)\n",
                         dut, did, local, partner, pdid, remote)
                    results.append(result)
                    retval = False
                    continue

            # shutdown remote link and get local link status
            tg.tg_interface_control(mode="break_link", port_handle=ph)
            wait()
            status3 = hooks.get_interface_status(dut, local)
            trace(dut, did, local, partner, pdid, remote, status3)

            # noshutdown remote link and get local link status
            tg.tg_interface_control(mode="restore_link", port_handle=ph)
            wait()
            status4 = hooks.get_interface_status(dut, local)
            trace(dut, did, local, partner, pdid, remote, status4)

            # log the result on fail
            if not check_status(status3, "down", status4, "up"):
                warn("4. port %s(%s)/%s is not connected to %s/%s(%s)\n", dut,
                     did, local, partner, pdid, remote)
                results.append(result)
                retval = False
                continue

            # log the result on pass
            result[6] = "OK"
            results.append(result)

    return [retval, header, results, False, False]
Exemplo n.º 8
0
def links_status(hooks, threads, check_type):
    header = [
        'DUT', 'DId', 'Local', "LStatus (A/O)", "Partner", 'PDId', "Remote",
        "RStatus (A/O)"
    ]
    funcs = [[tg_links_status, check_type],
             [duts_links_status, hooks, threads]]

    show_alias = bool(st.getenv("SPYTEST_TOPOLOGY_SHOW_ALIAS", "0") != "0")
    if show_alias:
        header.insert(3, "LAlias")
        header.insert(8, "RAlias")

    # st.fail during ctrl+c or prompt not found scenarios, is causing issues.
    # To avoid that below code block should be in try-except only.
    try:
        [[v1, [v2, seen_exp]],
         [e1, e2]] = putils.exec_all2(threads, "trace", funcs, True)
        if v1 is None or v2 is None or e1 is not None or e2 is not None or seen_exp:
            print(v1, v2, e1, e2, seen_exp)
            return [True, header, [], True, show_alias]
    except Exception:
        print("Observed exception during the thread call return handling")
        return [True, header, [], True, show_alias]

    v1_default = "?2?" if v1 else "NA"
    (results, exclude, (dids, palias)) = ([], [], fill_dev_ids())
    for dut in st.get_dut_names():
        for local, partner, remote in st.get_tg_links(dut, native=use_native):
            res = []
            res.append(dut)
            res.append(dids.get(dut, "?"))
            res.append(local)
            if show_alias:
                res.append(palias.get(local, local))
            res.append(v2.get("{}--{}".format(dut, local), "?1?"))
            res.append(partner)
            res.append(dids.get(partner, "?"))
            res.append(remote)
            if show_alias:
                res.append(palias.get(remote, remote))
            res.append(v1.get("{}--{}".format(partner, remote), v1_default))
            results.append(res)
        for local, partner, remote in st.get_dut_links(dut, native=use_native):
            name = "{}--{}".format(dut, local)
            if name in exclude:
                continue
            res = []
            res.append(dut)
            res.append(dids.get(dut, "?"))
            res.append(local)
            if show_alias:
                res.append(palias.get(local, local))
            res.append(v2.get("{}--{}".format(dut, local), "?3?"))
            res.append(partner)
            res.append(dids.get(partner, "?"))
            res.append(remote)
            if show_alias:
                res.append(palias.get(remote, remote))
            res.append(v2.get("{}--{}".format(partner, remote), "?4?"))
            exclude.append("{}--{}".format(partner, remote))
            results.append(res)
    return [True, header, results, False, show_alias]
Exemplo n.º 9
0
def verify_topology(check_type, threads=True):
    if check_type in ["status", "status2", "status3", "status4"]:
        return links_status(threads, check_type)

    retval = True
    results = []
    header = ['DUT', 'Local', "Partner", "Remote", "Status"]
    check_oneway = True
    exclude = []
    for dut in st.get_dut_names():
        alias = st.get_device_alias(dut)
        for local, partner, remote in st.get_dut_links(dut):
            palias = st.get_device_alias(partner)

            # check if the port is verified from other direction
            skip = False
            for ex in exclude:
                #print("CMP", dut, local, ex[0], ex[1])
                if dut == ex[0] and local == ex[1]:
                    skip = True
                    break
            if skip:
                log_info("{}/{} is already verified".format(alias, local))
                continue

            result = [alias, local, palias, remote, "Fail"]

            # shutdown local link and get remote link stats in partner
            portapi.shutdown(dut, [local])
            wait()
            status1 = portapi.get_interface_status(partner, remote)
            trace(alias, local, palias, remote, status1)

            # noshutdown local link and get remote link stats in partner
            portapi.noshutdown(dut, [local])
            wait()
            status2 = portapi.get_interface_status(partner, remote)
            trace(alias, local, palias, remote, status2)

            # log the result on fail
            if not check_status(status1, "down", status2, "up"):
                warn("1. port %s/%s is not connected to %s/%s\n", alias, local,
                     palias, remote)
                results.append(result)
                exclude.append([partner, remote])
                retval = False
                continue

            if not check_oneway:
                # shutdown remote link and get local link status
                portapi.shutdown(partner, [remote])
                wait()
                status3 = portapi.get_interface_status(dut, local)
                trace(alias, local, palias, remote, status3)

                # noshutdown remote link and get local link status
                portapi.noshutdown(partner, [remote])
                wait()
                status4 = portapi.get_interface_status(dut, local)
                trace(alias, local, palias, remote, status4)

                # log the result on fail
                if not check_status(status3, "down", status4, "up"):
                    warn("2. port %s/%s is not connected to %s/%s\n", alias,
                         local, palias, remote)
                    results.append(result)
                    retval = False
                    continue

            # log the result on pass
            result[4] = "OK"
            results.append(result)
            exclude.append([partner, remote])

        for local, partner, remote in st.get_tg_links(dut):
            palias = st.get_device_alias(partner)
            (tg, ph) = tgapi.get_handle_byname(None, tg=partner, port=remote)

            result = [alias, local, palias, remote, "Fail"]

            tgen_link_status_supported = False
            if tgen_link_status_supported:
                # shutdown local link and get remote link stats in partner
                portapi.shutdown(dut, [local])
                wait()
                status1 = get_link_status(tg, ph)
                trace(alias, local, palias, remote, status1)

                # no shutdown local link and get remote link stats in partner
                portapi.noshutdown(dut, [local])
                wait()
                status2 = get_link_status(tg, ph)
                trace(alias, local, palias, remote, status2)

                # log the result on fail
                if tgen_link_status_supported and (status1 or not status2):
                    warn("3. port %s/%s is not connected to %s/%s\n", alias,
                         local, palias, remote)
                    results.append(result)
                    retval = False
                    continue

            # shutdown remote link and get local link status
            tg.tg_interface_control(mode="break_link", port_handle=ph)
            wait()
            status3 = portapi.get_interface_status(dut, local)
            trace(alias, local, palias, remote, status3)

            # noshutdown remote link and get local link status
            tg.tg_interface_control(mode="restore_link", port_handle=ph)
            wait()
            status4 = portapi.get_interface_status(dut, local)
            trace(alias, local, palias, remote, status4)

            # log the result on fail
            if not check_status(status3, "down", status4, "up"):
                warn("4. port %s/%s is not connected to %s/%s\n", alias, local,
                     palias, remote)
                results.append(result)
                retval = False
                continue

            # log the result on pass
            result[4] = "OK"
            results.append(result)

    return [retval, header, results]