def requestCommandWithConnection(sTestManagerUrl, sTestBoxId, sTestBoxUuid, fBusy): """ Queries the test manager for a command and returns its respons + an open connection for acking/nack the command (and maybe more). No exceptions will be raised. On failure (None, None) will be returned. """ oConnection = None try: oConnection = TestBoxConnection(sTestManagerUrl, sTestBoxId, sTestBoxUuid, fLongTimeout=not fBusy) if fBusy: oResponse = oConnection.postRequest( constants.tbreq.REQUEST_COMMAND_BUSY) else: oResponse = oConnection.postRequest( constants.tbreq.REQUEST_COMMAND_IDLE) return (oResponse, oConnection) except: testboxcommons.log2Xcpt() if oConnection is not None: # Be kind to apache. try: oConnection.close() except: pass return (None, None)
def postRequestRaw(self, sAction, dParams): """ Posts a request to the test manager and gets the response. The dParams argument is a dictionary of unencoded key-value pairs (will be modified). Raises exception on failure. """ dHeader = \ { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'User-Agent': 'TestBoxScript/%s.0 (%s, %s)' % (__version__, utils.getHostOs(), utils.getHostArch()), 'Accept': 'text/plain,application/x-www-form-urlencoded', 'Accept-Encoding': 'identity', 'Cache-Control': 'max-age=0', 'Connection': 'keep-alive', } sServerPath = '/%s/testboxdisp.py' % ( self._oParsedUrl.path.strip('/'), ) # pylint: disable=no-member dParams[constants.tbreq.ALL_PARAM_ACTION] = sAction sBody = urllib_urlencode(dParams) ##testboxcommons.log2('sServerPath=%s' % (sServerPath,)); try: self._oConn.request('POST', sServerPath, sBody, dHeader) oResponse = self._oConn.getresponse() oResponse2 = TestBoxResponse(oResponse) except: testboxcommons.log2Xcpt() raise return oResponse2
def postRequestRaw(self, sAction, dParams): """ Posts a request to the test manager and gets the response. The dParams argument is a dictionary of unencoded key-value pairs (will be modified). Raises exception on failure. """ dHeader = \ { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'User-Agent': 'TestBoxScript/%s.0 (%s, %s)' % (__version__, utils.getHostOs(), utils.getHostArch()), 'Accept': 'text/plain,application/x-www-form-urlencoded', 'Accept-Encoding': 'identity', 'Cache-Control': 'max-age=0', 'Connection': 'keep-alive', }; sServerPath = '/%s/testboxdisp.py' % (self._oParsedUrl.path.strip('/'),); # pylint: disable=E1101 dParams[constants.tbreq.ALL_PARAM_ACTION] = sAction; sBody = urllib.urlencode(dParams); ##testboxcommons.log2('sServerPath=%s' % (sServerPath,)); try: self._oConn.request('POST', sServerPath, sBody, dHeader); oResponse = self._oConn.getresponse(); oResponse2 = TestBoxResponse(oResponse); except: testboxcommons.log2Xcpt(); raise return oResponse2;
def sendSignOn(sTestManagerUrl, dParams): """ Sends a sign-on request to the server, returns the response (TestBoxResponse). No exceptions will be raised. """ oConnection = None; try: oConnection = TestBoxConnection(sTestManagerUrl, None, None); return oConnection.postRequestRaw(constants.tbreq.SIGNON, dParams); except: testboxcommons.log2Xcpt(); if oConnection is not None: # Be kind to apache. try: oConnection.close(); except: pass; return TestBoxResponse(None);
def requestCommandWithConnection(sTestManagerUrl, sTestBoxId, sTestBoxUuid, fBusy): """ Queries the test manager for a command and returns its respons + an open connection for acking/nack the command (and maybe more). No exceptions will be raised. On failure (None, None) will be returned. """ oConnection = None; try: oConnection = TestBoxConnection(sTestManagerUrl, sTestBoxId, sTestBoxUuid, fLongTimeout = not fBusy); if fBusy: oResponse = oConnection.postRequest(constants.tbreq.REQUEST_COMMAND_BUSY); else: oResponse = oConnection.postRequest(constants.tbreq.REQUEST_COMMAND_IDLE); return (oResponse, oConnection); except: testboxcommons.log2Xcpt(); if oConnection is not None: # Be kind to apache. try: oConnection.close(); except: pass; return (None, None);