Esempio n. 1
0
def verify_lag_member_in_asic_db(asics, lag_id, pc_members, deleted=False):
    """
       Verifies lag member in ASIC DB
       It runs the command e.g.
    """
    for asic in asics:
        asicdb = AsicDbCli(asic)
        asic_lag_list = asicdb.get_asic_db_lag_list()
        asic_db_lag_member_list = asicdb.get_asic_db_lag_member_list()
        lag_oid = None
        if deleted:
            for lag in asic_lag_list:
                if asicdb.hget_key_value(
                        lag,
                        "SAI_LAG_ATTR_SYSTEM_PORT_AGGREGATE_ID") == lag_id:
                    lag_oid = ":".join(lag for lag in lag.split(':')[-1:-3:-1])

            for lag_member in asic_db_lag_member_list:
                if asicdb.hget_key_value(
                        lag_member, "SAI_LAG_MEMBER_ATTR_LAG_ID") == lag_oid:
                    pytest.fail(
                        "lag members {} still exist in lag member table on {},"
                        " Expected was should be deleted".format(
                            pc_members, asic.sonichost.hostname))
            logging.info('Lag members are deleted from {} on {}'.format(
                asic.asic_index, asic.sonichost.hostname))

        else:
            for lag in asic_lag_list:
                if asicdb.hget_key_value(
                        lag,
                        "SAI_LAG_ATTR_SYSTEM_PORT_AGGREGATE_ID") == lag_id:
                    lag_oid = ":".join(lag for lag in lag.split(':')[-2::1])
                    break

            for lag_member in asic_db_lag_member_list:
                if asicdb.hget_key_value(
                        lag_member, "SAI_LAG_MEMBER_ATTR_LAG_ID") == lag_oid:
                    logging.info('Lag members exist in {} on {}'.format(
                        asic.asic_index, asic.sonichost.hostname))
                    return

            pytest.fail('Lag members {} does not exist in {} on {}'.format(
                pc_members, asic.asic_index, asic.sonichost.hostname))
Esempio n. 2
0
def verify_lag_in_asic_db(asics, lag_id, deleted=False):
    """
    Verifies LAG in ASIC DB
    Args:
        asics<list>: asic
        lag_id<int>: lag id
        deleted<bool>: True if lag is deleted
    """
    for asic in asics:
        asicdb = AsicDbCli(asic)
        asic_db_lag_list = asicdb.get_asic_db_lag_list()
        if deleted:
            for lag in asic_db_lag_list:
                if asicdb.hget_key_value(
                        lag,
                        "SAI_LAG_ATTR_SYSTEM_PORT_AGGREGATE_ID") == lag_id:
                    pytest.fail('LAG id {} for LAG {} exist in ASIC DB,'
                                ' Expected was should not be present'.format(
                                    lag_id, TMP_PC))

            logging.info(
                'LAG id {} for LAG {} does not exist in ASIC DB'.format(
                    lag_id, TMP_PC))

        else:
            for lag in asic_db_lag_list:
                if asicdb.hget_key_value(
                        lag,
                        "SAI_LAG_ATTR_SYSTEM_PORT_AGGREGATE_ID") == lag_id:
                    logging.info(
                        'LAG id {} for LAG {} exist in ASIC DB'.format(
                            lag_id, TMP_PC))
                    return
            pytest.fail(
                'LAG id {} for LAG {} does not exist in ASIC DB'.format(
                    lag_id, TMP_PC))
Esempio n. 3
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()))