Пример #1
0
def check_voq_interfaces(duthosts, per_host, asic, cfg_facts):
    """
    Checks router interfaces on a dut.

    Args:
        duthosts: The duthosts fixture
        per_host: Instance of MultiAsicSonic host to check.
        asic: Instance of SonicAsic to check,
        cfg_facts: Config facts for the frontend duthost/asic under test

    """
    logger.info("Check router interfaces on node: %s, asic: %d",
                per_host.hostname, asic.asic_index)

    dev_intfs = cfg_facts.get('INTERFACE', {})
    voq_intfs = cfg_facts.get('VOQ_INBAND_INTERFACE', [])
    dev_sysports = get_device_system_ports(cfg_facts)

    rif_ports_in_asicdb = []

    # intf_list = get_router_interface_list(dev_intfs)
    asicdb = AsicDbCli(asic)
    asicdb_rif_table = asicdb.dump(asicdb.ASIC_ROUTERINTF_TABLE)
    sys_port_table = asicdb.dump(asicdb.ASIC_SYSPORT_TABLE)

    # asicdb_intf_key_list = asicdb.get_router_if_list()
    # Check each rif in the asicdb, if it is local port, check VOQ DB for correct RIF.
    # If it is on system port, verify slot/asic/port and OID match a RIF in VoQDB
    for rif in asicdb_rif_table.keys():
        rif_type = asicdb_rif_table[rif]['value'][
            "SAI_ROUTER_INTERFACE_ATTR_TYPE"]
        if rif_type != "SAI_ROUTER_INTERFACE_TYPE_PORT":
            logger.info("Skip this rif: %s, it is not on a port: %s", rif,
                        rif_type)
            continue
        else:
            portid = asicdb_rif_table[rif]['value'][
                "SAI_ROUTER_INTERFACE_ATTR_PORT_ID"]
            logger.info("Process RIF %s, Find port with ID: %s", rif, portid)

        porttype = asicdb.get_rif_porttype(portid)
        logger.info("RIF: %s is of type: %s", rif, porttype)
        if porttype == 'hostif':
            # find the hostif entry to get the physical port the router interface is on.
            hostifkey = asicdb.find_hostif_by_portid(portid)
            hostif = asicdb.hget_key_value(hostifkey, 'SAI_HOSTIF_ATTR_NAME')
            logger.info("RIF: %s is on local port: %s", rif, hostif)
            rif_ports_in_asicdb.append(hostif)
            if hostif not in dev_intfs and hostif not in voq_intfs:
                pytest.fail(
                    "Port: %s has a router interface, but it isn't in configdb."
                    % portid)

            # check MTU and ethernet address
            pytest_assert(
                asicdb_rif_table[rif]['value']["SAI_ROUTER_INTERFACE_ATTR_MTU"]
                == cfg_facts['PORT'][hostif]['mtu'],
                "MTU for rif %s is not %s" %
                (rif, cfg_facts['PORT'][hostif]['mtu']))
            intf_mac = get_sonic_mac(per_host, asic.asic_index, hostif)
            pytest_assert(
                asicdb_rif_table[rif]['value']
                ["SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS"].lower() ==
                intf_mac.lower(), "MAC for rif %s is not %s" % (rif, intf_mac))

            sysport_info = {
                'slot': cfg_facts['DEVICE_METADATA']['localhost']['hostname'],
                'asic': cfg_facts['DEVICE_METADATA']['localhost']['asic_name']
            }

            if per_host.is_multi_asic and len(duthosts.supervisor_nodes) == 0:
                check_rif_on_sup(per_host, sysport_info['slot'],
                                 sysport_info['asic'], hostif)
            else:
                for sup in duthosts.supervisor_nodes:
                    check_rif_on_sup(sup, sysport_info['slot'],
                                     sysport_info['asic'], hostif)

        elif porttype == 'sysport':
            try:
                port_output = sys_port_table[
                    "ASIC_STATE:SAI_OBJECT_TYPE_SYSTEM_PORT:" +
                    portid]['value']['SAI_SYSTEM_PORT_ATTR_CONFIG_INFO']
            except KeyError:
                # not a hostif or system port, log error and continue
                logger.error("Did not find OID %s in local or system tables" %
                             portid)
                continue
            port_data = json.loads(port_output)
            for cfg_port in dev_sysports:
                if dev_sysports[cfg_port]['system_port_id'] == port_data[
                        'port_id']:
                    logger.info("RIF: %s is on remote port: %s", rif, cfg_port)
                    break
            else:
                raise AssertionError(
                    "Did not find OID %s in local or system tables" % portid)

            sys_slot, sys_asic, sys_port = cfg_port.split("|")
            if per_host.is_multi_asic and len(duthosts.supervisor_nodes) == 0:
                check_rif_on_sup(per_host, sys_slot, sys_asic, sys_port)
            else:
                for sup in duthosts.supervisor_nodes:
                    check_rif_on_sup(sup, sys_slot, sys_asic, sys_port)

        elif porttype == 'port':
            # this is the RIF on the inband port.
            inband = get_inband_info(cfg_facts)
            logger.info("RIF: %s is on local port: %s", rif, inband['port'])

            # check MTU and ethernet address
            pytest_assert(
                asicdb_rif_table[rif]['value']["SAI_ROUTER_INTERFACE_ATTR_MTU"]
                == cfg_facts['PORT'][inband['port']]['mtu'],
                "MTU for rif %s is not %s" %
                (rif, cfg_facts['PORT'][inband['port']]['mtu']))
            intf_mac = get_sonic_mac(per_host, asic.asic_index, inband['port'])
            pytest_assert(
                asicdb_rif_table[rif]['value']
                ["SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS"].lower() ==
                intf_mac.lower(), "MAC for rif %s is not %s" % (rif, intf_mac))

            sysport_info = {
                'slot': cfg_facts['DEVICE_METADATA']['localhost']['hostname'],
                'asic': cfg_facts['DEVICE_METADATA']['localhost']['asic_name']
            }

            if per_host.is_multi_asic and len(duthosts.supervisor_nodes) == 0:
                check_rif_on_sup(per_host, sysport_info['slot'],
                                 sysport_info['asic'], inband['port'])
            else:
                for sup in duthosts.supervisor_nodes:
                    check_rif_on_sup(sup, sysport_info['slot'],
                                     sysport_info['asic'], inband['port'])

        # TODO: Could be on a LAG
        elif porttype == 'lag':
            lagid = asicdb.hget_key_value(
                "%s:%s" % (AsicDbCli.ASIC_LAG_TABLE, portid),
                'SAI_LAG_ATTR_SYSTEM_PORT_AGGREGATE_ID')
            logger.info("RIF: %s is on system LAG: %s", rif, lagid)

            if per_host.is_multi_asic and len(duthosts.supervisor_nodes) == 0:
                voqdb = VoqDbCli(per_host)
            else:
                voqdb = VoqDbCli(duthosts.supervisor_nodes[0])

            systemlagtable = voqdb.dump("SYSTEM_LAG_ID_TABLE")
            for lag, sysid in systemlagtable['SYSTEM_LAG_ID_TABLE'][
                    'value'].iteritems():
                if sysid == lagid:
                    logger.info("System LAG ID %s is portchannel: %s", lagid,
                                lag)
                    break

            myslot = cfg_facts['DEVICE_METADATA']['localhost']['hostname']
            myasic = cfg_facts['DEVICE_METADATA']['localhost']['asic_name']
            if lag.startswith("%s|%s" % (myslot, myasic)):
                logger.info(
                    "Lag: %s is a local portchannel with a router interface.",
                    lag)
                (s, a, lagname) = lag.split("|")
                pytest_assert(
                    lagname in cfg_facts['PORTCHANNEL_INTERFACE'],
                    "RIF Interface %s is in configdb.json but not in asicdb" %
                    rif)

                if per_host.is_multi_asic and len(
                        duthosts.supervisor_nodes) == 0:
                    check_rif_on_sup(per_host, myslot, myasic, lagname)
                else:
                    for sup in duthosts.supervisor_nodes:
                        check_rif_on_sup(sup, myslot, myasic, lagname)

            else:
                logger.info(
                    "Lag: %s is a remote portchannel with a router interface.",
                    lag)

    # Verify each RIF in config had a corresponding local port RIF in the asicDB.
    for rif in dev_intfs:
        if rif not in rif_ports_in_asicdb:
            raise AssertionError(
                "Interface %s is in configdb.json but not in asicdb" % rif)

    logger.info("Interfaces %s are present in configdb.json and asicdb" %
                str(dev_intfs.keys()))
Пример #2
0
def test_voq_interface_create(duthosts):
    """
    Verify router interfaces are created on all line cards and present in Chassis App Db.

    * Verify router interface creation on local ports in ASIC DB.
    * PORT_ID should match system port table and traced back to config_db.json, mac and MTU should match as well.
    * Verify SYSTEM_INTERFACE table in Chassis AppDb (redis-dump -h <ip> -p 6380 -d 12 on supervisor).
    * Verify creation interfaces with different MTUs in configdb.json.
    * Verify creation of different subnet masks in configdb.json.
    * Repeat with IPv4, IPv6, dual-stack.

    """
    for per_host in duthosts.frontend_nodes:
        logger.info("Check router interfaces on node: %s", per_host.hostname)

        for asic in per_host.asics:
            cfg_facts = asic.config_facts(source="persistent")['ansible_facts']
            dev_intfs = cfg_facts['INTERFACE']
            dev_sysports = get_device_system_ports(cfg_facts)

            slot = per_host.facts['slot_num']
            rif_ports_in_asicdb = []

            # intf_list = get_router_interface_list(dev_intfs)
            asicdb = AsicDbCli(asic)

            asicdb_intf_key_list = asicdb.get_router_if_list()
            # Check each rif in the asicdb, if it is local port, check VOQ DB for correct RIF.
            # If it is on system port, verify slot/asic/port and OID match a RIF in VoQDB
            for rif in asicdb_intf_key_list:
                rif_type = asicdb.hget_key_value(
                    rif, "SAI_ROUTER_INTERFACE_ATTR_TYPE")
                if rif_type != "SAI_ROUTER_INTERFACE_TYPE_PORT":
                    logger.info("Skip this rif: %s, it is not on a port: %s",
                                rif, rif_type)
                    continue
                else:
                    portid = asicdb.hget_key_value(
                        rif, "SAI_ROUTER_INTERFACE_ATTR_PORT_ID")
                    logger.info("Process RIF %s, Find port with ID: %s", rif,
                                portid)

                porttype = asicdb.get_rif_porttype(portid)
                logger.info("RIF: %s is of type: %s", rif, porttype)
                if porttype == 'hostif':
                    # find the hostif entry to get the physical port the router interface is on.
                    hostifkey = asicdb.find_hostif_by_portid(portid)
                    hostif = asicdb.hget_key_value(hostifkey,
                                                   'SAI_HOSTIF_ATTR_NAME')
                    logger.info("RIF: %s is on local port: %s", rif, hostif)
                    rif_ports_in_asicdb.append(hostif)
                    if hostif not in dev_intfs:
                        pytest.fail(
                            "Port: %s has a router interface, but it isn't in configdb."
                            % portid)

                    # check MTU and ethernet address
                    asicdb.get_and_check_key_value(
                        rif,
                        cfg_facts['PORT'][hostif]['mtu'],
                        field="SAI_ROUTER_INTERFACE_ATTR_MTU")
                    intf_mac = get_sonic_mac(per_host, asic.asic_index, hostif)
                    asicdb.get_and_check_key_value(
                        rif,
                        intf_mac,
                        field="SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS")

                    sup_rif = asicdb.hget_key_value("VIDTORID",
                                                    "oid:" + rif.split(":")[3])
                    sysport_info = find_system_port(dev_sysports, slot,
                                                    asic.asic_index, hostif)
                    for sup in duthosts.supervisor_nodes:
                        check_rif_on_sup(sup, sup_rif, sysport_info['slot'],
                                         sysport_info['asic'], hostif)

                elif porttype == 'sysport':
                    try:
                        port_output = asicdb.hget_key_value(
                            "ASIC_STATE:SAI_OBJECT_TYPE_SYSTEM_PORT:" + portid,
                            field="SAI_SYSTEM_PORT_ATTR_CONFIG_INFO")
                    except RedisKeyNotFound:
                        # not a hostif or system port, log error and continue
                        logger.error(
                            "Did not find OID %s in local or system tables" %
                            portid)
                        continue
                    port_data = json.loads(port_output)
                    for cfg_port in dev_sysports:
                        if dev_sysports[cfg_port][
                                'system_port_id'] == port_data['port_id']:
                            logger.info("RIF: %s is on remote port: %s", rif,
                                        cfg_port)
                            break
                    else:
                        raise AssertionError(
                            "Did not find OID %s in local or system tables" %
                            portid)

                    sys_slot, sys_asic, sys_port = cfg_port.split("|")
                    sup_rif = asicdb.hget_key_value("VIDTORID",
                                                    "oid:" + rif.split(":")[3])
                    for sup in duthosts.supervisor_nodes:
                        check_rif_on_sup(sup, sup_rif, sys_slot, sys_asic,
                                         sys_port)

                elif porttype == 'port':
                    # this is the RIF on the inband port.
                    inband = get_inband_info(cfg_facts)
                    logger.info("RIF: %s is on local port: %s", rif,
                                inband['port'])

                    # check MTU and ethernet address
                    asicdb.get_and_check_key_value(
                        rif,
                        cfg_facts['PORT'][inband['port']]['mtu'],
                        field="SAI_ROUTER_INTERFACE_ATTR_MTU")
                    intf_mac = get_sonic_mac(per_host, asic.asic_index,
                                             inband['port'])
                    asicdb.get_and_check_key_value(
                        rif,
                        intf_mac,
                        field="SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS")

                    sup_rif = asicdb.hget_key_value("VIDTORID",
                                                    "oid:" + rif.split(":")[3])
                    sysport_info = find_system_port(dev_sysports, slot,
                                                    asic.asic_index,
                                                    inband['port'])
                    for sup in duthosts.supervisor_nodes:
                        check_rif_on_sup(sup, sup_rif, sysport_info['slot'],
                                         sysport_info['asic'], inband['port'])

            # Verify each RIF in config had a corresponding local port RIF in the asicDB.
            for rif in dev_intfs:
                pytest_assert(
                    rif in rif_ports_in_asicdb,
                    "Interface %s is in configdb.json but not in asicdb" % rif)
            logger.info(
                "Interfaces %s are present in configdb.json and asicdb" %
                str(dev_intfs.keys()))
Пример #3
0
def test_voq_interface_create(duthosts, enum_frontend_dut_hostname,
                              enum_asic_index, all_cfg_facts):
    """
    Verify router interfaces are created on all line cards and present in Chassis App Db.

    * Verify router interface creation on local ports in ASIC DB.
    * PORT_ID should match system port table and traced back to config_db.json, mac and MTU should match as well.
    * Verify SYSTEM_INTERFACE table in Chassis AppDb (redis-dump -h <ip> -p 6380 -d 12 on supervisor).
    * Verify creation interfaces with different MTUs in configdb.json.
    * Verify creation of different subnet masks in configdb.json.
    * Repeat with IPv4, IPv6, dual-stack.

    """
    per_host = duthosts[enum_frontend_dut_hostname]
    asic = per_host.asics[
        enum_asic_index if enum_asic_index is not None else 0]
    cfg_facts = all_cfg_facts[per_host.hostname][
        asic.asic_index]['ansible_facts']
    logger.info("Check router interfaces on node: %s, asic: %d",
                per_host.hostname, asic.asic_index)

    dev_intfs = cfg_facts['INTERFACE']
    voq_intfs = cfg_facts['VOQ_INBAND_INTERFACE']
    dev_sysports = get_device_system_ports(cfg_facts)

    slot = per_host.facts['slot_num']

    rif_ports_in_asicdb = []

    # intf_list = get_router_interface_list(dev_intfs)
    asicdb = AsicDbCli(asic)
    asicdb_rif_table = asicdb.dump(asicdb.ASIC_ROUTERINTF_TABLE)
    sys_port_table = asicdb.dump(asicdb.ASIC_SYSPORT_TABLE)

    # asicdb_intf_key_list = asicdb.get_router_if_list()
    # Check each rif in the asicdb, if it is local port, check VOQ DB for correct RIF.
    # If it is on system port, verify slot/asic/port and OID match a RIF in VoQDB
    for rif in asicdb_rif_table.keys():
        rif_type = asicdb_rif_table[rif]['value'][
            "SAI_ROUTER_INTERFACE_ATTR_TYPE"]
        if rif_type != "SAI_ROUTER_INTERFACE_TYPE_PORT":
            logger.info("Skip this rif: %s, it is not on a port: %s", rif,
                        rif_type)
            continue
        else:
            portid = asicdb_rif_table[rif]['value'][
                "SAI_ROUTER_INTERFACE_ATTR_PORT_ID"]
            logger.info("Process RIF %s, Find port with ID: %s", rif, portid)

        porttype = asicdb.get_rif_porttype(portid)
        logger.info("RIF: %s is of type: %s", rif, porttype)
        if porttype == 'hostif':
            # find the hostif entry to get the physical port the router interface is on.
            hostifkey = asicdb.find_hostif_by_portid(portid)
            hostif = asicdb.hget_key_value(hostifkey, 'SAI_HOSTIF_ATTR_NAME')
            logger.info("RIF: %s is on local port: %s", rif, hostif)
            rif_ports_in_asicdb.append(hostif)
            if hostif not in dev_intfs and hostif not in voq_intfs:
                pytest.fail(
                    "Port: %s has a router interface, but it isn't in configdb."
                    % portid)

            # check MTU and ethernet address
            pytest_assert(
                asicdb_rif_table[rif]['value']["SAI_ROUTER_INTERFACE_ATTR_MTU"]
                == cfg_facts['PORT'][hostif]['mtu'],
                "MTU for rif %s is not %s" %
                (rif, cfg_facts['PORT'][hostif]['mtu']))
            intf_mac = get_sonic_mac(per_host, asic.asic_index, hostif)
            pytest_assert(
                asicdb_rif_table[rif]['value']
                ["SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS"].lower() ==
                intf_mac.lower(), "MAC for rif %s is not %s" % (rif, intf_mac))

            sysport_info = find_system_port(dev_sysports, slot,
                                            asic.asic_index, hostif)
            for sup in duthosts.supervisor_nodes:
                check_rif_on_sup(sup, sysport_info['slot'],
                                 sysport_info['asic'], hostif)

        elif porttype == 'sysport':
            try:
                port_output = sys_port_table[
                    "ASIC_STATE:SAI_OBJECT_TYPE_SYSTEM_PORT:" +
                    portid]['value']['SAI_SYSTEM_PORT_ATTR_CONFIG_INFO']
            except KeyError:
                # not a hostif or system port, log error and continue
                logger.error("Did not find OID %s in local or system tables" %
                             portid)
                continue
            port_data = json.loads(port_output)
            for cfg_port in dev_sysports:
                if dev_sysports[cfg_port]['system_port_id'] == port_data[
                        'port_id']:
                    logger.info("RIF: %s is on remote port: %s", rif, cfg_port)
                    break
            else:
                raise AssertionError(
                    "Did not find OID %s in local or system tables" % portid)

            sys_slot, sys_asic, sys_port = cfg_port.split("|")
            for sup in duthosts.supervisor_nodes:
                check_rif_on_sup(sup, sys_slot, sys_asic, sys_port)

        elif porttype == 'port':
            # this is the RIF on the inband port.
            inband = get_inband_info(cfg_facts)
            logger.info("RIF: %s is on local port: %s", rif, inband['port'])

            # check MTU and ethernet address
            pytest_assert(
                asicdb_rif_table[rif]['value']["SAI_ROUTER_INTERFACE_ATTR_MTU"]
                == cfg_facts['PORT'][inband['port']]['mtu'],
                "MTU for rif %s is not %s" %
                (rif, cfg_facts['PORT'][inband['port']]['mtu']))
            intf_mac = get_sonic_mac(per_host, asic.asic_index, inband['port'])
            pytest_assert(
                asicdb_rif_table[rif]['value']
                ["SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS"].lower() ==
                intf_mac.lower(), "MAC for rif %s is not %s" % (rif, intf_mac))

            sysport_info = find_system_port(dev_sysports, slot,
                                            asic.asic_index, inband['port'])

            for sup in duthosts.supervisor_nodes:
                check_rif_on_sup(sup, sysport_info['slot'],
                                 sysport_info['asic'], inband['port'])

        # TODO: Could be on a LAG

    # Verify each RIF in config had a corresponding local port RIF in the asicDB.
    for rif in dev_intfs:
        pytest_assert(
            rif in rif_ports_in_asicdb,
            "Interface %s is in configdb.json but not in asicdb" % rif)

    logger.info("Interfaces %s are present in configdb.json and asicdb" %
                str(dev_intfs.keys()))