From fde28316332414323569c975c024f6e533208ce5 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Tue, 11 May 2010 16:22:29 +0200
Subject: [PATCH] =?UTF-8?q?RAPI=20client:=20Fix=20behaviour=20of=20?=
 =?UTF-8?q?=E2=80=9Callocatable=E2=80=9D=20storage=20flag?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When modifying a storage unit, the β€œallocatable” flag should default
to β€œno modification”. This replicates the behaviour of the command
line interface.

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

diff --git a/lib/rapi/client.py b/lib/rapi/client.py
index 61a6e7184..b05867aca 100644
--- a/lib/rapi/client.py
+++ b/lib/rapi/client.py
@@ -987,7 +987,7 @@ class GanetiRapiClient(object):
                              ("/%s/nodes/%s/storage" %
                               (GANETI_RAPI_VERSION, node)), query, None)
 
-  def ModifyNodeStorageUnits(self, node, storage_type, name, allocatable=True):
+  def ModifyNodeStorageUnits(self, node, storage_type, name, allocatable=None):
     """Modifies parameters of storage units on the node.
 
     @type node: str
@@ -996,8 +996,9 @@ class GanetiRapiClient(object):
     @param storage_type: storage type whose units to modify
     @type name: str
     @param name: name of the storage unit
-    @type allocatable: bool
-    @param allocatable: TODO: Document me
+    @type allocatable: bool or None
+    @param allocatable: Whether to set the "allocatable" flag on the storage
+                        unit (None=no modification, True=set, False=unset)
 
     @rtype: int
     @return: job id
@@ -1006,9 +1007,11 @@ class GanetiRapiClient(object):
     query = [
       ("storage_type", storage_type),
       ("name", name),
-      ("allocatable", allocatable),
       ]
 
+    if allocatable is not None:
+      query.append(("allocatable", allocatable))
+
     return self._SendRequest(HTTP_PUT,
                              ("/%s/nodes/%s/storage/modify" %
                               (GANETI_RAPI_VERSION, node)), query, None)
diff --git a/test/ganeti.rapi.client_unittest.py b/test/ganeti.rapi.client_unittest.py
index def0548ce..585d58e9a 100755
--- a/test/ganeti.rapi.client_unittest.py
+++ b/test/ganeti.rapi.client_unittest.py
@@ -450,6 +450,18 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
     self.assertItems(["node-z"])
     self.assertQuery("storage_type", ["lvm-pv"])
     self.assertQuery("name", ["hda"])
+    self.assertQuery("allocatable", None)
+
+    for allocatable, query_allocatable in [(True, "1"), (False, "0")]:
+      self.rapi.AddResponse("7205")
+      job_id = self.client.ModifyNodeStorageUnits("node-z", "lvm-pv", "hda",
+                                                  allocatable=allocatable)
+      self.assertEqual(7205, job_id)
+      self.assertHandler(rlib2.R_2_nodes_name_storage_modify)
+      self.assertItems(["node-z"])
+      self.assertQuery("storage_type", ["lvm-pv"])
+      self.assertQuery("name", ["hda"])
+      self.assertQuery("allocatable", [query_allocatable])
 
   def testRepairNodeStorageUnits(self):
     self.rapi.AddResponse("99")
-- 
GitLab