def ValidateLearntMacEntries(self, node, ret, cli_op): if utils.IsDryRun(): return True if not ret: logger.error("pdsctl show learn mac cmd failed") return False # split output per object mac_entries = cli_op.split("---") for mac in mac_entries: yamlOp = utils.LoadYaml(mac) if not yamlOp: continue yamlOp = yamlOp['macentry']['entryauto'] mac_key = yamlOp['key']['macaddr'] subnet_uuid = utils.GetYamlSpecAttr(yamlOp['key'], 'subnetid') vnic_uuid_str = utils.List2UuidStr( utils.GetYamlSpecAttr(yamlOp, 'vnicid')) # verifying if the info learnt is expected from config vnic_obj = self.GetVnicByL2MappingKey(node, mac_key, subnet_uuid, 0) if vnic_obj == None: logger.error( f"vnic not found in client object store for key {mac_key} {subnet_uuid}{0}" ) return False # verifying if VNIC has been programmed correctly by Learn args = "--id " + vnic_uuid_str ret, op = utils.RunPdsctlShowCmd(node, "vnic", args, True) if not ret: logger.error(f"show vnic failed for vnic id {vnic_uuid_str}") return False cmdop = op.split("---") logger.info("Num entries returned for vnic show id %s is %s" % (vnic_uuid_str, (len(cmdop) - 1))) for vnic_entry in cmdop: yamlOp = utils.LoadYaml(vnic_entry) if not yamlOp: continue vnic_spec = yamlOp['spec'] hostif = vnic_spec['hostif'] if utils.PdsUuid( hostif).GetUuid() != vnic_obj.HostIfUuid.GetUuid(): logger.error( f"host interface did not match for {vnic_uuid_str}") return False if vnic_spec['macaddress'] != vnic_obj.MACAddr.getnum(): logger.error( f"mac address did not match for {vnic_uuid_str}") return False logger.info( "Found VNIC %s entry for learn MAC MAC:%s, Subnet:%s, VNIC:%s " % (utils.List2UuidStr(utils.GetYamlSpecAttr( vnic_spec, 'id')), vnic_obj.MACAddr.get(), vnic_obj.SUBNET.UUID, vnic_uuid_str)) return True
def VerifyVnicStats(self, spec): if utils.IsDryRun(): return True cmd = "vnic statistics --id " + self.UUID.String() status, op = pdsctl.ExecutePdsctlShowCommand(cmd, None) entries = op.split("---") yamlOp = utils.LoadYaml(entries[0]) if not yamlOp: return False statAttrs = [ 'RxPackets', 'RxBytes', 'TxPackets', 'TxBytes', 'MeterRxPackets', 'MeterRxBytes', 'MeterTxPackets', 'MeterTxBytes' ] mismatch = False for statAttr in statAttrs: lstatAttr = statAttr.lower() if yamlOp['stats'][lstatAttr] != getattr( self.Stats, statAttr) + spec[lstatAttr]: preStat = getattr(self.Stats, statAttr) expStat = preStat + spec[lstatAttr] output = yamlOp['stats'][lstatAttr] logger.info( f"{statAttr} mismatch. PreStat: %d, ExpStat: %d, Output: %d" % (preStat, expStat, output)) mismatch = True if mismatch: return False return True
def ValidatePdsctlRead(self, node, ret, stdout): if utils.IsDryRun(): return True if not ret: logger.error("pdsctl show cmd failed for ", self.ObjType) return False device = self.GetObjectByKey(node, 0) if "API_STATUS_NOT_FOUND" in stdout: if device.IsHwHabitant(): logger.error(f"GRPC get request failed for {device} with {stdout}") device.Show() return False return True # split output per object cmdop = stdout.split("---") for op in cmdop: yamlOp = utils.LoadYaml(op) if not yamlOp: continue device = self.GetObjectByKey(node, 0) resp = yamlOp['response'] if not utils.ValidateObject(device, resp, yaml=True): logger.error("pdsctl read validation failed for ", op) device.Show() return False return True
def ValidatePdsctlRead(self, node, ret, stdout): if utils.IsDryRun(): return True if not ret: logger.error("pdsctl show cmd failed for ", self.ObjType) return False # split output per object cmdop = stdout.split("---") assert((len(cmdop) - 1) == self.GetNumHwObjects(node)) for op in cmdop: yamlOp = utils.LoadYaml(op) if not yamlOp: continue key = self.GetKeyfromSpec(yamlOp['spec'], yaml=True) cfgObj = self.GetObjectByKey(node, key) if not utils.ValidateObject(cfgObj, yamlOp, yaml=True): logger.error("pdsctl read validation failed for ", op) cfgObj.Show() return False return True
def VerifyLearntIpEntries(self, node, ret, cli_op): if utils.IsDryRun(): return True if not ret: logger.error("pdsctl show learn ip cmd failed") return False # split output per object ip_entries = cli_op.split("---") for ip in ip_entries: yamlOp = utils.LoadYaml(ip) if not yamlOp: continue ip = yamlOp['key']['ipaddr']['v4orv6']['v4addr'] ip_str = utils.Int2IPAddrStr(ip) vpc_uuid = utils.GetYamlSpecAttr(yamlOp['key'], 'vpcid') vpc_uuid_str = utils.List2UuidStr(vpc_uuid) subnet_uuid = utils.GetYamlSpecAttr(yamlOp['macinfo'], 'subnetid') mac_str = utils.Int2MacStr(yamlOp['macinfo']['macaddr']) # verifying if the info learnt is expected from config lmap_obj = self.GetLMapObjByEpIpKey(node, ip_str, vpc_uuid) if lmap_obj == None: logger.error(f"lmap not found in client object store for key {vpc_uuid_str}, {ip_str}") return False # verifying if the EP is from local mapping. args = " | grep " + vpc_uuid_str + " | grep " + ip_str + " | grep " + mac_str ret, op = utils.RunPdsctlShowCmd(node, "mapping internal local", args, False) if not ret: logger.error(f"show mapping internal local failed for VPC id {vpc_uuid_str}, IP {ip_str}") return False cmdop = op.split('\n') if not len(cmdop): logger.error("No (%s) entries found in lmap show VPC id %s, IP %s "%( len(cmdop), vpc_uuid_str, ip_str)) return False logger.info("Found (%s) LMAP entry for learn IP:%s, VPC:%s MAC:%s, Subnet:%s "%( (len(cmdop)-1), ip_str, vpc_uuid_str, mac_str, utils.List2UuidStr(subnet_uuid))) return True
def __generate_host_interfaces_iota(self, node, topospec): cmd_op = self.ReadLifs(node) if utils.IsDryRun(): return for lif in cmd_op: lif_yaml = utils.LoadYaml(lif) if not lif_yaml: continue lif_spec = lif_yaml['spec'] lif_status = lif_yaml['status'] intf_type = lif_spec['type'] spec = InterfaceSpec_() spec.iid = utils.LifIfIndex2HostIfIndex(lif_status['ifindex']) node_mac = 0 for x in lif_spec['id'][-6:]: node_mac = ((node_mac << 8) | x) spec.uuid = utils.PdsUuid(spec.iid, node_uuid=node_mac) spec.ifname = lif_status['name'] spec.macaddress = objects.MacAddressBase( integer=lif_spec['macaddress']) spec.origin = 'implicitly-created' spec.txpolicer = False if hasattr(topospec, 'hostinterface'): if getattr(topospec.hostinterface, 'txpolicer', False) == True: spec.txpolicer = True if intf_type == types_pb2.LIF_TYPE_INBAND_MGMT: inb_mgmtif = InbandMgmtInterfaceObject(node, spec) self.__inband_mgmt_ifs[node].update( {inb_mgmtif.GetInterfaceName(): inb_mgmtif}) elif intf_type == types_pb2.LIF_TYPE_HOST: hostif = HostInterfaceObject(node, spec) self.__hostifs[node].update({hostif.InterfaceId: hostif}) if self.__hostifs[node]: self.__hostifs_iter[node] = utils.rrobiniter( sorted(self.__hostifs[node].keys())) return
def VerifyLearntIpEntriesWithRemoteMapping(self, node, peer_node, ret, cli_op): if utils.IsDryRun(): return True if not ret: logger.error("pdsctl show learn ip cmd failed for %s" % peer_node) return False # split output per object ip_entries = cli_op.split("---") for ip in ip_entries: yamlOp = utils.LoadYaml(ip) if not yamlOp: continue yamlOp = yamlOp['ipentry']['entryauto'] ip = yamlOp['key']['ipaddr']['v4orv6']['v4addr'] ip_str = utils.Int2IPAddrStr(ip) vpc_uuid = utils.GetYamlSpecAttr(yamlOp['key'], 'vpcid') subnet_uuid = utils.GetYamlSpecAttr(yamlOp['macinfo'], 'subnetid') mac = yamlOp['macinfo']['macaddr'] if not self.ValidateRemoteMappingInfo(node, ip_str, vpc_uuid, mac, subnet_uuid): return False return True