Exemple #1
0
	def _getClient(self):
		if not self._client:
			serverUrl = os.environ.get('TESTERMAN_SERVER')
			if not serverUrl:
				raise Exception("Sorry, no testerman server set (TESTERMAN_SERVER).")
			self._client = TestermanClient.Client(name = "Testerman Admin", userAgent = "testerman-admin", serverUrl = serverUrl)

		return self._client
Exemple #2
0
	def __init__(self):
		threading.Thread.__init__(self)
		self._stopEvent = threading.Event()
		address = (cm.get("interface.wc.ip"), cm.get("interface.wc.port"))
		serverUrl = "http://%s:%s" % (cm.get("ts.ip"), cm.get("ts.port"))
		client = TestermanClient.Client(name = "Testerman WebClient", userAgent = "WebClient/%s" % VERSION, serverUrl = serverUrl)
		self._client = client
		RequestHandler.registerApplication('/', WebClientApplication, 
			documentRoot = cm.get("testerman.webclient.document_root"), 
			testermanClient = client,
			debug = cm.get("wcs.debug"),
			authenticationRealm = 'Testerman WebClient',
			theme = cm.get("wcs.webui.theme"))
		RequestHandler.registerApplication('/websocket', XcApplication, 
			testermanServerUrl = serverUrl,
			debug = cm.get("wcs.debug"))

		self._server = HttpServer(address, RequestHandler)
Exemple #3
0
    def __init__(self):
        threading.Thread.__init__(self)
        self._stopEvent = threading.Event()
        address = (cm.get("interface.ws.ip"), cm.get("interface.ws.port"))
        self._server = XmlRpcServer(address, RequestHandler, allow_none=True)
        serverUrl = "http://%s:%s" % (
            (cm.get("interface.ws.ip") in ['', "0.0.0.0"] and "localhost")
            or cm.get("interface.ws.ip"), cm.get("interface.ws.port"))
        client = TestermanClient.Client(name="Embedded Testerman WebClient",
                                        userAgent="WebClient/%s" %
                                        WebClientServer.VERSION,
                                        serverUrl=serverUrl)
        getLogger().info("Embedded WCS using serverUrl: %s" % serverUrl)
        # Register applications in this server
        WebServer.WebApplicationDispatcherMixIn.registerApplication(
            "/",
            TestermanWebApplication,
            documentRoot=cm.get("testerman.web.document_root"),
            debug=cm.get("ts.debug"),
            theme=cm.get("ts.webui.theme"))
        WebServer.WebApplicationDispatcherMixIn.registerApplication(
            "/webclient",
            WebClientServer.WebClientApplication,
            documentRoot=cm.get("testerman.webclient.document_root"),
            testermanClient=client,
            debug=cm.get("ts.debug"),
            authenticationRealm='Testerman WebClient',
            theme=cm.get("wcs.webui.theme"))
        WebServer.WebApplicationDispatcherMixIn.registerApplication(
            '/websocket',
            WebClientServer.XcApplication,
            testermanServerUrl=serverUrl,
            debug=cm.get("ts.debug"))

        # We should be more selective...
        self._server.register_instance(WebServices)
        self._server.logRequests = False
Exemple #4
0
def main():
	defaultTarget = os.path.abspath(os.path.dirname(sys.modules[globals()['__name__']].__file__) + "/..")

	expandPath = lambda x: x and os.path.abspath(os.path.expandvars(os.path.expanduser(x)))
	
	usage = "usage: %prog [options] [command]"

	# Command Line Options parsing
	parser = optparse.OptionParser(version = getVersion(), usage = usage)
		
	group = optparse.OptionGroup(parser, "Basic Options")
	group.add_option("-t", "--target", dest = "target", metavar = "TARGET", help = "target to administrate. Either a path to a Testerman runtime directory (\"Testerman home\") or the URL of a Testerman server. When administrating a specific Testerman server by URL, some control functions (such as start/stop and configuration) may be disabled. You may also set TESTERMAN_ADMIN_TARGET environment variable.", default = os.environ.get("TESTERMAN_ADMIN_TARGET", defaultTarget))
	group.add_option("-c", "--context", dest = "context", metavar = "CONTEXT", help = "set the initial working context to CONTEXT (for instance, testerman/component). Useful when executing a command directly.", default = None)
	parser.add_option_group(group)

	group = optparse.OptionGroup(parser, "Advanced Options")
	group.add_option("-r", dest = "docroot", metavar = "DOCUMENT_ROOT", help = "force to use DOCUMENT_ROOT as the document root. This overrides the document root auto-detection from the target.", default = None)
	parser.add_option_group(group)

	group = optparse.OptionGroup(parser, "Advanced Options")
	group.add_option("--debug", dest = "debug", action = "store_true", help = "turn debug traces on (default: %default)", default = False)
	parser.add_option_group(group)

	(options, args) = parser.parse_args()


	if not options.target:
		print """
Missing mandatory target. Please use -t <testerman_home> or -t <server_url>,
for instance:
  testerman-admin -t http://server:8080
  testerman-admin -t /path/to/testerman/installation

or set the TESTERMAN_ADMIN_TARGET environment variable."""
		sys.exit(1)


	if options.docroot:
		options.docroot = expandPath(options.docroot)

	# According to the target, autodetect docroot/servers info

	# Managed target: a running server
	if options.target.startswith("http://"):
		serverUrl = options.target
		os.environ["TESTERMAN_SERVER"] = serverUrl
		# Now retrieve the docroot from the running server
		client = TestermanClient.Client(name = "Testerman Admin", userAgent = "testerman-admin", serverUrl = serverUrl)
		
		# Detect settings from the running Testerman server
		try:
			docroot, tacs_ip, tacs_port = None, None, None
			for variable in client.getVariables("ts")['persistent']:
				if variable['key'] == 'testerman.document_root':
					docroot = variable['actual']
				elif variable['key'] == 'tacs.ip':
					tacs_ip = variable['actual']
				elif variable['key'] == 'tacs.port':
					tacs_port = variable['actual']
		except:
			print "Sorry, cannot find a running Testerman server at %s." % serverUrl
			sys.exit(2)

		if not docroot or not tacs_ip or not tacs_port:
			print "Sorry, the Testerman server running at %s cannot be managed (missing a mandatory configuration variable)."
			sys.exit(2)
		
		os.environ["TESTERMAN_DOCROOT"] = docroot
		os.environ["TESTERMAN_TACS"] = "%s:%s" % (tacs_ip, tacs_port)

		print "Found running Testerman server, using document root: %s" % docroot

		# Forced docroot overrides the autodetection
		if options.docroot:
			os.environ["TESTERMAN_DOCROOT"] = docroot
	

	# Managed target: a complete runtime environment.
	else:
		# a Testerman home dir was provided.
		# Get all other values from the configuration file.
		home = expandPath(options.target)
		os.environ["TESTERMAN_HOME"] = home
		cm = ConfigManager.ConfigManager()
		try:
			cm.read("%s/conf/testerman.conf" % home)
		except Exception, e:
			print "Invalid Testerman target - cannot find or read %s/conf/testerman.conf file." % home
			sys.exit(2)

		# Detect settings from the configuration file
		os.environ["TESTERMAN_DOCROOT"] = expandPath(cm.get("testerman.document_root"))
		ip = cm.get("interface.ws.ip", "")
		if not ip or ip == "0.0.0.0":
			ip = "localhost"
		os.environ["TESTERMAN_SERVER"] = "http://%s:%s" % (ip, cm.get("interface.ws.port", 8080))
		os.environ["TESTERMAN_TACS"] = "%s:%s" % (cm.get("tacs.ip", "127.0.0.1"), cm.get("tacs.port", 8087))

		# Forced docroot overrides the autodetection
		if options.docroot:
			os.environ["TESTERMAN_DOCROOT"] = options.docroot
		
		# Also check if we have a running server
		serverUrl = os.environ["TESTERMAN_SERVER"]
		docroot = os.environ["TESTERMAN_DOCROOT"]
		client = TestermanClient.Client(name = "Testerman Admin", userAgent = "testerman-admin", serverUrl = serverUrl)
		try:
			for variable in client.getVariables("ts")['transient']:
				if variable['key'] == 'testerman.testerman_home':
					runningHome = expandPath(variable['value'])
					if home != runningHome:
						print "WARNING: another Testerman server is already running using the configured URL (%s), located in %s" % (serverUrl, runningHome)
					break
			for variable in client.getVariables("ts")['persistent']:
				if variable['key'] == 'testerman.document_root':
					runningDocroot = expandPath(variable['actual'])
					if docroot != runningDocroot:
						print "WARNING: a Testerman server is already running using the configured URL (%s), but using a different document root (%s) as the one that will be managed by this session (%s)" % (serverUrl, runningDocroot, docroot)
					break
		except:
			pass
Exemple #5
0
 def __init__(self, serverUrl):
     self.__client = TestermanClient.Client(name="Testerman CLI Client",
                                            userAgent=getVersion(),
                                            serverUrl=serverUrl)
     self.__jobCompleteEvent = threading.Event()
     self.__client.setLogger(logging.getLogger('cli'))
Exemple #6
0
	def __init__(self, testermanServerUrl, **kwargs):
		WebServer.WebSocketApplication.__init__(self, **kwargs)
		self._client = TestermanClient.Client(name = "Testerman WebClient/WebSocket", userAgent = "WebClient/%s" % VERSION, serverUrl = testermanServerUrl)
Exemple #7
0
				
	##
	# ViewContext
	##
	def getClient(self):
		return self._client	

	def icon(self, resource):
		return self._iconCache.icon(resource)


# Basic test
if __name__ == "__main__":
	import sys
	import TestermanClient

	app = QApplication([])

	client = TestermanClient.Client("test", "AgentView/1.0.0", serverUrl = "http://localhost:8080")
	client.startXc()
	
	w = WAgentView()
	w.show()
	w.setClient(client)
	
	app.exec_()
	client.stopXc()


	
Exemple #8
0
        if item:
            self._viewLog(item.getId())


################################################################################
# Standalone viewer / for testing
################################################################################

if __name__ == "__main__":
    import sys
    import TestermanClient

    if len(sys.argv) < 2:
        serverUrl = "http://localhost:8080"
    else:
        serverUrl = sys.argv[1]

    app = QApplication([])

    client = TestermanClient.Client("test",
                                    "JobQueue/1.0.0",
                                    serverUrl=serverUrl)
    client.startXc()

    w = WJobTreeWidget()
    w.show()
    w.setClient(client)

    app.exec_()
    client.stopXc()