Fixes for xmlrpc code
cover Fixes for xmlrpc code
From: Alexandru DAMIAN <[email protected]>
Hello,
These are two patches that refactor the XMLRPC client code to make it more reusable, with the goal of using the client class directly in the Toaster build controller to start, control and stop a bitbake server.
Can you please review and merge ?
Cheers,
Alex
The following changes since commit ef2bf63e56b87e19d1a9059dd2d81a9a1a537254:
fetch2/gitsm: Documentation improvements for gitsm:// fetcher (2014-05-19 12:02:45 +0100)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib adamian/20140519-xmlrpcfixes
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=adamian/20140519-xmlrpcfixes
Alexandru DAMIAN (2):
bitbake: move configuration reading code
xmlrpc: client - remove fatal errors
bin/bitbake | 46 +++++++++++++++++++++++++++++++++++----------- lib/bb/server/xmlrpc.py | 33 ++++++--------------------------- 2 files changed, 41 insertions(+), 38 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/2 bitbake: move configuration reading code
From: Alexandru DAMIAN <[email protected]>
The configuration reading code should live in the main bitbake entry point, and the server modules should be supplied with correct configuration instead of attempting to parse from configuration files.
This patch moves the endpoint address reading from XMLRPC to the bitbake main script.
--- bin/bitbake | 23 ++++++++++++++++++++++- lib/bb/server/xmlrpc.py | 24 ------------------------ 2 files changed, 22 insertions(+), 25 deletions(-)
bin/bitbake +22 -1
@@ -200,6 +200,28 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters): options.servertype = "xmlrpc" options.remote_server = os.environ["BBSERVER"] + # if BBSERVER says to autodetect, let's do that + if options.remote_server: + [host, port] = options.remote_server.split(":", 2) + port = int(port) + # use automatic port if port set to -1, means read it from + # the bitbake.lock file; this is a bit tricky, but we always expect + # to be in the base of the build directory if we need to have a + # chance to start the server later, anyway + if port == -1: + lock_location = "./bitbake.lock" + # we try to read the address at all times; if the server is not started, + # we'll try to start it after the first connect fails, below + try: + lf = open(lock_location, 'r') + remotedef = lf.readline() + [host, port] = remotedef.split(":") + port = int(port) + lf.close() + options.remote_server = remotedef + except Exception as e: + sys.exit("Failed to read bitbake.lock (%s), invalid port" % str(e)) + return options, targets[1:]
@@ -309,7 +331,6 @@ def main(): # we start a stub server that is actually a XMLRPClient that connects to a real server server = servermodule.BitBakeXMLRPCClient(configParams.observe_only) server.saveConnectionDetails(configParams.remote_server) - server.saveConnectionConfigParams(configParams) if not configParams.server_only: if configParams.status_only:
lib/bb/server/xmlrpc.py +0 -24
@@ -340,9 +340,6 @@ class BitBakeXMLRPCClient(BitBakeBaseServer): def saveConnectionDetails(self, remote): self.remote = remote - def saveConnectionConfigParams(self, configParams): - self.configParams = configParams - def establishConnection(self, featureset): # The format of "remote" must be "server:port" try:
@@ -351,27 +348,6 @@ class BitBakeXMLRPCClient(BitBakeBaseServer): except Exception as e: bb.fatal("Failed to read remote definition (%s)" % str(e)) - # use automatic port if port set to -1, meaning read it from - # the bitbake.lock file - if port == -1: - lock_location = "%s/bitbake.lock" % self.configParams.environment.get('BUILDDIR') - lock = bb.utils.lockfile(lock_location, False, False) - if lock: - # This means there is no server running which we can - # connect to on the local system. - bb.utils.unlockfile(lock) - return None - - try: - lf = open(lock_location, 'r') - remotedef = lf.readline() - [host, port] = remotedef.split(":") - port = int(port) - lf.close() - self.remote = remotedef - except Exception as e: - bb.fatal("Failed to read bitbake.lock (%s)" % str(e)) - # We need our IP for the server connection. We get the IP # by trying to connect with the server try:
Signature · 1 line
1.9.1
PATCH 2/2 xmlrpc: client - remove fatal errors
From: Alexandru DAMIAN <[email protected]>
When we use the XMLRPC client API to connect to a bitbake server, we want to receive errors from the API instead of having the API exiting without warning.
Thus the "bb.fatal" calls have been replaced with "bb.warn" calls, and we re-raise the original exception for handling by the original caller.
The bitbake starting script has been modified to properly test for failures in calling the client API and handle them.
--- bin/bitbake | 23 +++++++++++++---------- lib/bb/server/xmlrpc.py | 9 ++++++--- 2 files changed, 19 insertions(+), 13 deletions(-)
bin/bitbake +13 -10
@@ -332,26 +332,29 @@ def main(): server = servermodule.BitBakeXMLRPCClient(configParams.observe_only) server.saveConnectionDetails(configParams.remote_server) + def _getServerConnection(server, featureset): + try: + server_connection = server.establishConnection(featureset) + except Exception as e: + bb.fatal("Could not connect to server %s: %s" % (configParams.remote_server, str(e))) + return server_connection + if not configParams.server_only: if configParams.status_only: - try: - server_connection = server.establishConnection(featureset) - except: - sys.exit(1) - if not server_connection: - sys.exit(1) + server_connection = _getServerConnection(server, featureset) server_connection.terminate() sys.exit(0) # Setup a connection to the server (cooker) - server_connection = server.establishConnection(featureset) - if not server_connection: + try: + server_connection = server.establishConnection(featureset) + except: if configParams.kill_server: - bb.fatal("Server already killed") + bb.fatal("Server already offline") configParams.bind = configParams.remote_server start_server(servermodule, configParams, configuration, featureset) bb.event.ui_queue = [] - server_connection = server.establishConnection(featureset) + server_connection = _getServerConnection(server, featureset) # Restore the environment in case the UI needs it for k in cleanedvars:
lib/bb/server/xmlrpc.py +6 -3
@@ -346,7 +346,8 @@ class BitBakeXMLRPCClient(BitBakeBaseServer): [host, port] = self.remote.split(":") port = int(port) except Exception as e: - bb.fatal("Failed to read remote definition (%s)" % str(e)) + bb.warn("Failed to read remote definition (%s)" % str(e)) + raise e # We need our IP for the server connection. We get the IP # by trying to connect with the server
@@ -356,13 +357,15 @@ class BitBakeXMLRPCClient(BitBakeBaseServer): ip = s.getsockname()[0] s.close() except Exception as e: - bb.fatal("Could not create socket for %s:%s (%s)" % (host, port, str(e))) + bb.warn("Could not create socket for %s:%s (%s)" % (host, port, str(e))) + raise e try: self.serverImpl = XMLRPCProxyServer(host, port) self.connection = BitBakeXMLRPCServerConnection(self.serverImpl, (ip, 0), self.observer_only, featureset) return self.connection.connect() except Exception as e: - bb.fatal("Could not connect to server at %s:%s (%s)" % (host, port, str(e))) + bb.warn("Could not connect to server at %s:%s (%s)" % (host, port, str(e))) + raise e def endSession(self): self.connection.removeClient()
Signature · 1 line
1.9.1