def SetupVlanGroups(self): topo = store.GetTopology() vmps = topo.GetVlanMappings() if vmps: origVlans = self.GetVlans() origVlanRangeString = self.__buildVlanRangeString(origVlans) vmo = int(len(origVlans)/len(vmps.items())) vlans = self.__splitVlans(origVlans, vmo) for x, (vgId, vmp) in enumerate(vmps.items()): skipAllocation = getattr(vmp,"skip_allocation", False) vlanRange = vlans[x] vlanRangeString = self.__buildVlanRangeString(vlanRange) for entry in vmp.groups: allocator = self.__getVlanAllocatorByGroupId(vgId) if not allocator: allocator = resmgr.TestbedMultiVlanAllocator(vgId, vlanRange[0], len(vlanRange), "classic", skipAllocation) allocator.addMember(entry.node, entry.nic, entry.port) self.__addMultiVlanAllocator(allocator) if not allocator.isMember(entry.node, entry.nic, entry.port): allocator.addMember(entry.node, entry.nic, entry.port) node = topo.GetNodeByName(entry.node) #this returns topo node object port = node.GetPortByIndex(entry.nic, entry.port) nic_device = node.GetDeviceByNicNumber(entry.nic) portspeed = nic_device.GetPortSpeed() self.__sendSetVlanRequest(port.get("SwitchIP"), port.get("SwitchPort"), origVlanRangeString, port.get("SwitchUsername"), port.get("SwitchPassword"), True, portspeed) self.__sendSetVlanRequest(port.get("SwitchIP"), port.get("SwitchPort"), vlanRangeString, port.get("SwitchUsername"), port.get("SwitchPassword"), False, portspeed) return types.status.SUCCESS
def get_athena_node_nic_names(): node_nic_names = [] nics = store.GetTopology().GetNicsByPipeline("athena") for nic in nics: node_nic_names.append((nic.GetNodeName(), nic.Name())) return node_nic_names
def ExitHandler(self): if GlobalOptions.dryrun: return status = self.__teardown() Logger.info(f"Testsuite {self.Name()} teardown STATUS = {status}") api.UnsetBreakoutInterfaces() logcollector.CollectLogs() logcollector.CollectTechSupport(self.Name()) self.CollectCores() self.writeTestResults() if store.GetTestbed().IsUsingProdVCenter(): store.GetTestbed().CleanupTestbed() store.GetTopology().CleanupTopology() return
def __apply_skip_filters(self): if not api.IsSimulation() and not store.GetTestbed().GetOs( ).intersection(self.__spec.meta.os) and not GlobalOptions.dryrun: Logger.info("Skipping Testbundle: %s due to OS mismatch." % self.__spec.meta.name) return True if GlobalOptions.testbundles and self.__spec.meta.name not in GlobalOptions.testbundles: Logger.info("Skipping Testbundle: %s due to cmdline filter." % self.__spec.meta.name) return True if not self.__parent.IsBitw() and store.GetTopology().ValidateNics( self.__spec.meta.nics) != True and not GlobalOptions.dryrun: Logger.info("Skipping Testbundle: %s due to Incompatible NICs." % self.__spec.meta.name) return True return False
def CollectLogs(): if GlobalOptions.dryrun or GlobalOptions.skip_logs: return nodes = [] try: for node in store.GetTopology().GetNodes(): node.username = node.MgmtUserName() node.password = node.MgmtPassword() node.ip = node.MgmtIpAddress() cimcInfo = node.GetCimcInfo() if cimcInfo: node.cimcIp = cimcInfo.GetIp() node.cimcUsername = cimcInfo.GetUsername() node.cimcPassword = cimcInfo.GetPassword() nodes.append(node) except Exception as e: Logger.debug( 'topo not setup yet, gathering node info from testbed json file: %s' % str(e)) nodes = buildNodesFromTestbedFile(GlobalOptions.testbed_json) pool = ThreadPool(len(nodes)) results = pool.map(__collect_onenode, nodes)
def Setup(tc): # get node info tc.bitw_node_name = None tc.wl_node_name = None tc.wl_node = None # Assuming only one bitw node and one workload node nics = store.GetTopology().GetNicsByPipeline("athena") for nic in nics: tc.bitw_node_name = nic.GetNodeName() break workloads = api.GetWorkloads() if len(workloads) == 0: api.Logger.error('No workloads available') return api.types.status.FAILURE tc.wl_node_name = workloads[0].node_name tc.nodes = api.GetNodes() for node in tc.nodes: if node.Name() == tc.wl_node_name: tc.wl_node = node api.SetTestsuiteAttr("bitw_node_name", tc.bitw_node_name) api.SetTestsuiteAttr("wl_node_name", tc.wl_node_name) api.SetTestsuiteAttr("wl_node", tc.wl_node) api.SetTestsuiteAttr( "send_pkt_path", api.GetTopDir() + '/iota/test/athena/testcases/networking/scripts/send_pkt.py') api.SetTestsuiteAttr( "recv_pkt_path", api.GetTopDir() + '/iota/test/athena/testcases/networking/scripts/recv_pkt.py') return api.types.status.SUCCESS
def Setup(tc): # get node info tc.bitw_node_name = None tc.wl_node_name = None # Assuming only one bitw node and one workload node nics = store.GetTopology().GetNicsByPipeline("athena") for nic in nics: tc.bitw_node_name = nic.GetNodeName() break api.SetTestsuiteAttr("bitw_node_name", tc.bitw_node_name) workloads = api.GetWorkloads() if len(workloads) == 0: api.Logger.error('No workloads available') return api.types.status.FAILURE tc.wl_node_name = workloads[0].node_name api.SetTestsuiteAttr("wl_node_name", tc.wl_node_name) host_intfs = api.GetNaplesHostInterfaces(tc.wl_node_name) # Assuming single nic per host if len(host_intfs) != 2: api.Logger.error('Failed to get host interfaces') return api.types.status.FAILURE tc.wl = [] for wl in workloads: tc.wl.append(wl) api.Logger.info("wl: vlan: {}, mac: {}, ip: {}".format( wl.uplink_vlan, wl.mac_address, wl.ip_address)) tc.intfs = [] tc.intfs.append({ 'name': 'inb_mnic0', 'ip': str(tc.wl[0].ip_address), 'sub_ip': str(tc.wl[2].ip_address), 'vlan': str(tc.wl[2].uplink_vlan) }) tc.intfs.append({ 'name': 'inb_mnic1', 'ip': str(tc.wl[1].ip_address), 'sub_ip': str(tc.wl[3].ip_address), 'vlan': str(tc.wl[3].uplink_vlan) }) api.SetTestsuiteAttr("inb_mnic_intfs", tc.intfs) # copy device_bootstrap.json to naples bootstrap_json_fname = api.GetTopDir( ) + '/nic/conf/athena/device_bootstrap.json' api.CopyToNaples(tc.bitw_node_name, [bootstrap_json_fname], "") # write and copy pensando_pre_init.sh to naples f = open('pensando_pre_init.sh', "w") f.write('echo "copying device.json"\n') f.write('cp /data/device_bootstrap.json /nic/conf/device.json\n') f.close() api.CopyToNaples(tc.bitw_node_name, ['pensando_pre_init.sh'], "") os.remove('pensando_pre_init.sh') # move pensando_pre_init.sh to /sysconfig/config0/ and restart Athena Node req = api.Trigger_CreateExecuteCommandsRequest() cmd = "mv /pensando_pre_init.sh /sysconfig/config0/" api.Trigger_AddNaplesCommand(req, tc.bitw_node_name, cmd) cmd = "mv /device_bootstrap.json /data/" api.Trigger_AddNaplesCommand(req, tc.bitw_node_name, cmd) resp = api.Trigger(req) cmd = resp.commands[0] api.PrintCommandResults(cmd) if cmd.exit_code != 0: api.Logger.error("Bootstrap setup failed on node %s" % \ tc.bitw_node_name) return api.types.status.FAILURE # reboot the node api.Logger.info("Rebooting {}".format(tc.bitw_node_name)) return api.RestartNodes([tc.bitw_node_name], 'reboot')
def ReImageTestbed(self, req_json, devices={}): """ Build a new image-manifest file for initializing Naples and Driver """ # Generate new image manifest file Logger.info("Building new image-manifest {}".format(req_json)) if devices: nodeNames = [val['nodeName'] for key,val in devices.items()] reimg_req = parser.ParseJsonStream(req_json) with open(self.__image_manifest_file, "r") as fh: new_img_manifest = json.loads(fh.read()) manifest_file = self.__image_manifest_file self.__fw_upgrade_done = False reimage_driver = getattr(reimg_req, 'InstallDriver', False) reimage_firmware = getattr(reimg_req, 'InstallFirmware', False) # pick the non-latest versions if reimage_driver: # driver image to be changed new_img_manifest["Drivers"] = None dr_img_manifest_file = os.path.join(GlobalOptions.topdir, "images", reimg_req.DriverVersion + ".json") with open(dr_img_manifest_file, "r") as fh: dr_img_manifest = json.loads(fh.read()) new_img_manifest["Drivers"] = dr_img_manifest["Drivers"] if reimage_firmware: # Firmware image to be changed new_img_manifest["Firmwares"] = None fw_img_manifest_file = os.path.join(GlobalOptions.topdir, "images", reimg_req.FirmwareVersion + ".json") with open(fw_img_manifest_file, "r") as fh: fw_img_manifest = json.loads(fh.read()) new_img_manifest["Firmwares"] = fw_img_manifest["Firmwares"] if reimage_driver or reimage_firmware: new_img_manifest["Version"] = "NA" # TODO # Create {GlobalOptions.topdir}/images if not exists folder = os.path.join(GlobalOptions.topdir, "images") if not os.path.isdir(folder): os.mkdir(folder) manifest_file = os.path.join(folder, reimg_req.TestCaseName + ".json") with open(manifest_file, "w") as fh: fh.write(json.dumps(new_img_manifest, indent=2)) # Call API to reimage testbed : restrict for naples nodes only GlobalOptions.only_reboot = False GlobalOptions.skip_firmware_upgrade = False if devices: store.GetTopology().SaveNodes(nodeNames) self.__recover_testbed(manifest_file, driver_reimage_only=reimage_driver and not reimage_firmware, firmware_reimage_only=reimage_firmware and not reimage_driver, naples_host_only=True, devices=devices) if devices: store.GetTopology().RestoreNodes(nodeNames) return types.status.SUCCESS
def __getNodeByName(self, nodeName): node = [node for node in store.GetTopology().GetNodes() if node._Node__name == nodeName] if node == []: return None return node[0]