RAPI client: Don't check node role in client
authorMichael Hanselmann <hansmi@google.com>
Tue, 11 May 2010 15:55:45 +0000 (17:55 +0200)
committerMichael Hanselmann <hansmi@google.com>
Tue, 11 May 2010 17:27:57 +0000 (19:27 +0200)
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
test/ganeti.rapi.client_unittest.py

index 86d78fc..dccbf95 100644 (file)
@@ -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" %
index 52346dd..0d83580 100755 (executable)
@@ -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,