Change method dispatch in ClientOps to enforce luxi.REQ_ALL
authorKlaus Aehlig <aehlig@google.com>
Mon, 15 Jul 2013 09:24:28 +0000 (11:24 +0200)
committerKlaus Aehlig <aehlig@google.com>
Mon, 15 Jul 2013 12:59:58 +0000 (14:59 +0200)
ClientOps' handle_request dispatches on the luxi request received. Change
this to first verify if the request is luxi.REQ_ALL. In this way, we catch
programming errors introducing "secret" luxi requests earlier. This is relevant,
as our other checks for internal consistency compare against luxi.REQ_ALL.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>

lib/server/masterd.py

index 8b52c35..b0e8708 100644 (file)
@@ -279,6 +279,10 @@ class ClientOps:
       logging.info("Received invalid arguments of type '%s'", type(args))
       raise ValueError("Invalid arguments type '%s'" % type(args))
 
+    if method not in luxi.REQ_ALL:
+      logging.info("Received invalid request '%s'", method)
+      raise ValueError("Invalid operation '%s'" % method)
+
     # TODO: Rewrite to not exit in each 'if/elif' branch
 
     if method == luxi.REQ_SUBMIT_JOB:
@@ -446,8 +450,9 @@ class ClientOps:
       return _SetWatcherPause(context, until)
 
     else:
-      logging.info("Received invalid request '%s'", method)
-      raise ValueError("Invalid operation '%s'" % method)
+      logging.critical("Request '%s' in luxi.REQ_ALL, but not known", method)
+      raise errors.ProgrammerError("Operation '%s' in luxi.REQ_ALL,"
+                                   " but not implemented" % method)
 
   def _Query(self, op):
     """Runs the specified opcode and returns the result.