예제 #1
0
def getTestId(module):
    """This program is to create txt file for test ID.
    Usage: getTestIdforTestLink.py <module_name>"""
    module_path=default_path+'/'+module
    if not os.path.exists(module_path):
        print '%s is not exist. Exit.' % module_path
        sys.exit()
    data=[]
    if module=='EventParsing':
        folders=os.listdir(module_path)
        if '.svn' in folders:
            folders.remove('.svn')
        for f in folders:
            index_file=module_path+'/'+f+'/Index'
            data=CSVHandler.getDataFromFile(data_meta[module], index_file, None, None)
            myW=open(module+'.txt', 'w')
            for key in data.keys():
                holder=[]
                holder.append(key)
                holder.append(desc[module] % data[key].name)
                myW.write(','.join(holder)+'\n')
            myW.close()
    else:
        index_file=module_path+'/'+module[0].lower()+module[1:]+'Data.csv'
        data=CSVHandler.getDataFromFile(data_meta[module], index_file, None, None)
        myW=open(module+'.txt', 'w')
        for key in data.keys():
            holder=[]
            holder.append(key)
            holder.append(desc[module] % data[key].name)
            myW.write(','.join(holder)+'\n')
        myW.close()
예제 #2
0
    def getCommonData(self, taskFiles):
        indexModule = {}
        if taskFiles.lower() == 'all':
            folders = os.listdir(self.path)
            if '.svn' in folders:
                folders.remove('.svn')
        else:
            folders = taskFiles.split(',')
        for f in folders:
            rawData = CSVHandler.getDataFromFile('eventParsingData',
                                                 self.path + '/' + f +
                                                 '/Index',
                                                 None,
                                                 None,
                                                 asCsv=False)
            for key in rawData.keys():
                if rawData[key].reptDevIpAddr == '$localhost':
                    rawData[key].reptDevIpAddr = self.testConfig.localhost
                if f not in indexModule.keys():
                    indexModule[f] = {}
                    indexModule[f][key] = rawData[key]
                else:
                    indexModule[f][key] = rawData[key]
        self.commons = indexModule

        return self.commons
예제 #3
0
 def getEventTypesInModule(self, module):
     indexPath = self.dbPath + '/' + str(module) + '/Index'
     indexData = {}
     if os.path.exists(indexPath):
         self.index = CSVHandler.getDataFromFile('eventParsingData',
                                                 indexPath,
                                                 None,
                                                 None,
                                                 asCsv=False)
         map = {}
         maxId = 1
         for key in self.index:
             eventType = self.index[key].eventType
             id = int(self.index[key].name.split('_')[-1])
             if id > maxId:
                 maxId = id
             if eventType not in indexData.keys():
                 indexData[eventType] = [self.index[key]]
             else:
                 exist_cases = indexData[eventType]
                 exist_cases.append(self.index[key])
                 indexData[eventType] = exist_cases
         map['indexPath'] = indexPath
         map['indexData'] = indexData
         map['maxId'] = maxId
         self.module_event_map[module] = map
예제 #4
0
def addEventParsingCase(appServer, module, fileName, method):
    myLocal=socket.gethostbyname(socket.gethostname())
    myQuery=queryHandler(appServer)
    myFile=open(fileName)
    data=myFile.readlines()
    myFile.close()
    reporters=[]
    eventtypes=[]
    for line in data:
        reporter,eventtype=line.split(',')
        if reporter not in reporters:
            reporters.append(reporter)
        if eventtype.strip() not in eventtypes:
            eventtypes.append(eventtype.strip())
    reporterStr=','.join(reporters)
    eventStr='","'.join(eventtypes)
    params={}
    params['SingleEvtConstr']=event_query_params['SingleEvtConstr'] % (reporterStr, eventStr)
    retSubData=myQuery.getQuery(params, incident_query_report_interval)
    topPath=test_path % 'EventParsing'
    sumData=CSVHandler.getDataFromFile('eventParsingData', topPath+'/eventParsingData.csv', None, None)
    modifyData={}
    for itemkey in sumData.keys():
        if sumData[itemkey].module not in modifyData.keys():
            modifyData[sumData[itemkey].module]={}
            modifyData[sumData[itemkey].module][itemkey]=sumData[itemkey]
        else:
            modifyData[sumData[itemkey].module][itemkey]=sumData[itemkey]
    if module in modifyData.keys():
        startCaseNum=int(modifyData[module][-1].name.split(module)[-1])
    else:
        startCaseNum=0
    i=1
    summary={}
    detail={}
    for subkey in retSubData.keys():
        obj=ClassLocator.getClassObj('eventParsingData', module='test')
        obj.module=module
        if startCaseNum+i < 10:
            obj.name=module+'0'+str(startCaseNum+i)
        else:
            obj.name=module+str(startCaseNum+i)
        i+=1
        newType,newIp=subkey.split('@')
        subData=retSubData[subkey][-1].attributes
        params={}
        msg=''
        for parKey in subData:
            if parKey=='rawEventMsg':
                msg=subData[parKey]
                if newIp not in msg:
                    newIp='$localhost'
            else:
                if parKey in event_any_params:
                    params[parKey]='any'
                else:
                    params[parKey]=subData[parKey]
        obj.eventType=newType
        obj.reptDevIpAddr=newIp
        obj.method=method
        summary[obj.name]=obj
        map={}
        map['reporter']=newIp
        map['msg']=msg
        map['param']=params
        if newType+'.dat' in detail.keys():
            detail[newType+'.dat'].append(map)
        else:
            detail[newType+'.dat']=[map]
    modulePath=topPath+'/'+module
    if not os.path.exists(modulePath):
        os.mkdir(modulePath)
    files=os.listdir(modulePath)
    if module not in modifyData.keys():
        modifyData[module]=summary
    else:
        for subkey in summary.keys():
            modifyData[module][subkey]=summary[subkey]
    myWrite=open(topPath+'/eventParsingData.csv', 'w')
    myWrite.write(summary_title+'\n')
    for subkey in modifyData.keys():
        for morekey in modifyData[subkey].keys():
            myObj=modifyData[subkey][morekey]
            eventtype=myObj.eventType
            mykey=''
            line=summary_line % (eventtype, myObj.name, myObj.module, myObj.reptDevIpAddr, mykey, myObj.method)
            myWrite.write(line+'\n')
    myWrite.close()
    for itemkey in detail:
        file=itemkey
        for rep in event_replace_symbol:
            if rep in itemkey:
                file=file.replace(rep, '$')
        fullPath=topPath+'/'+module+'/'+file
        if os.path.exists(fullPath):
            myDetail=open(fullPath, 'a')
        else:
            myDetail=open(fullPath, 'w')
        for sub in detail[itemkey]:
            myDetail.write(Title['reporter']+'\n')
            myDetail.write(sub['reporter']+'\n')
            myDetail.write(Title['msg']+'\n')
            myDetail.write(sub['msg']+'\n')
            myDetail.write(Title['param']+'\n')
            sub['param']['phCustId']='$sender'
            sub['param']['relayDevIpAddr']='$localhost'
            if sub['param']['reptDevIpAddr']==myLocal:
                sub['param']['reptDevIpAddr']='$localhost'
            for parkey in sub['param'].keys():
                myDetail.write(parkey+'='+sub['param'][parkey]+'\n')
        myDetail.close()
    print 'Done'
예제 #5
0
    def getCommonData(self, param):
        self.commons = CSVHandler.getDataFromFile(
            'logDiscoverData', self.path + '/logDiscoverData.csv', None, None)

        return self.commons
예제 #6
0
 def getCommonData(self, taskFiles):
     return CSVHandler.getDataFromFile('incidentData',
                                       self.path + '/incidentData.csv',
                                       None, None)
예제 #7
0
    def getCommonData(self):
        indexData = CSVHandler.getDataFromFile(
            'DbPopulatorData', self.path + '/DbPopulatorData.csv', None, None)
        self.commons = indexData

        return self.commons