def runEventExport(config, testSuite): option=config['option'] myHandler=ComHandler.comHandler(config['dataCollector'], config['appServer'], config['user'], config['password']) totalParam=[] accessIps=[] finalResult=None caseList=[] for case in testSuite.testcases: timeParam=makeTime.MakeTime(case.startTime, case.endTime) myPrompt='' if config['SshAdmin']=='root': myPrompt='#' else: myPrompt='$' mySSH=SshHandler.SshHandler(config['dataCollector'], config['SshAdmin'], config['SshPass'], prompt=myPrompt) cmdList=[] cmdList.append(makeCmd(case.option, config['destFolder'], timeParam, case.reporter, case.custName)) value=mySSH.runCmd(cmdList) time.sleep(120) mySCP=ScpHandler.ScpHandler(config['dataCollector'], config['SshAdmin'], config['SshPass']) fileName=config['destFolder']+'/'+FILENAME mySCP.getFile(fileName) testParam=getFile(FILENAME) logging.debug("Script return %s", testParam) queryString='reptDevIpAddr='+case.reporter inXml=createQuery.CreateQueryXML(queryString, startTime=timeParam['startTime']['uTime'], endTime=timeParam['endTime']['uTime']) myHandler.getEvent("POST", xml=inXml) param=parsingQueryResult.XMLParsingQueryResult(myHandler.xml, filter=FILTER) logging.debug("REST API return %s", param) if len(param)!=testParam: print "phExportEvent script generates %d records." % len(testParam) print "REST API query returns %d records." % len(param) resultCase=eventExportCompare.verifyResult(config, case.name, "N/A", case.reporter, testParam, param) caseList.append(resultCase) totalPass=0 totalFail=0 totalMissing=0 for item in caseList: if item.status=='Pass': logging.debug("Total Pass: %s",totalPass) totalPass+=1 elif item.status=='Fail': totalFail+=1 logging.debug("Total Fail: %s",totalFail) elif item.status=='NoReturn': totalMissing+=1 logging.debug("Total No Return: %s",totalMissing) resultTestSuite=autoTestResultClass.TestSuiteResult(testSuite.name, testSuite.fileName, len(testSuite.testcases), totalPass, totalFail, totalMissing, caseList) logging.debug('TestSuite Result:\n') logging.debug('TestSuiteResult name: %s total Run: %s pass: %s fail: %s', resultTestSuite.name, resultTestSuite.totalRun, resultTestSuite.totalPass, resultTestSuite.totalFail) return resultTestSuite
def sentEventTask(config, testSuite): option = config['option'] myHandler = ComHandler.comHandler(config['dataCollector'], config['appServer'], config['user'], config['password']) if option != "CheckOnly": if testSuite.method == 'snmptrap': for case in testSuite.testcases: logging.debug(case.parseEvent) returnC = os.system(case.parseEvent) else: if testSuite.method == 'netflow': myHandler.udpClient(port=2055) else: myHandler.udpClient() for case in testSuite.testcases: if testSuite.method == 'netflow': realMsg = GenerateNetFlowData.getNetFlowPacket( case.parseEvent) else: realMsg = case.parseEvent.decode() myHandler.sendEvent(realMsg) logging.debug(realMsg) myHandler.udpClientClose() finalResult = None if option != "SendOnly": if 'sleep' in config: sleepTime = float(config['sleep']) * 60 else: sleepTime = 120.0 time.sleep(sleepTime) keyMap = testSuite.getKeyMap() queryString = 'eventType IN (' + keyMap[ 'eventType'] + ') AND reptDevIpAddr IN (' + keyMap['reporter'] + ')' inXml = createQuery.CreateQueryXML(queryString) myHandler.getEvent("POST", xml=inXml) param = parsingQueryResult.XMLParsingQueryResult(myHandler.xml, check=True) finalResult = compareTestResult.runCompareResult( config, testSuite, param) return finalResult
def runIncident(config, testSuite): option=config['option'] param=[] myHandler=ComHandler.comHandler(config['dataCollector'], config['appServer'], config['user'], config['password']) myHandler.udpClient() for case in testSuite.testcases: inXml='' if case.createDevice.lower()=="true": inXml=createDevice.createDeviceList(case.deviceType, case.deviceName, case.reporter, 1, "1") queryString="discovered/discover?sync=true" myHandler.setSecure() myHandler.getEvent(queryString, inXml, "PUT") time.sleep(120) if option!="SendOnly": keyMap=testSuite.getKeyMap() queryString='phEventCategory=1 AND (eventType IN ('+keyMap['eventType']+') AND incidentRptIp IN ('+keyMap['reporter']+'))' inXml=createQuery.CreateQueryXML(queryString) logging.debug(inXml) if testSuite.sendEvent=="true": for i in range(0, int(case.sentCount)): for j in range(0, int(case.repeatCount)): for k in range(0, len(case.events)): myHandler.sendEvent(case.events[k].incidentMsg) logging.debug(case.events[k].incidentMsg.decode()) time.sleep(float(case.repeatInterval)) if option!="SendOnly": if inXml!='': myHandler.getEvent('', inXml, "POST") myParam={} myParam["Event "+str(i+1)]=parsingQueryResult.XMLParsingQueryResult(myHandler.xml, "nocheck") param.append(myParam) else: print "No Query XML. Exit." exit() time.sleep(float(case.sentInterval))
def runIncident(config, testSuite, type): option = config['option'] myHandler = ComHandler.comHandler(config['dataCollector'], config['appServer'], config['user'], config['password']) myHandler.udpClient() finalResult = [] caseList = [] for case in testSuite.testcases: inXml = '' if case.createDevice.lower() == "true": inXml = createDevice.createDeviceList(case.deviceType, case.deviceName, case.reporter, 1, case.custId) queryString = "discovered/discover?sync=true" myHandler.setSecure() myHandler.getEvent("PUT", urlString=queryString, xml=inXml) time.sleep(120) if option != "SendOnly": keyMap = testSuite.getKeyMap() queryString = 'phEventCategory=1 AND (eventType IN (' + keyMap[ 'eventType'] + ') AND incidentRptIp IN (' + keyMap[ 'reporter'] + '))' inXml = createQuery.CreateQueryXML(queryString) logging.debug(inXml) mapping = {} if testSuite.sendEvent == "true": for i in range(0, int(case.sendCount)): for j in range(0, int(case.repeatCount)): for k in range(0, len(case.events)): myHandler.sendEvent(case.events[k].incidentMsg) logging.debug(case.events[k].incidentMsg.decode()) if case.repeatInterval != '': time.sleep(float(case.repeatInterval))
def RunTask(config, testSuite): option = config['option'] myIncident = incidentHandler.incidentHandler(config['dataCollector'], config['appServer'], config['user'], config['password']) myIncident.udpClient() totalParam = [] type = testSuite.type reason = '' if type == 'pattern': reason = PATTERN_BASE if type == 'time': reason = TIME_BASE for testcase in testSuite.testcaseList: #create device in CMDB for testing then wait 2 minutes for it to work if testcase.createDevice == "yes": createDevice.createDeviceList(config['appServer'], testcase.deviceType, testcase.deviceName, testcase.reporter, 1, "1") time.sleep(120) if option == "check": myParam = {} myParam['firstCount'] = '1' myParam['secondCount'] = testcase['repeatCount'] if type == 'time': myTime = (int(testcase.clearInterval) - 300) / 60 num = str(myTime) reason.replace("$n", num) myParam['reason'] = reason queryString = 'eventType IN ("' + testcase.eventType + '") AND hostIpAddr IN (' + testcase.reporter + ')' queryXML = createQuery.CreateQueryXML(queryString, 'Incidents', '1') logging.debug(queryXML) if testSuite.sendEvent == "true": incidentEvent = testcase.incidentEvent for i in range(int(incidentEvent.repeatCount)): for j in range(int(incidentEvent.sendCount)): for msg in incidentEvent.incidentList: myIncident.sendEvent(msg) time.sleep(int(incidentEvent.sendInterval)) time.sleep(int(incidentEvent.repeatInterval)) if option == "check": myIncident.getEvent(queryXML) myParam["Event " + str(i + 1)] = parseReturn.XMLParsingQueryResult( myIncident.xml) #clear event if testSuite.clearEvent == "true": time.sleep(int(testcase.clearInterval)) myIncident.sendEvent(testcase.clearEvent) if testSuite.type != "general" and option == "check": time.sleep(int(testcase.clearWait)) myIncident.getEvent(queryXML) myParam["Clear Event"] = parseReturn.XMLParsingQueryResult( myIncident.xml) if option == "check": logging.debug(myParam) totalParam.append(myParam) for param in totalParam: verifyResult.verifyResult(param) finalResult = "good" else: finalResult = "test done" myIncident.udpClientClose() return finalResult
time.sleep(120) for i in range(0, int(case.repeatCount)): for j in range(0, len(case.events)): myHandler.sendEvent(case.events[j].incidentMsg) logging.debug(case.events[j].incidentMsg.decode()) time.sleep(float(case.repeatInterval)) myHandler.udpClientClose() finalResult = None if option != "SendOnly": if 'sleep' in config: sleepTime = float(config['sleep']) * 60 else: sleepTime = 120.0 time.sleep(sleepTime) keyMap = testSuite.getKeyMap() queryString = 'phEventCategory=1 AND (eventType IN (' + keyMap[ 'eventType'] + ') AND incidentRptIp IN (' + keyMap[ 'reporter'] + '))' inXml = createQuery.CreateQueryXML(queryString) myHandler.getEvent("POST", xml=inXml) param = parsingQueryResult.XMLParsingQueryResult(myHandler.xml) finalResult = compareTestResult.runCompareResult( config, testSuite, param) return finalResult