def test_voq_switch_create(duthosts): """Compare the config facts with the asic db for switch: * Verify ASIC_DB get all system ports referenced in configDB created on all hosts and ASICs. * Verify object creation and values of port attributes. """ switch_id_list = [] for per_host in duthosts.frontend_nodes: for asic in per_host.asics: cfg_facts = asic.config_facts(source="persistent")['ansible_facts'] dev_facts = cfg_facts['DEVICE_METADATA']['localhost'] asicdb = AsicDbCli(asic) switchkey = asicdb.get_switch_key() logger.info("Checking switch %s", switchkey) check_list = { "max_cores": "SAI_SWITCH_ATTR_MAX_SYSTEM_CORES", "switch_id": "SAI_SWITCH_ATTR_SWITCH_ID" } for k in check_list: asicdb.get_and_check_key_value(switchkey, dev_facts[k], field=check_list[k]) pytest_assert( dev_facts["switch_id"] not in switch_id_list, "Switch ID: %s has been used more than once" % dev_facts["switch_id"]) switch_id_list.append(dev_facts["switch_id"]) asicdb.get_and_check_key_value(switchkey, "SAI_SWITCH_TYPE_VOQ", field="SAI_SWITCH_ATTR_TYPE")
def test_voq_switch_create(self, duthosts, enum_frontend_dut_hostname, enum_asic_index, all_cfg_facts): """Compare the config facts with the asic db for switch: * Verify ASIC_DB get all system ports referenced in configDB created on all hosts and ASICs. * Verify object creation and values of port attributes. """ 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'] dev_facts = cfg_facts['DEVICE_METADATA']['localhost'] asicdb = AsicDbCli(asic) switchkey = asicdb.get_switch_key() logger.info("Checking switch %s", switchkey) check_list = { "max_cores": "SAI_SWITCH_ATTR_MAX_SYSTEM_CORES", "switch_id": "SAI_SWITCH_ATTR_SWITCH_ID" } for k in check_list: asicdb.get_and_check_key_value(switchkey, dev_facts[k], field=check_list[k]) pytest_assert( dev_facts["switch_id"] not in TestVoqSwitch.SWITCH_ID_LIST, "Switch ID: %s has been used more than once" % dev_facts["switch_id"]) TestVoqSwitch.SWITCH_ID_LIST.append(dev_facts["switch_id"]) asicdb.get_and_check_key_value(switchkey, "SAI_SWITCH_TYPE_VOQ", field="SAI_SWITCH_ATTR_TYPE")
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()))