Ejemplo n.º 1
0
    def logResult(self, test, files):
        """ When a test result has been processed update the database """
        peer = None
        if test.peer:
            peer = Peer.get(macAddress = test.peer.macAddr)

        testDetails = TestDetails.get(testId = test.testId)
        testState = TestStates.filter(sequenceId = test.state.index).get()

        values = {
            'testDetailsRef'         : testDetails,
            'executed'               : test.executed,
            'invalid'                : test.invalid,
            'result'                 : testState,
            'error'                  : test.error,
            'startTime'              : test.startTime,
            'duration'               : math.ceil(test.duration),
            'manualInspection'       : test.manualInspection,
            'peerRef'                : peer,
            'iterationId'            : test.uniqueId }

        testResult = None
        if testDetails.testresults_set.count() == 1:
            testResult = testDetails.testresults_set.get()
            if TestStateValues.NORESLT().index != testResult.result.sequenceId:
                testResult = None

        if testResult: # Update object
            for name, value in values.items():
                setattr(testResult, name, value)
        else: # Create new object
            testResult = TestResults.create(**values)
            testResult.testExecutionDetailsRef = self.executionDetails
        testResult.save()
Ejemplo n.º 2
0
    def __setupStage(self):
        """ Create all objects within the database with defaults """
        self.executionDetails = TestExecutionDetails.create(
            testSuiteName = self.testSuiteName,
            executionName = self.executionName, #TODO: make me!
            scmidentifier = 'N/A',
            shortFilterDesc = self.shortFilterDesc,
            testPackDescriptor = self.packFilterDesc,
            startTime = time.time(),
            endTime = -1,
            duration = -1,
            envservExecutionModeName = 'automated', # FIXME: read from config
            hostNetAddress = Network.getIPAddressByInterface(),
            hostMacAddress = Network.getMacAddress(),
            tasVersion = os.environ['TAS_VERSION'])
        self.executionDetails.save()

        if not hasattr(self, 'source'):
            raise Exception("SQLLiteLogger: Source object has not been set")

        ResultBaseModel.Meta.database.set_autocommit(False)
        for group in self.source.groups:
            for test in group.tests:

                testDetails = TestDetails.get_or_create(
                    testId = str(test.testId),
                    module = str(test.testFile),
                    testName = test.combineClassMethod(),
                    invalid = test.invalid,
                    manualInspection = test.manualInspection,
                    docstrings = "\n".join(test.docstrings),
                    timeout = test.testTimeout)

                testState = TestStates.filter(sequenceId = test.state.index).get()
                testResults = TestResults.create(
                    testDetailsRef = testDetails,
                    executed = False,
                    invalid = test.invalid,
                    result = testState,
                    error = test.error,
                    startTime = -1,
                    duration = -1,
                    manualInspection = test.manualInspection,
                    testExecutionDetailsRef = self.executionDetails,
                    peerRef = None,
                    iterationId = None)

                testResults.save()
                testDetails.save()

        ResultBaseModel.Meta.database.commit()
        ResultBaseModel.Meta.database.set_autocommit(True)