コード例 #1
0
def genBaseBatchResult(task):
    xml = ElementTree.Element("batchResult", \
                              filename=task, \
                              md5sum=libapitest.hexdigest(task))
    return xml
コード例 #2
0
    def loadBatchFile(self, fileName):
        """ load the batchFile """
        self.printDebug("[->]\tbatchHandler.loadBatchFile(%s)"%(fileName))
        self.hasRun        = False
        self.batchFileName = fileName
        self.batchFilePath = os.path.split(fileName)[0]
        self.testGraph.clear()
        self.testGraph.set_name(self.batchFileName)
        if not os.path.exists(self.batchFileName):
            print "Error encountered in '%s'"%(self.parentTask)
            print "\tCould not locate file '%s'\n"%(self.batchFileName)
        try:
            self.batchFileTree = ElementTree.parse(self.batchFileName)
        except:
            print "Could not parse '%s'.\n"%(self.batchFileName)


        ##########
        #
        # MySQL Test Code :: loadBatchFile
        #
        if self.options and self.options["sqldb"] and self.db.connected:
            from db_mysql import apitestdb
            fname = os.path.abspath(self.batchFileName)
            if self.db_parent_batchid == None:
                query="""
                      INSERT INTO `results` (`RUNID`,`FNAME`,`STATUS`,`TYPE`,`TIMEOUT`)
                      VALUES (%d,'%s','%s','BATCH',0.0)
                      """ % (self.db_runid,fname,'RUNNING')
            else:
                query="""
                      INSERT INTO `results` (`RUNID`,`PID`,`FNAME`,`STATUS`,
                                             `TYPE`,`TIMEOUT`)
                      VALUES (%d,%d,'%s','RUNNING','BATCH',0.0)
                      """ % (self.db_runid,self.db_parent_batchid,fname)
            self.db.execute(query)
            self.db_batchid = self.db.getMaxID("results")
        #
        # MySQL Test Code END
        #
        ##########

            
        batchFileTreeRoot = self.batchFileTree.getroot()

        self.xmlroot = ElementTree.Element("batchResult", \
                              filename=self.batchFileName, \
                              status="", \
                              md5sum=libapitest.hexdigest(self.batchFileName),
                              timeStart=libapitest.genTimeStamp() )

        xmlOutputSummary = ElementTree.SubElement(self.xmlroot,'summary', \
                              nPass='******',nFail='0',nTotal='0')

        self.batchID = self.WB.TD.addBatch(self.xmlroot)
        #self.xmlroot.attrib['batchID']=str(self.batchID)

        parentBatchID = self.WB.TD.B.data[ self.batchID ][4]
        if parentBatchID != None:
            self.xmlroot.attrib['pBatchID'] = str(parentBatchID)

        self.runID = self.WB.TD.R.currentID
        self.xmlroot.attrib['runID']=str(self.runID)
       
        # Insert shortDescription from batch file into result text.
        SD = batchFileTreeRoot.find("shortDescription")
        if SD != None:
            if SD.text != None:
                desc = SD.text
                if desc != None:
                    desc = string.lstrip(desc)
                    if desc != "":
                        bSD = ElementTree.SubElement(self.xmlroot,'shortDescription')
                        bSD.text = desc
    
        
        ## Load <test> Elements from Batch File. 
        #
        #  mustPass : determines if this test must pass for the batch file
        #             to PASS.
        #  mustPass = TRUE : (DEFAULT) Test must pass for the batch file to pass.
        #  mustPass = FALSE: Test is not considered in passing/failing a batch file.
        #
        mustPassDefault = "TRUE"
        statusDefault   = "PASS"

        # User can change default behaviour of mustPass by using
        # <parameter key="mustPass" value={true|false} /> 
        # anywhere in the batch file.
        for iParam in batchFileTreeRoot.findall('parameter'):
            key   = iParam.attrib.get('key',None)
            value = iParam.attrib.get('value',mustPassDefault)
            value = string.upper(value)
            if key=='mustPass' and value in ("TRUE","FALSE"):
                mustPassDefault = value

        for iTest in batchFileTreeRoot.findall('test'):
            tname= iTest.attrib.get('name','__noname__')
            if not self.batchFilePath == '':
                tname = self.batchFilePath+"/"+tname
            mustPass = iTest.attrib.get('mustPass',mustPassDefault)
            
            self.printDebug("\ttname    = %s"%tname)
            self.printDebug("\tmustPass = %s"%mustPass)

            self.testGraph.add_vertex(tname,["DNE",mustPass])
            
        ## Iterate over dependencies, parent name and child name
        ## (pname,cname) get __noname__ if left out.
        ## status defaults to PASS.
        ## Load <dep> Elements from Batch file.
        for iDep in batchFileTreeRoot.findall('dep'):
            pname = iDep.attrib.get('parent','__noname__')
            cname = iDep.attrib.get('child','__noname__')
            status= iDep.attrib.get('status',statusDefault) 
            
            if self.batchFilePath != "":
                pname = self.batchFilePath+"/"+pname
                cname = self.batchFilePath+"/"+cname

            if not self.testGraph.has_vertex(pname):
                self.testGraph.add_vertex(pname,["DNE",mustPassDefault])
            if not self.testGraph.has_vertex(cname):
                self.testGraph.add_vertex(cname,["DNE",mustPassDefault])
                
            self.testGraph.add_edge(pname,cname,[status])

        testOrder = self.testGraph.topological_sort()

        self.clearQueue()
        for iTest in testOrder:
            self.testQueue.put(iTest)
        self.printDebug("\ttestQueue.queue = %s"%(`self.testQueue.queue`))
        self.printDebug("\ttestGraph.vertex_list = %s"%self.testGraph.vertex_list())
        return 0