From d21eda27acbfd4da15725000f738c5f6aeadcad3 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Mon, 10 Aug 2009 17:17:39 +0100
Subject: [PATCH] ConfdProcessor: move verification to __init__

During a query execution we currently verify whether we have that query
supported in our dispatch table. Since it's an error not to have it
anyway, we move this verification to the class creation, erroring out
early if such a problem exists.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/confd/server.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/lib/confd/server.py b/lib/confd/server.py
index 3d1a2ee0c..efea38d51 100644
--- a/lib/confd/server.py
+++ b/lib/confd/server.py
@@ -57,6 +57,9 @@ class ConfdProcessor(object):
     """
     self.reader = reader
     self.hmac_key = utils.ReadFile(constants.HMAC_CLUSTER_KEY)
+    assert \
+      not constants.CONFD_REQS.symmetric_difference(self.DISPATCH_TABLE), \
+      "DISPATCH_TABLE is unaligned with CONFD_REQS"
 
   def ExecQuery(self, payload_in, ip, port):
     """Process a single UDP request from a client.
@@ -131,10 +134,6 @@ class ConfdProcessor(object):
       msg = "missing requested salt"
       raise errors.ConfdRequestError(msg)
 
-    if request.type not in self.DISPATCH_TABLE:
-      msg = "Valid request %d not in DISPATCH_TABLE" % request.type
-      raise errors.ProgrammerError(msg)
-
     query_object = self.DISPATCH_TABLE[request.type](self.reader)
     status, answer = query_object.Exec(request.query)
     reply = objects.ConfdReply(
-- 
GitLab