def initSubDataMap(cls): slatypeData = cls._getSubDataValue('slatype') for sla_id in slatypeData.keys(): if slatypeData[sla_id]: continue slaObj = queryCatInfo('sla', {'id': sla_id})[0] slatypeData[sla_id] = getValue(slaObj, 'name') viewtypeData = cls._getSubDataValue('viewtype') for view_id in viewtypeData.keys(): if viewtypeData[view_id]: continue viewObj = queryCatInfo('viewtype', {'id': view_id})[0] viewtypeData[view_id] = getValue(viewObj, 'name') cls._raw_initialized = True
def getBugId(bugzillaId): retObjs = queryCatInfo('bugzilla', {'number': bugzillaId}) if not retObjs: logger.error("Bug PR %s hasn't added into CAT database yet", bugzillaId) return None else: return getId(retObjs[0])
def getMachineId(hostName): retObjs = queryCatInfo('machine', {'hostname': hostName}, apiVersion='v3.0') if not retObjs: raise Exception("No machine named as %s" % hostName) else: return getId(retObjs[0])
def getDeliverablesByBuild(buildId): retObjs = queryCatInfo('deliverable', {'build': buildId}) if not retObjs: raise Exception("No CAT deliverable generated by CAT build %d" % buildId) else: deliverableIds = [getId(retObj, 'id') for retObj in retObjs] return Deliverable.getFullyInitializedCatObjectList(deliverableIds)
def getBuildsByChangeset(changeset): """Return a list of Build instances whose CLN equals to changeset """ retObjs = queryCatInfo('build', {'changeset': changeset}) if not retObjs: raise Exception("No CAT build generated against CLN %s" % changeset) else: buildIds = [retObj['id'] for retObj in retObjs] return Build.getFullyInitializedCatObjectList(buildIds)
def queryTestrunsByDeliverableId(deliverableId, areaId, skipRunning=True): """ Quary all testruns by deliverable id """ testrunObjs = queryCatInfo('testrun', {'deliverables':deliverableId, 'area':areaId}) if not testrunObjs: raise Exception("No testrun run against with deliverables %s in area %s"\ % (deliverableId, areaId)) return Testrun.queryTestrunsByObjs(testrunObjs, skipRunning, skipPass=False, parserLog=False)
def queryTestrunsByDeliverableObjects(deliverableObjects, areaId, skipRunning=True): testrunObjs = [] for deliverable_obj in deliverableObjects: deliverableId= deliverable_obj.getId() testrunObjs.extend(queryCatInfo('testrun', {'deliverables':deliverableId, 'area':areaId})) if not testrunObjs: raise Exception("No testrun run against with deliverables %s in area %s"\ % (deliverableId, areaId)) return Testrun.queryTestrunsByObjs(testrunObjs, skipRunning, skipPass=False, parserLog=False)
def getBranchIds(branchNames): """Get branch Ids via branch name @branchName """ branchIds = [] for branchName in branchNames: retObjs = queryCatInfo('branch', {'name': branchName}) if not retObjs: raise Exception("No branch named as %s" % branchName) else: for retObj in retObjs: branchIds.append(getId(retObj)) return branchIds
def getDeliverablesByBuilder(builderId, limitDay=1): retObjs = queryCatInfo('deliverable', {'builder': builderId}, orderBy='-endtime', limitDay=7) if not retObjs: raise Exception( "No CAT deliverable generated from builder %d " "in the last %d days", builderId, limitDay) else: deliverableIds = [getId(retObj, 'id') for retObj in retObjs] return Deliverable.getFullyInitializedCatObjectList(deliverableIds)
def QueryEnabledWorkunitInArea(areaId): workunitObjs = [] search_obj = {'enabled':'true', 'area':areaId} workunitDatas = queryCatInfo('workunit', search_obj, apiVersion='v3.0') if not workunitDatas: raise Exception("Cannot find any workunit in area %s" % areaId) for workunitData in workunitDatas: wuId = getId(workunitData, "id") workunit = Workunit(wuId) workunit.initCatRawInfo() workunitObjs.append(workunit) return workunitObjs
def _queryTrObjsByWuIds(wuIds): trObjs = [] for wuId in wuIds: logger.info("Retrieving testrun data with workunit id %s", wuId) wuTrObjs = queryCatInfo('testrun', {'workunit': wuId}, limitDay=limitDay, limit=limitNumber, orderBy="-endtime") if wuTrObjs: logger.info("Totally get %d testruns" % len(wuTrObjs)) trObjs.extend(wuTrObjs) return trObjs
def getAreaIds(areaNames): """Get area Ids via area name @areaName """ areaIds = [] for areaName in areaNames: retObjs = queryCatInfo('area', {'name': areaName}) if not retObjs: raise Exception("No area named as %s " % areaName) else: for retObj in retObjs: areaIds.append(getId(retObj)) return areaIds
def getWorkloadIds(wlNames): """Get workload id via workload name @wlName """ wlIds = [] for wlName in wlNames: retObj = queryCatInfo('workload', {'name': wlName}) if not retObj: raise Exception("No workload named as %s " % wlName) else: wlIds.append(getId(retObj[0])) return wlIds
def initSubDataMap(cls): locationData = cls._getSubDataValue('location_id') for location_id in locationData.keys(): if locationData[location_id]: continue try: locationObj = queryCatInfo('location', {'id': location_id}, apiVersion='v3.0')[0] locationData[location_id] = getValue(locationObj, 'name') except: locationData[location_id] = NOT_AVALIABLE cls._raw_initialized = True
def getAreaownerIds(areaIds, branchIds): """Get areaowner ids via area ids and branch ids """ areaowners = [] for areaId in areaIds: for branchId in branchIds: tmpObjs = queryCatInfo('areaowner', { 'area': areaId, 'branch': branchId }, apiVersion='v3.0') for tmpObj in tmpObjs: areaowners.append(getId(tmpObj)) return areaowners
def getChildrenAreaIds(parentAreaIds): """Get children area Ids via parent area Ids """ childAreaIds = [] logger.debug("Get child area ids from parent area %s" % parentAreaIds) for parentAreaId in parentAreaIds: retObjs = queryCatInfo('area', {'parent': parentAreaId}) for retObj in retObjs: if not getValue(retObj, 'visible'): logger.debug("Child area %s is not visable ,skip" % getId(retObj)) continue childAreaIds.append(getId(retObj)) return childAreaIds
def _queryTrObjsByCatView(wlNames=None, areaIds=None, areaNames=None, branchNames=None, testerIds=None, bldTypes=None): def _argsWrapper(args): if not args: return [None] else: return args if not wlNames: wlIds = [None] else: from workload import Workload wlIds = Workload.getWorkloadIds(wlNames) if areaNames: areaIds = Area.getAreaIds(areaNames) elif areaIds: childrenIds = Area.getChildrenAreaIds(areaIds) if childrenIds: areaIds.extend(childrenIds) else: areaIds = [None] # The order for filterKey and filterLoop should be matched filterKey = ['workload', 'area__id__in', 'deliverables__build__branch__in', 'tester__id__in', 'deliverables__build__bldtype__in'] filterLoop = itertools.product(wlIds, areaIds, _argsWrapper(branchNames), _argsWrapper(testerIds), _argsWrapper(bldTypes)) filterLoop = list(filterLoop) trObjs = [] for item in filterLoop: filterMap = {} for i in range(len(item)): if item[i] is None: continue filterMap[filterKey[i]] = item[i] logger.info("Retrieving testrun data via RestAPI with filterInfo: %s", filterMap) tmpTrObjs = queryCatInfo('testrun', filterMap, limitDay=limitDay, limit=limitNumber, orderBy="-endtime") if tmpTrObjs: logger.info("Totally get %d testruns" % len(tmpTrObjs)) trObjs.extend(tmpTrObjs) return trObjs
def getBuildsByProductionInfo(product, branch, bldtype, limitDay=1): """ Get build info by product. """ retObjs = queryCatInfo('build', { 'site_name': product, 'branch': branch, 'bldtype': bldtype }, limitDay=limitDay) if not retObjs: raise Exception("No CAT build generated against CLN %s" % changeset) else: buildIds = [retObj['id'] for retObj in retObjs] return Build.getFullyInitializedCatObjectList(buildIds)
def queryTestrunsByCLN(cln, skipRunning=True): """Query testruns by CLN @rtype: a list of Testrun instances """ build_datas = Build.getBuildsByChangeset(cln) deliverable_ids = [] for build_data in build_datas: sub_deliverable_ids = build_data.getDeliverableIds() if sub_deliverable_ids: deliverable_ids.extend(sub_deliverable_ids) logger.info("Retrieving testrun data which deliverable id is in %s", deliverable_ids) testrunObjs = queryCatInfo('testrun', {'deliverables__id__in': ','.join(deliverable_ids)}) if not testrunObjs: raise Exception("No testrun run against with deliverables %s"\ % deliverable_ids) return Testrun.queryTestrunsByObjs(testrunObjs, skipRunning, skipPass=False, parserLog=False)
def __init__(self, catObjId, catObj=None): assert (self._objType is not None) assert (self._leafNode is not None) assert (self._subDataMap is not None) self._id = catObjId self._catObj = catObj if self._catObj is None: catData = queryCatInfo(self._objType, {'id': self._id}, apiVersion=self._api) if not catData: raise Exception("%s doesn't exist in CAT" % self) else: self._catObj = catData[0] else: # If defined catObj, treat as the baseline input self._id = getId(self._catObj) self._hyperlink = getCatHyperLink(self._objType, self._id) self._htmlId = genHyperLink(content=self._id, hyperlink=self._hyperlink) self._full_initialized = False