From 352e1a263cdd58b6c505f1d337ee6a27a7f53290 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Fri, 30 Mar 2012 13:58:33 +0200
Subject: [PATCH] errors: Add exception for RAPI testing utilities

This exception is raised to abort before actually sending a LUXI call
(there is no LUXI server involved in the test). The testing utilities
catch the exception to report a success (i.e. the code didn't throw
an exception before due to invalid types, etc.). To allow the exception
to be thrown all the way to the test utilities, the HTTP server library
must ignore it. Also some overly generic exception handling is removed
from the RAPI request handler.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/errors.py      | 6 ++++++
 lib/http/server.py | 4 +++-
 lib/server/rapi.py | 4 ----
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/errors.py b/lib/errors.py
index 3847353b7..27d2fccf7 100644
--- a/lib/errors.py
+++ b/lib/errors.py
@@ -429,6 +429,12 @@ class QueryFilterParseError(ParseError):
             str(inner)]
 
 
+class RapiTestResult(GenericError):
+  """Exception containing results from RAPI test utilities.
+
+  """
+
+
 # errors should be added above
 
 
diff --git a/lib/http/server.py b/lib/http/server.py
index d28bf6659..a5294964e 100644
--- a/lib/http/server.py
+++ b/lib/http/server.py
@@ -35,6 +35,7 @@ from ganeti import http
 from ganeti import utils
 from ganeti import netutils
 from ganeti import compat
+from ganeti import errors
 
 
 WEEKDAYNAME = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
@@ -233,7 +234,8 @@ def _HandleServerRequestInner(handler, req_msg):
 
       # Call actual request handler
       result = handler.HandleRequest(handler_context)
-    except (http.HttpException, KeyboardInterrupt, SystemExit):
+    except (http.HttpException, errors.RapiTestResult,
+            KeyboardInterrupt, SystemExit):
       raise
     except Exception, err:
       logging.exception("Caught exception")
diff --git a/lib/server/rapi.py b/lib/server/rapi.py
index 5ccc60e6e..972419cda 100644
--- a/lib/server/rapi.py
+++ b/lib/server/rapi.py
@@ -194,10 +194,6 @@ class RemoteApiHandler(http.auth.HttpServerRequestAuthentication,
       raise http.HttpGatewayTimeout()
     except luxi.ProtocolError, err:
       raise http.HttpBadGateway(str(err))
-    except:
-      method = req.request_method.upper()
-      logging.exception("Error while handling the %s request", method)
-      raise
 
     req.resp_headers[http.HTTP_CONTENT_TYPE] = http.HTTP_APP_JSON
 
-- 
GitLab