From 7189e7909a1710ad9c13dbee71dc83bcc3ef3e7d Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Tue, 11 Aug 2009 16:29:10 +0100
Subject: [PATCH] querylib: abstract a couple of common errors

Rather than composing them every time, we'll keep "ready-made" tuples
for unknown entries and internal errors (which is, yet, unused)

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/confd/querylib.py | 9 ++++++---
 lib/constants.py      | 1 +
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/confd/querylib.py b/lib/confd/querylib.py
index c51bfa2fa..caa5002bc 100644
--- a/lib/confd/querylib.py
+++ b/lib/confd/querylib.py
@@ -25,6 +25,11 @@
 
 from ganeti import constants
 
+# constants for some common errors to return from a query
+QUERY_UNKNOWN_ENTRY_ERROR = (constants.CONFD_REPL_STATUS_ERROR,
+                             constants.CONFD_ERROR_UNKNOWN_ENTRY)
+QUERY_INTERNAL_ERROR = (constants.CONFD_REPL_STATUS_ERROR,
+                        constants.CONFD_ERROR_INTERNAL)
 
 class ConfdQuery(object):
   """Confd Query base class.
@@ -93,9 +98,7 @@ class NodeRoleQuery(ConfdQuery):
       return status, answer
     flags = self.reader.GetNodeStatusFlags(node)
     if flags is None:
-      status = constants.CONFD_REPL_STATUS_ERROR
-      answer = constants.CONFD_ERROR_UNKNOWN_ENTRY
-      return status, answer
+      return QUERY_UNKNOWN_ENTRY_ERROR
 
     master_candidate, drained, offline = flags
     if master_candidate:
diff --git a/lib/constants.py b/lib/constants.py
index 2ca5f755f..7264954f6 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -654,6 +654,7 @@ CONFD_REPL_STATUSES = frozenset([
 
 # A few common errors for confd
 CONFD_ERROR_UNKNOWN_ENTRY = 1
+CONFD_ERROR_INTERNAL = 2
 
 # Each request is "salted" by the current timestamp.
 # This constants decides how many seconds of skew to accept.
-- 
GitLab