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()
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
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
def testGroupDefinition(self, type): for test in TestConstant.group_tasks.keys(): print '\nGroup Defn Test Task: %s' % test file = self.path + test + '.csv' data = CSVHandler.getDatafromFile(file) if not hasattr(self, 'groups'): self.groups = self.configHandler.getData('group') retData = self.groups[TestConstant.group_tasks[test]] self.verifyData(data, retData, self.__getListKey('group'))
def testGeneralDefinition(self, type=False): if type: tests = [type] else: tests = TestConstant.general_tasks.keys() for test in tests: print '\nTest %s' % test myPath = self.__getPath( type) + '.' + TestConstant.general_tasks[type] if TestConstant.general_tasks[type] == 'xml': indexData = XmlHandler.getDatafromFile(myPath, type) elif TestConstant.general_tasks[type] == 'csv': indexData = CSVHandler.getDatafromFile(myPath, type=type) retData = self.configHandler.getData(test) self.verifyData(indexData, retData, testUtility.getListKey(type))
def __getOriData(self, task, fileName): test, type = fileName.split('.') path = self.__getPath(task) file = path + fileName if type == 'csv': data = CSVHandler.getDatafromFile(file) elif type == 'xml': mydata = XMLHelper.unpickleFile(file, XML_TYPE[test], type='list') data = {} for item in mydata: for attr in classUtility.getAttrList(item): if attr in SPECIAL_LIST: newValue = self.__specialFormat(item, attr) setattr(item, attr, newValue) key = getattr(item, XML_DATAKEY[test]) data[key] = item return data
def __indexEventParser(self, fileList, type, myPath): for file in fileList: if '.xml' not in file or file in SKIP_FILES: fileList.remove(file) data = {} for file in fileList: name = file.split('.')[0] myFile = open(myPath + file, 'r') text = '' for line in myFile.readlines(): text += line.replace('\n', '') myFile.close() data[name] = text indexData = {} deviceTypes = self.__getCMDBData('deviceType') orderData = CSVHandler.getDatafromFile(myPath + 'parserOrder.csv') pattern = re.compile(REGEX) for key in data.keys(): if SPLIT['head'] in data[key]: valueHead = SPLIT['head'] else: valueHead = SPLIT['althead'] myHead = data[key].split(valueHead, 1) if len(myHead) == 2: middle = myHead[1] else: print 'there is no such data pattern.' myTail = middle.split(SPLIT['tail']) myObj = locateClassInstance.getClassInstance(type) myObj.attribute['name'] = key myObj.parserXml = valueHead + myTail[0] + SPLIT['tail'] myWord = myHead[0].split('</deviceType')[0] ret = pattern.search(myWord) myType = ret.group('modelName') + '-' + ret.group('vendorName') if myType in deviceTypes.keys(): myObj.deviceType = deviceTypes[myType] myObj.priority = orderData[key].priority indexData[key] = myObj return indexData
def testModule(self, type): print 'type: %s' % type.name myPath = self.__getPath(type.name) print 'path: %s' % myPath indexData = {} if type.name in testConstant.populator_task_trans.keys(): typeName = testConstant.populator_task_trans[type.name] else: typeName = type.name print 'type: %s' % typeName if type.fileType == 'xml': indexData = self.__getXMLData(type.name, myPath) elif type.fileType == 'csv': indexData = CSVHandler.getDatafromFolder(type.name, myPath) restType = self.__getRestTransTest(type.name) retData = self.restApiHandler.getData(restType) if type.name in testConstant.populator_special_handling: finalOri, finalRet = self.__specialHandling( type.name, indexData, retData) else: finalOri = indexData finalRet = retData return myPath, finalOri, finalRet
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'
def getCommonData(self, param): self.commons = CSVHandler.getDataFromFile( 'logDiscoverData', self.path + '/logDiscoverData.csv', None, None) return self.commons
def getCommonData(self, taskFiles): return CSVHandler.getDataFromFile('incidentData', self.path + '/incidentData.csv', None, None)
def getCommonData(self): indexData = CSVHandler.getDataFromFile( 'DbPopulatorData', self.path + '/DbPopulatorData.csv', None, None) self.commons = indexData return self.commons