---
lib/rapi/rlib2.py | 22 +++++------
test/ganeti.rapi.rlib2_unittest.py | 68 ++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 12 deletions(-)
diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py
index df6c775..0961c2c 100644
--- a/lib/rapi/rlib2.py
+++ b/lib/rapi/rlib2.py
@@ -515,19 +515,16 @@ class R_2_nodes_name_storage(baserlib.OpcodeResource):
})
-class R_2_nodes_name_storage_modify(baserlib.ResourceBase):
+class R_2_nodes_name_storage_modify(baserlib.OpcodeResource):
"""/2/nodes/[node_name]/storage/modify resource.
"""
- def PUT(self):
- node_name = self.items[0]
+ PUT_OPCODE = opcodes.OpNodeModifyStorage
+ def GetPutOpInput(self):
storage_type = self._checkStringVariable("storage_type", None)
- if not storage_type:
- raise http.HttpBadRequest("Missing the required 'storage_type'"
- " parameter")
-
name = self._checkStringVariable("name", None)
+
if not name:
raise http.HttpBadRequest("Missing the required 'name'"
" parameter")
@@ -538,11 +535,12 @@ class
R_2_nodes_name_storage_modify(baserlib.ResourceBase):
changes[constants.SF_ALLOCATABLE] = \
bool(self._checkIntVariable("allocatable", default=1))
- op = opcodes.OpNodeModifyStorage(node_name=node_name,
- storage_type=storage_type,
- name=name,
- changes=changes)
- return self.SubmitJob([op])
+ return ({}, {
+ "node_name": self.items[0],
+ "storage_type": storage_type,
+ "name": name,
+ "changes": changes,
+ })
class R_2_nodes_name_storage_repair(baserlib.ResourceBase):
diff --git a/test/ganeti.rapi.rlib2_unittest.py
b/test/ganeti.rapi.rlib2_unittest.py
index 0e6b7a7..8b9a3c6 100755
--- a/test/ganeti.rapi.rlib2_unittest.py
+++ b/test/ganeti.rapi.rlib2_unittest.py
@@ -586,6 +586,74 @@ class TestStorageQuery(unittest.TestCase):
self.assertRaises(http.HttpBadRequest, handler.GET)
+class TestStorageModify(unittest.TestCase):
+ def test(self):
+ clfactory = _FakeClientFactory(_FakeClient)
+
+ for allocatable in [None, "1", "0"]:
+ queryargs = {
+ "storage_type": constants.ST_LVM_VG,
+ "name": "pv-a",
+ }
+
+ if allocatable is not None:
+ queryargs["allocatable"] = allocatable
+
+ handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify,
+ ["node9292"], queryargs, {}, clfactory)
+ job_id = handler.PUT()
+
+ cl = clfactory.GetNextClient()
+ self.assertRaises(IndexError, clfactory.GetNextClient)
+
+ (exp_job_id, (op, )) = cl.GetNextSubmittedJob()
+ self.assertEqual(job_id, exp_job_id)
+ self.assertTrue(isinstance(op, opcodes.OpNodeModifyStorage))
+ self.assertEqual(op.node_name, "node9292")
+ self.assertEqual(op.storage_type, constants.ST_LVM_VG)
+ self.assertEqual(op.name, "pv-a")
+ if allocatable is None:
+ self.assertFalse(op.changes)
+ else:
+ assert allocatable in ("0", "1")
+ self.assertEqual(op.changes, {
+ constants.SF_ALLOCATABLE: (allocatable == "1"),
+ })
+ self.assertFalse(hasattr(op, "dry_run"))
+ self.assertFalse(hasattr(op, "force"))
+
+ self.assertRaises(IndexError, cl.GetNextSubmittedJob)
+
+ def testErrors(self):
+ clfactory = _FakeClientFactory(_FakeClient)
+
+ # No storage type
+ queryargs = {
+ "name": "xyz",
+ }
+ handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify,
+ ["node26016"], queryargs, {}, clfactory)
+ self.assertRaises(http.HttpBadRequest, handler.PUT)
+
+ # No name
+ queryargs = {
+ "storage_type": constants.ST_LVM_VG,
+ }
+ handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify,
+ ["node21218"], queryargs, {}, clfactory)
+ self.assertRaises(http.HttpBadRequest, handler.PUT)
+
+ # Invalid value
+ queryargs = {
+ "storage_type": constants.ST_LVM_VG,
+ "name": "pv-b",
+ "allocatable": "noint",
+ }
+ handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify,
+ ["node30685"], queryargs, {}, clfactory)
+ self.assertRaises(http.HttpBadRequest, handler.PUT)
+
+
class TestParseInstanceCreateRequestVersion1(testutils.GanetiTestCase):
def setUp(self):
testutils.GanetiTestCase.setUp(self)
--
1.7.6