Commit 98270691 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

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


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 8d232068
......@@ -549,27 +549,27 @@ class R_2_nodes_name_storage_modify(baserlib.OpcodeResource):
})
class R_2_nodes_name_storage_repair(baserlib.ResourceBase):
class R_2_nodes_name_storage_repair(baserlib.OpcodeResource):
"""/2/nodes/[node_name]/storage/repair resource.
"""
def PUT(self):
node_name = self.items[0]
PUT_OPCODE = opcodes.OpRepairNodeStorage
storage_type = self._checkStringVariable("storage_type", None)
if not storage_type:
raise http.HttpBadRequest("Missing the required 'storage_type'"
" parameter")
def GetPutOpInput(self):
"""Repairs 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")
op = opcodes.OpRepairNodeStorage(node_name=node_name,
storage_type=storage_type,
name=name)
return self.SubmitJob([op])
return ({}, {
"node_name": self.items[0],
"storage_type": storage_type,
"name": name,
})
class R_2_groups(baserlib.OpcodeResource):
......
......@@ -654,6 +654,51 @@ class TestStorageModify(unittest.TestCase):
self.assertRaises(http.HttpBadRequest, handler.PUT)
class TestStorageRepair(unittest.TestCase):
def test(self):
clfactory = _FakeClientFactory(_FakeClient)
queryargs = {
"storage_type": constants.ST_LVM_PV,
"name": "pv16611",
}
handler = _CreateHandler(rlib2.R_2_nodes_name_storage_repair,
["node19265"], 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.OpRepairNodeStorage))
self.assertEqual(op.node_name, "node19265")
self.assertEqual(op.storage_type, constants.ST_LVM_PV)
self.assertEqual(op.name, "pv16611")
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_repair,
["node11275"], 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_repair,
["node21218"], 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