コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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))
コード例 #4
0
                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
コード例 #5
0
                        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))

        if testSuite.clearEvent=="true":
            time.sleep(float(case.clearInterval))
            myHandler.sendEvent(case.clearEvent)

        time.sleep(float(case.clearWait))
        myHandler.getEvent('', inXml, "POST")
        clearParam={}
        clearParam['Clear Event']=parsingQueryResult.XMLParsingQueryResult(myHandler.xml, "nocheck")
        param.append(clearParam)

    myHandler.udpClientClose()

    finalResult=compareTestResult.runCompareResult(config, testSuite, param)

    return finalResult