Accept both PUT and POST in noded
authorIustin Pop <iustin@google.com>
Fri, 21 Oct 2011 21:51:39 +0000 (23:51 +0200)
committerIustin Pop <iustin@google.com>
Tue, 7 Feb 2012 11:52:36 +0000 (12:52 +0100)
This is a partial cherry-pick from
7530364ddbe949bc34fc26f25ba3f5d921beb021 on master:

Currently, noded requires PUT, even though the semantics of the RPC
calls do not match a PUT. We change the code accept both PUT and POST,
with the intention to remove the PUT support in a later version.

Additionally, we add a message to the HttpBadRequest exception to make
clear the failure mode (not seeing any error message was what made me
send this patch…). This was the only description-less use of this
exception, by the way.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: René Nussbaumer <rn@google.com>
(cherry picked from commit 7530364ddbe949bc34fc26f25ba3f5d921beb021)

What was not cherry-picked is the rpc change (to switch to PUT). The
reason I want to backport this to devel-2.5 is that when upgrading to
2.6, having noded accept both makes for an easier upgrade path.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/server/noded.py

index bdd2dec..0377ba9 100644 (file)
@@ -138,8 +138,9 @@ class NodeHttpServer(http.server.HttpServer):
     """Handle a request.
 
     """
-    if req.request_method.upper() != http.HTTP_PUT:
-      raise http.HttpBadRequest()
+    # FIXME: Remove HTTP_PUT in Ganeti 2.7
+    if req.request_method.upper() not in (http.HTTP_PUT, http.HTTP_POST):
+      raise http.HttpBadRequest("Only PUT and POST methods are supported")
 
     path = req.request_path
     if path.startswith("/"):