def _doSignOn(self): """ Worker for _maybeSignOn that does the actual signing on. """ assert not self._oCommand.isRunning(); # Reset the siged-on state. testboxcommons.log('Signing-on...') self._fSignedOn = False self._idTestBox = None self._cSignOnAttempts += 1; # Assemble SIGN-ON request parameters and send the request. dParams = {}; for sParam in self._ddSignOnParams: dParams[sParam] = self._ddSignOnParams[sParam][self.VALUE]; oResponse = TestBoxConnection.sendSignOn(self._oOptions.sTestManagerUrl, dParams); # Check response. try: sResult = oResponse.getStringChecked(constants.tbresp.ALL_PARAM_RESULT); if sResult != constants.tbresp.STATUS_ACK: raise TestBoxException('Result is %s' % (sResult,)); oResponse.checkParameterCount(3); idTestBox = oResponse.getIntChecked(constants.tbresp.SIGNON_PARAM_ID, 1, 0x7ffffffe); sTestBoxName = oResponse.getStringChecked(constants.tbresp.SIGNON_PARAM_NAME); except TestBoxException, err: testboxcommons.log('Failed to sign-on: %s' % (str(err),)) testboxcommons.log('Server response: %s' % (oResponse.toString(),)); return False;
def openTestManagerConnection(self): """ Opens up a connection to the test manager. Raises exception on failure. """ return TestBoxConnection(self._oOptions.sTestManagerUrl, self._idTestBox, self._sTestBoxUuid);
def _doSignOn(self): """ Worker for _maybeSignOn that does the actual signing on. """ assert not self._oCommand.isRunning(); # Reset the siged-on state. testboxcommons.log('Signing-on...') self._fSignedOn = False self._idTestBox = None self._cSignOnAttempts += 1; # Assemble SIGN-ON request parameters and send the request. dParams = {}; for sParam in self._ddSignOnParams: dParams[sParam] = self._ddSignOnParams[sParam][self.VALUE]; oResponse = TestBoxConnection.sendSignOn(self._oOptions.sTestManagerUrl, dParams); # Check response. try: sResult = oResponse.getStringChecked(constants.tbresp.ALL_PARAM_RESULT); if sResult != constants.tbresp.STATUS_ACK: raise TestBoxException('Result is %s' % (sResult,)); oResponse.checkParameterCount(3); idTestBox = oResponse.getIntChecked(constants.tbresp.SIGNON_PARAM_ID, 1, 0x7ffffffe); sTestBoxName = oResponse.getStringChecked(constants.tbresp.SIGNON_PARAM_NAME); except TestBoxException as err: testboxcommons.log('Failed to sign-on: %s' % (str(err),)) testboxcommons.log('Server response: %s' % (oResponse.toString(),)); return False; # Successfully signed on, update the state. self._fSignedOn = True; self._fNeedReSignOn = False; self._cSignOnAttempts = 0; self._idTestBox = idTestBox; self._sTestBoxName = sTestBoxName; # Update the environment. os.environ['TESTBOX_ID'] = str(self._idTestBox); os.environ['TESTBOX_NAME'] = sTestBoxName; os.environ['TESTBOX_CPU_COUNT'] = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_CPU_COUNT); os.environ['TESTBOX_MEM_SIZE'] = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_MEM_SIZE); os.environ['TESTBOX_SCRATCH_SIZE'] = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_SCRATCH_SIZE); testboxcommons.log('Successfully signed-on with Test Box ID #%s and given the name "%s"' \ % (self._idTestBox, self._sTestBoxName)); # Set up the scratch area. self.reinitScratch(fUseTheForce = self._fFirstSignOn, cRetries = 2); self._fFirstSignOn = False; return True;
def dispatch(self): """ Receive orders from Test Manager and execute them """ (self._idTestBox, self._sTestBoxName, self._fSignedOn) = self._oCommand.resumeIncompleteCommand() self._fNeedReSignOn = self._fSignedOn if self._fSignedOn: os.environ['TESTBOX_ID'] = str(self._idTestBox) os.environ['TESTBOX_NAME'] = self._sTestBoxName while True: # Make sure we're signed on before trying to do anything. self._maybeSignOn() while not self._fSignedOn: iFactor = 1 if self._cSignOnAttempts < 100 else 4 time.sleep( random.randint(self.kcSecMinSignOnDelay * iFactor, self.kcSecMaxSignOnDelay * iFactor)) self._maybeSignOn() # Retrieve and handle command from the TM. (oResponse, oConnection) = TestBoxConnection.requestCommandWithConnection( self._oOptions.sTestManagerUrl, self._idTestBox, self._sTestBoxUuid, self._oCommand.isRunning()) if oResponse is not None: self._oCommand.handleCommand(oResponse, oConnection) if oConnection is not None: if oConnection.isConnected(): self._oCommand.flushLogOnConnection(oConnection) oConnection.close() # Automatically reboot if scratch init fails. if self._cReinitScratchErrors > 8 and self.reinitScratch( cRetries=3) is False: testboxcommons.log( 'Scratch does not initialize cleanly after %d attempts, rebooting...' % (self._cReinitScratchErrors, )) self._oCommand.doReboot() # delay a wee bit before looping. ## @todo We shouldn't bother the server too frequently. We should try combine the test reporting done elsewhere # with the command retrieval done here. I believe tinderclient.pl is capable of doing that. iFactor = 1 if self._cReinitScratchErrors > 0: iFactor = 4 time.sleep( random.randint(self.kcSecMinDelay * iFactor, self.kcSecMaxDelay * iFactor))
def dispatch(self): """ Receive orders from Test Manager and execute them """ (self._idTestBox, self._sTestBoxName, self._fSignedOn) = self._oCommand.resumeIncompleteCommand(); self._fNeedReSignOn = self._fSignedOn; if self._fSignedOn: os.environ['TESTBOX_ID'] = str(self._idTestBox); os.environ['TESTBOX_NAME'] = self._sTestBoxName; while True: # Make sure we're signed on before trying to do anything. self._maybeSignOn(); while not self._fSignedOn: iFactor = 1 if self._cSignOnAttempts < 100 else 4; time.sleep(random.randint(self.kcSecMinSignOnDelay * iFactor, self.kcSecMaxSignOnDelay * iFactor)); self._maybeSignOn(); # Retrieve and handle command from the TM. (oResponse, oConnection) = TestBoxConnection.requestCommandWithConnection(self._oOptions.sTestManagerUrl, self._idTestBox, self._sTestBoxUuid, self._oCommand.isRunning()); if oResponse is not None: self._oCommand.handleCommand(oResponse, oConnection); if oConnection is not None: if oConnection.isConnected(): self._oCommand.flushLogOnConnection(oConnection); oConnection.close(); # Automatically reboot if scratch init fails. if self._cReinitScratchErrors > 8 and self.reinitScratch() is False: testboxcommons.log('Scratch does not initialize cleanly after %d attempts, rebooting...' % ( self._cReinitScratchErrors, )); self._oCommand.doReboot(); # delay a wee bit before looping. ## @todo We shouldn't bother the server too frequently. We should try combine the test reporting done elsewhere # with the command retrieval done here. I believe tinderclient.pl is capable of doing that. iFactor = 1; if self._cReinitScratchErrors > 0: iFactor = 4; time.sleep(random.randint(self.kcSecMinDelay * iFactor, self.kcSecMaxDelay * iFactor));