From 1068639f028bc0421e9b6596df012d94cb903442 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Tue, 11 May 2010 17:55:45 +0200
Subject: [PATCH] RAPI client: Don't check node role in client

Only the server knows which node roles can be set via RAPI.
Constants are provided for convenience.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/rapi/client.py                  | 25 +++++++++----------------
 test/ganeti.rapi.client_unittest.py |  3 ---
 2 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/lib/rapi/client.py b/lib/rapi/client.py
index 86d78fcdf..dccbf95a7 100644
--- a/lib/rapi/client.py
+++ b/lib/rapi/client.py
@@ -45,9 +45,12 @@ REPLACE_DISK_PRI = "replace_on_primary"
 REPLACE_DISK_SECONDARY = "replace_on_secondary"
 REPLACE_DISK_CHG = "replace_new_secondary"
 REPLACE_DISK_AUTO = "replace_auto"
-VALID_NODE_ROLES = frozenset([
-  "drained", "master", "master-candidate", "offline", "regular",
-  ])
+
+NODE_ROLE_DRAINED = "drained"
+NODE_ROLE_MASTER_CANDIATE = "master-candidate"
+NODE_ROLE_MASTER = "master"
+NODE_ROLE_OFFLINE = "offline"
+NODE_ROLE_REGULAR = "regular"
 
 
 class Error(Exception):
@@ -73,13 +76,6 @@ class GanetiApiError(Error):
     self.code = code
 
 
-class InvalidNodeRole(Error):
-  """Raised when an invalid node role is used.
-
-  """
-  pass
-
-
 def FormatX509Name(x509_name):
   """Formats an X509 name.
 
@@ -932,13 +928,10 @@ class GanetiRapiClient(object):
     @rtype: int
     @return: job id
 
-    @raise InvalidNodeRole: If an invalid node role is specified
-
     """
-    if role not in VALID_NODE_ROLES:
-      raise InvalidNodeRole("%s is not a valid node role" % role)
-
-    query = [("force", force)]
+    query = [
+      ("force", force),
+      ]
 
     return self._SendRequest(HTTP_PUT,
                              ("/%s/nodes/%s/role" %
diff --git a/test/ganeti.rapi.client_unittest.py b/test/ganeti.rapi.client_unittest.py
index 52346dd35..0d83580a9 100755
--- a/test/ganeti.rapi.client_unittest.py
+++ b/test/ganeti.rapi.client_unittest.py
@@ -428,9 +428,6 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
     self.assertQuery("force", ["1"])
     self.assertEqual("\"master-candidate\"", self.http.last_request.data)
 
-    self.assertRaises(client.InvalidNodeRole,
-                      self.client.SetNodeRole, "node-bar", "fake-role")
-
   def testGetNodeStorageUnits(self):
     self.rapi.AddResponse("42")
     self.assertEqual(42,
-- 
GitLab