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()
def __getPeer(self, peer): """ Retrieve peer details from the database by a peer object """ try: return Peer.get(macAddress = peer.macAddr) except Peer.DoesNotExist: peer = Peer.create( macAddress = peer.macAddr, netAddress = "%s:%s" % (peer.ipAddr, '5005')) peer.save() return peer