Ejemplo n.º 1
0
 def checkParserEvents(self, sys_define=False):
     event_map=self.getAllParserEvents(sysdefine=sys_define)
     for key in event_map.keys():
         ao_list=event_map[key]
         self.dbHandler.getEventTypesInModule(key.replace('Parser', ''))
         auto_list=self.dbHandler.module_event_map.keys()
         new_list, extra, exist_list=processList(ao_list, auto_list)
         new_wild_list=[]
         for item in new_list:
             if '$' in item:
                 new_wild_list.append(item)
             else:
                 self.needCoverEvents.append(item)
         if len(new_wild_list) and len(extra):
             for item in new_wild_list:
                 start_pos=item.find('$')
                 end_pos=start_pos+8
                 front=item[:start_pos]
                 end=item[end_pos+1:]
                 for e in extra:
                     if front==e[:start_pos] and end==e[end_pos+1:]:
                         exist_list.append(item)
                         new_list.remove(item)
                         extra.remove(e)
                         break
         print 'module name %s' % key
         self.createModuleHtml(key, exist_list, new_list)
Ejemplo n.º 2
0
    def compareData(self, preData, postData):
        missKey, extraKey, commonKey=testUtility.processList(preData.keys(), postData.keys())
        keyMap={'common':str(len(commonKey)), 'missing':str(len(missKey)), 'extra':str(len(extraKey))}
        myData=[]
        errorMsg=''
        for key in commonKey:
            errorMsg=classUtility.compare(preData[key], postData[key], 'name', errorMsg, IGNORE_LIST)
            myMap={}
            myMap['name']=key
            if errorMsg:
                myMap['status']='Mismatch'
                myMap['reason']=errorMsg
            else:
                myMap['status']='Match'
                myMap['reason']='No Error'
            myData.append(myMap)
        if len(missKey):
            for key in missKey:
                myMap={}
                myMap['name']=key
                myMap['status']='Missing'
                myMap['reason']='Not in compare system'
                myData.append(myMap)
        if len(extraKey):
            for key in extraKey:
                myMap={}
                myMap['name']=key
                myMap['status']='Extra'
                myMap['reason']='Not in base system'
                myData.append(myMap)

        return myData, keyMap
Ejemplo n.º 3
0
def autoTest(file, server=None):
    """starting point to run automation test."""
    testConfig = getTestConfig(file, src=server)
    if testConfig.threadPool is not None:
        thread_pool = testConfig.threadPool
    else:
        thread_pool = default_threads_pool
    thread_wait = 5
    if testConfig.threadWaitTime is not None:
        thread_wait = int(testConfig.threadWaitTime)
    else:
        thread_wait = default_thread_wait
    threads = []
    taskNames = []
    queue = Queue.Queue()
    return_queue = Queue.Queue()
    for task in testConfig.testTask:
        taskNames.append(task.taskName)
        if not task.taskName in supported_tasks:
            print 'test task: %s is not supported at current time.' % task.taskName
            exit()
        testObj = tokenDict[task.taskName](task, testConfig)
        id = 1
        commData = testObj.getCommonData(task.taskFiles)
        if commData:
            setattr(testConfig, 'commonData', commData)
        globalData = testObj.getGlobalData()
        if globalData:
            setattr(testConfig, 'globalData', globalData)
        tests = testObj.getTestList(task.taskFiles)

        if not tests:
            print 'no tests performed.'
            exit()
        miss, extra, common = processList(tests.keys(), commData.keys())
        miss_map = {}
        if miss:
            print 'NOT implemented:\n'
            for item in miss:
                if item not in not_miss:
                    if type(tests[item]).__name__ == 'unicode':
                        type_name = tests[item]
                    else:
                        type_name = tests[item].name
                    print 'Id: %s Name: %s\n' % (item, type_name)
                    miss_map[item] = type_name

        for testKey in common:
            map = {}
            map['name'] = task.taskName
            map['task'] = tests[testKey]
            map['key'] = testKey
            map['obj'] = tokenDict[task.taskName](task, testConfig)
            queue.put(map)

        if len(common) > thread_pool:
            thread_size = thread_pool
        else:
            thread_size = len(common)

        for i in range(thread_size):
            thread = testThread(queue, return_queue)
            thread.setDaemon(True)
            thread.start()
            threads.append(thread)
            if thread_wait:
                time.sleep(thread_wait)

    queue.join()
    fullResult = []
    while not return_queue.empty():
        item = return_queue.get_nowait()
        if item:
            fullResult.append(item)

    print "Main Test Thread Exiting"
    if testConfig.ruleTest and testConfig.ruleTestSupport:
        #check testRule for incident testing
        if testConfig.testTask[0].taskName == 'Incident':
            for item in fullResult:
                if item.caseList[
                        0].status == 'NoReturn' and item.testMethod == 'syslog':
                    myMap = {
                        'ruleId': item.ruleId,
                        'rawMsg': item.rawMsg,
                        'reportIp': item.reptDevIpAddr
                    }
                    status, msg = testRule(testConfig.testServer.appServer,
                                           ruleData=myMap)
                    reason = ''
                    if status == "Pass":
                        item.caseList[0].status = 'Pass'
                    elif status == 'Failure':
                        matched = ''
                        for key in test_rule_exps.keys():
                            match = test_rule_exps[key].search(msg)
                            if match:
                                matched = key
                                break
                        reason = 'testRule triggers failure: %s' % matched
                    elif status == 'Unfinish':
                        rasson = 'testRule triggers unfinished after timeout 10 minutes'
                    item.testRuleResultSummary = reason
                    item.testRuleResultDetail = msg

    autoRet = AutoTestResult()
    autoRet.name = '-'.join(taskNames)
    if hasattr(testConfig, 'batch'):
        autoRet.batch = testConfig.batch
    else:
        autoRet.batch = ''
    autoRet.testType = testConfig.testType
    autoRet.runTime = testConfig.runTime
    autoRet.runVersion = testConfig.buildVersion
    autoRet.localhost = testConfig.localhost
    autoRet.recipient = testConfig.recipient
    autoRet.testFolder = TestConstant.default_result_path + testConfig.name
    if miss_map:
        setattr(autoRet, 'miss', miss_map)
    if classUtility.getType(testConfig.sendEmail) != 'NoneType':
        autoRet.sendEmail = True
    for item in fullResult:
        for count in TestConstant.test_result_counters:
            value = getattr(autoRet, count)
            value += getattr(item, count)
            setattr(autoRet, count, value)
        autoRet.suiteList.append(item)

    msg = testReport().generateReport(autoRet)

    return msg
Ejemplo n.º 4
0
    def verifyData(self, type, params, retData, debugInfo, module, sendTime):
        resObjList = []
        for key in type.keys():
            if type[key].key:
                keyVal = type[key].eventType + '@' + type[
                    key].reptDevIpAddr + ' (' + type[key].key + ')'
            else:
                keyVal = type[key].eventType + '@' + type[key].reptDevIpAddr
            expData = params[keyVal]
            resObj = getClassObj('TestCaseResult', module='autoTest')
            actData = ''
            if keyVal in retData.keys():
                if keyVal:
                    actData = retData[keyVal][0]
            elif ' (' in keyVal:
                oriKey, map = keyVal.split(' (')
                mapKey, mapVal = map[:-1].split(':')
                if oriKey in retData.keys():
                    for item in retData[oriKey]:
                        if mapKey in item.attributes.keys():
                            if mapVal == item.attributes[mapKey]:
                                actData = item
                        elif not mapVal:
                            actData = item

            if actData:
                miss, extra, common = processList(expData['params'].keys(),
                                                  actData.attributes.keys())
                for comkey in common:
                    map = {}
                    map['param'] = comkey
                    if actData.attributes[comkey] != None:
                        map['actValue'] = actData.attributes[comkey]
                        if 'Name' in comkey and 'HOST-' in actData.attributes[
                                comkey]:
                            ignore_param.update([comkey])
                    else:
                        map['actValue'] = 'None'
                    map['expectValue'] = expData['params'][comkey]
                    if '\n' in map['actValue']:
                        map['actValue'] = map['actValue'].replace('\n', '')
                    if self.testType != 'Official' and map[
                            'param'] in ignore_param:
                        resObj.Pass.append(map)
                        continue
                    if map['expectValue'] == 'any' or map['expectValue'].strip(
                    ) == map['actValue'].strip():
                        resObj.Pass.append(map)
                    else:
                        if map['param'] in ignore_space_params:
                            if map['expectValue'].replace(
                                    ' ',
                                    '') == map['actValue'].replace(' ', ''):
                                resObj.Pass.append(map)
                            else:
                                resObj.Fail.append(map)
                        else:
                            resObj.Fail.append(map)
                if miss:
                    for misskey in miss:
                        map = {}
                        map['param'] = misskey
                        map['expectValue'] = expData['params'][misskey]
                        map['actValue'] = 'None'
                        resObj.Missing.append(map)
                if extra:
                    for exkey in extra:
                        if exkey not in event_ignore_params and actData.attributes[
                                exkey]:
                            map = {}
                            map['param'] = exkey
                            map['expectValue'] = 'None'
                            map['actValue'] = actData.attributes[exkey]
                            resObj.Extra.append(map)
                if resObj.Fail:
                    resObj.status = 'Fail'
                else:
                    resObj.status = 'Pass'
            else:
                resObj.status = 'NoReturn'
                failDetail = self.eventDebug(keyVal, expData['msg'], sendTime)
                setattr(resObj, 'reasons', failDetail)
            if self.testConfig.localhost in keyVal:
                keyVal = keyVal.replace(self.testConfig.localhost,
                                        '$localhost')
            resObj.name = key + '(' + keyVal + ')'
            resObjList.append(resObj)
        suiteObj = getClassObj('TestSuiteResult', module='autoTest')
        suiteObj.name = module
        suiteObj.taskName = 'EventParsing'
        suiteObj.debugInfo = debugInfo
        for item in resObjList:
            suiteObj.totalRun += 1
            oldVal = getattr(suiteObj, 'total' + item.status)
            oldVal += 1
            setattr(suiteObj, 'total' + item.status, oldVal)
            suiteObj.caseList.append(item)

        return suiteObj
Ejemplo n.º 5
0
    def verifyData(self, name, ori, ret):
        resObjList = []
        if ret:
            miss, extraRaw, common = testUtility.processList(
                ori.keys(), ret.keys())
            extra = []
            if name in testConstant.populator_comp_ignore.keys():
                for subKey in extraRaw:
                    if testConstant.populator_comp_ignore[name] not in subKey:
                        extra.append(subKey)
            else:
                extra = extraRaw
            for ikey in common:
                oriData = ori[ikey]
                retData = ret[ikey]
                attrList = classUtility.getAttrList(oriData)
                resObj = getClassObj('TestCaseResult', module='autoTest')
                resObj.name = ikey
                for item in attrList:
                    map = {}
                    map['param'] = item
                    map['expectValue'] = getattr(oriData, item)
                    if hasattr(retData, item):
                        map['actValue'] = getattr(retData, item)
                    else:
                        map['actValue'] = 'Missing'
                    if '\n' in map['actValue']:
                        map['actValue'] = map['actValue'].replace('\n', '')
                    if map['expectValue'].strip().lower(
                    ) == map['actValue'].strip().lower():
                        resObj.Pass.append(map)
                    else:
                        resObj.Fail.append(map)
                if resObj.Fail:
                    resObj.status = 'Fail'
                elif resObj.Missing:
                    resObj.status = 'Missing'
                elif resObj.Extra:
                    resObj.status = 'Extra'
                else:
                    resObj.status = 'Pass'
                resObjList.append(resObj)
            if miss:
                for misskey in miss:
                    resObj = getClassObj('TestCaseResult', module='autoTest')
                    resObj.name = misskey
                    resObj.status = 'NoReturn'
                    setattr(resObj, 'reasons', 'Fail to import')
                    resObjList.append(resObj)
            if extra:
                for extrakey in extra:
                    resObj = getClassObj('TestCaseResult', module='autoTest')
                    resObj.name = extrakey
                    resObj.status = 'Extra'
                    map = {}
                    map['param'] = extrakey
                    map['expectValue'] = 'None'
                    map['actValue'] = extrakey
                    resObj.Extra.append(map)
                    resObjList.append(resObj)
        suiteObj = getClassObj('TestSuiteResult', module='autoTest')
        suiteObj.name = name
        for item in resObjList:
            suiteObj.totalRun += 1
            oldVal = getattr(suiteObj, 'total' + item.status)
            oldVal += 1
            setattr(suiteObj, 'total' + item.status, oldVal)
            suiteObj.caseList.append(item)

        return suiteObj