def getBacktrace(): return TestermanNodes.getBacktrace()
probe.onTriSAReset() self.response(transactionId, 200, "OK") else: self.response(transactionId, 505, "Not supported") else: # Other scheme self.response(transactionId, 505, "Not supported") except ProbeException, e: self.response(transactionId, 516, "Probe error", str(e) + "\n" + Nodes.getBacktrace()) except Exception, e: self.response(transactionId, 515, "Internal server error", str(e) + "\n" + Nodes.getBacktrace()) def onNotification(self, channel, message): """ Notification: nothing to support in this Agent. """ self.getLogger().warning("Received a notification, discarding:\n" + str(message)) def onResponse(self, channel, transactionId, message): self.getLogger().warning( "Received an asynchronous response, discarding:\n" + str(message)) def initialize(self, controllerAddress, localAddress): Nodes.ConnectingNode.initialize(self, controllerAddress, localAddress)
def onRequest(self, channel, transactionId, request): self.getLogger().debug("Received a request:\n%s" % str(request)) method = request.getMethod() uri = request.getUri() try: if uri.getScheme() == "agent": # Agent-level request if method == "DEPLOY": probeInfo = request.getApplicationBody() self.deployProbe(name=probeInfo['probe-name'], type_=probeInfo['probe-type']) self.response(transactionId, 200, "OK") elif method == "UNDEPLOY": probeInfo = request.getApplicationBody() self.undeployProbe(name=probeInfo['probe-name']) self.response(transactionId, 200, "OK") elif method == "RESTART": self.response(transactionId, 200, "OK") self.getLogger().info("-- Unregistering --") self.unregisterAgent() self.getLogger().info("-- Restarting --") Restarter.restart() elif method == "UPDATE": self.getLogger().info("Updating...") args = request.getApplicationBody() if not args: args = {} # If a preferredVersion is provided, preferred branches, if provided, are ignored preferredVersion = args.get('version', None) preferredBranches = args.get('branches', ['stable']) ret = self.updateAgent(preferredBranches, preferredVersion) self.getLogger().info("Update status: %s" % ret) self.response(transactionId, 200, "OK") elif method == "KILL": self.response(transactionId, 501, "Not implemented") else: self.getLogger().warning( "Received unsupported agent method: %s" % method) self.response(transactionId, 505, "Not supported") elif uri.getScheme() == "probe": # Probe-level request # Check correct 'routing' if uri.getDomain() != self.getNodeName(): self.response(transactionId, 404, "Probe not found (incorrect agent)") # First, look for the probe. name = uri.getUser() probe = self.probes.get(name, None) if not probe: self.response(transactionId, 404, "Probe not found") else: if method == "TRI-SEND": probe.onTriSend(request.getApplicationBody(), request.getHeader('SUT-Address')) self.response(transactionId, 200, "OK") elif method == "TRI-MAP": probe.onTriMap() self.response(transactionId, 200, "OK") elif method == "TRI-UNMAP": probe.onTriUnmap() self.response(transactionId, 200, "OK") elif method == "TRI-EXECUTE-TESTCASE": # Set the probe properties properties = request.getApplicationBody() if properties: for name, value in properties.items(): probe.setProperty(name, value) probe.onTriExecuteTestCase() self.response(transactionId, 200, "OK") elif method == "TRI-SA-RESET": probe.onTriSAReset() self.response(transactionId, 200, "OK") else: self.response(transactionId, 505, "Not supported") else: # Other scheme self.response(transactionId, 505, "Not supported") except ProbeException, e: self.response(transactionId, 516, "Probe error", str(e) + "\n" + Nodes.getBacktrace())
def getBacktrace(): import TestermanNodes return TestermanNodes.getBacktrace()
else: raise XaException("Unsupported method", 505, "Not Supported") except TacsException, e: resp = Messages.Response(e.code, e.reason) resp.setBody(str(e)) self.sendResponse(channel, transactionId, resp) except XaException, e: resp = Messages.Response(e.code, e.reason) resp.setBody(str(e)) self.sendResponse(channel, transactionId, resp) except Exception, e: resp = Messages.Response(501, "Internal server error") resp.setBody(str(e) + "\n" + Nodes.getBacktrace()) self.sendResponse(channel, transactionId, resp) def onNotification(self, channel, notification): self.getLogger().debug("New notification received:\n%s" % str(notification)) method = notification.getMethod() if method == "LOG": self._controller.onLog(channel, notification) elif method == "TRI-ENQUEUE-MSG": self._controller.onTriEnqueueMsg(channel, notification) else: self.getLogger().info("Received unsupported notification method: " + method) def onResponse(self, channel, transactionId, response): self.getLogger().warning("Received an unexpected asynchronous response")
def onRequest(self, channel, transactionId, request): self.getLogger().debug("Received a request:\n%s" % str(request)) method = request.getMethod() uri = request.getUri() try: if uri.getScheme() == "agent": # Agent-level request if method == "DEPLOY": probeInfo = request.getApplicationBody() self.deployProbe(name = probeInfo['probe-name'], type_ = probeInfo['probe-type']) self.response(transactionId, 200, "OK") elif method == "UNDEPLOY": probeInfo = request.getApplicationBody() self.undeployProbe(name = probeInfo['probe-name']) self.response(transactionId, 200, "OK") elif method == "RESTART": self.response(transactionId, 200, "OK") self.getLogger().info("-- Unregistering --") self.unregisterAgent() self.getLogger().info("-- Restarting --") Restarter.restart() elif method == "UPDATE": self.getLogger().info("Updating...") args = request.getApplicationBody() if not args: args = {} # If a preferredVersion is provided, preferred branches, if provided, are ignored preferredVersion = args.get('version', None) preferredBranches = args.get('branches', [ 'stable' ]) ret = self.updateAgent(preferredBranches, preferredVersion) self.getLogger().info("Update status: %s" % ret) self.response(transactionId, 200, "OK") elif method == "KILL": self.response(transactionId, 501, "Not implemented") else: self.getLogger().warning("Received unsupported agent method: %s" % method) self.response(transactionId, 505, "Not supported") elif uri.getScheme() == "probe": # Probe-level request # Check correct 'routing' if uri.getDomain() != self.getNodeName(): self.response(transactionId, 404, "Probe not found (incorrect agent)") # First, look for the probe. name = uri.getUser() probe = self.probes.get(name, None) if not probe: self.response(transactionId, 404, "Probe not found") else: if method == "TRI-SEND": probe.onTriSend(request.getApplicationBody(), request.getHeader('SUT-Address')) self.response(transactionId, 200, "OK") elif method == "TRI-MAP": probe.onTriMap() self.response(transactionId, 200, "OK") elif method == "TRI-UNMAP": probe.onTriUnmap() self.response(transactionId, 200, "OK") elif method == "TRI-EXECUTE-TESTCASE": # Set the probe properties properties = request.getApplicationBody() if properties: for name, value in properties.items(): probe.setProperty(name, value) probe.onTriExecuteTestCase() self.response(transactionId, 200, "OK") elif method == "TRI-SA-RESET": probe.onTriSAReset() self.response(transactionId, 200, "OK") else: self.response(transactionId, 505, "Not supported") else: # Other scheme self.response(transactionId, 505, "Not supported") except ProbeException, e: self.response(transactionId, 516, "Probe error", str(e) + "\n" + Nodes.getBacktrace())
self.response(transactionId, 200, "OK") elif method == "TRI-SA-RESET": probe.onTriSAReset() self.response(transactionId, 200, "OK") else: self.response(transactionId, 505, "Not supported") else: # Other scheme self.response(transactionId, 505, "Not supported") except ProbeException, e: self.response(transactionId, 516, "Probe error", str(e) + "\n" + Nodes.getBacktrace()) except Exception, e: self.response(transactionId, 515, "Internal server error", str(e) + "\n" + Nodes.getBacktrace()) def onNotification(self, channel, message): """ Notification: nothing to support in this Agent. """ self.getLogger().warning("Received a notification, discarding:\n" + str(message)) def onResponse(self, channel, transactionId, message): self.getLogger().warning("Received an asynchronous response, discarding:\n" + str(message)) def initialize(self, controllerAddress, localAddress): Nodes.ConnectingNode.initialize(self, controllerAddress, localAddress) ## # Agent actual services implementation.