Commit 8d232068 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

rlib2: Convert /2/nodes/[node_name]/storage/modify to OpcodeResource


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent eb08e09d
......@@ -518,19 +518,19 @@ 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
storage_type = self._checkStringVariable("storage_type", None)
if not storage_type:
raise http.HttpBadRequest("Missing the required 'storage_type'"
" parameter")
def GetPutOpInput(self):
"""Modifies a storage volume on a node.
"""
storage_type = self._checkStringVariable("storage_type", None)
name = self._checkStringVariable("name", None)
if not name:
raise http.HttpBadRequest("Missing the required 'name'"
" parameter")
......@@ -541,11 +541,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):
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment