[bitbake-devel] [PATCH 2/2] xmlrpc: client - remove fatal errors

Alex DAMIAN alexandru.damian at intel.com
Mon May 19 13:36:53 UTC 2014


From: Alexandru DAMIAN <alexandru.damian at intel.com>

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.

Signed-off-by: Alexandru DAMIAN <alexandru.damian at intel.com>
---
 bin/bitbake             | 23 +++++++++++++----------
 lib/bb/server/xmlrpc.py |  9 ++++++---
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/bin/bitbake b/bin/bitbake
index fcfe043..ab881c5 100755
--- a/bin/bitbake
+++ b/bin/bitbake
@@ -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:
diff --git a/lib/bb/server/xmlrpc.py b/lib/bb/server/xmlrpc.py
index 6fc5543..379544a 100644
--- a/lib/bb/server/xmlrpc.py
+++ b/lib/bb/server/xmlrpc.py
@@ -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()
-- 
1.9.1




More information about the bitbake-devel mailing list