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

rlib2: Convert /2/groups/[group_name]/modify to OpcodeResource


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent c91407bc
......@@ -632,33 +632,20 @@ class R_2_groups_name(baserlib.ResourceBase):
return self.SubmitJob([op])
def _ParseModifyGroupRequest(name, data):
"""Parses a request for modifying a node group.
@rtype: L{opcodes.OpGroupSetParams}
@return: Group modify opcode
"""
return baserlib.FillOpcode(opcodes.OpGroupSetParams, data, {
"group_name": name,
})
class R_2_groups_name_modify(baserlib.ResourceBase):
class R_2_groups_name_modify(baserlib.OpcodeResource):
"""/2/groups/[group_name]/modify resource.
"""
def PUT(self):
"""Changes some parameters of node group.
PUT_OPCODE = opcodes.OpGroupSetParams
@return: a job id
def GetPutOpInput(self):
"""Changes some parameters of node group.
"""
baserlib.CheckType(self.request_body, dict, "Body contents")
op = _ParseModifyGroupRequest(self.items[0], self.request_body)
return self.SubmitJob([op])
assert self.items
return (self.request_body, {
"group_name": self.items[0],
})
def _ParseRenameGroupRequest(name, data, dry_run):
......
......@@ -752,11 +752,10 @@ class TestParseInstanceReplaceDisksRequest(unittest.TestCase):
})
class TestParseModifyGroupRequest(unittest.TestCase):
def setUp(self):
self.Parse = rlib2._ParseModifyGroupRequest
class TestGroupModify(unittest.TestCase):
def test(self):
clfactory = _FakeClientFactory(_FakeClient)
name = "group6002"
for policy in constants.VALID_ALLOC_POLICIES:
......@@ -764,26 +763,54 @@ class TestParseModifyGroupRequest(unittest.TestCase):
"alloc_policy": policy,
}
op = self.Parse(name, data)
self.assert_(isinstance(op, opcodes.OpGroupSetParams))
handler = _CreateHandler(rlib2.R_2_groups_name_modify, [name], {}, data,
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.OpGroupSetParams))
self.assertEqual(op.group_name, name)
self.assertEqual(op.alloc_policy, policy)
self.assertFalse(hasattr(op, "dry_run"))
self.assertRaises(IndexError, cl.GetNextSubmittedJob)
def testUnknownPolicy(self):
clfactory = _FakeClientFactory(_FakeClient)
data = {
"alloc_policy": "_unknown_policy_",
}
self.assertRaises(http.HttpBadRequest, self.Parse, "name", data)
handler = _CreateHandler(rlib2.R_2_groups_name_modify, ["xyz"], {}, data,
clfactory)
self.assertRaises(http.HttpBadRequest, handler.PUT)
self.assertRaises(IndexError, clfactory.GetNextClient)
def testDefaults(self):
clfactory = _FakeClientFactory(_FakeClient)
name = "group6679"
data = {}
op = self.Parse(name, data)
self.assert_(isinstance(op, opcodes.OpGroupSetParams))
handler = _CreateHandler(rlib2.R_2_groups_name_modify, [name], {}, {},
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.OpGroupSetParams))
self.assertEqual(op.group_name, name)
self.assertFalse(hasattr(op, "alloc_policy"))
self.assertFalse(hasattr(op, "dry_run"))
self.assertRaises(IndexError, cl.GetNextSubmittedJob)
class TestGroupAdd(unittest.TestCase):
......
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