Commit df340fae authored by Michael Hanselmann's avatar Michael Hanselmann

RAPI: Use FillOpCode for modifying node group

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 88bc199a
......@@ -451,8 +451,8 @@ Returns a job ID.
Body parameters:
``alloc_policy`` (string)
If present, the new allocation policy for the node group.
.. opcode_params:: OP_GROUP_SET_PARAMS
:exclude: group_name
``/2/groups/[group_name]/rename``
......
......@@ -628,8 +628,10 @@ def _ParseModifyGroupRequest(name, data):
@return: Group modify opcode
"""
alloc_policy = baserlib.CheckParameter(data, "alloc_policy", default=None)
return opcodes.OpGroupSetParams(group_name=name, alloc_policy=alloc_policy)
return baserlib.FillOpcode(opcodes.OpGroupSetParams, data, {
"group_name": name,
})
class R_2_groups_name_modify(baserlib.R_Generic):
......
......@@ -476,5 +476,39 @@ class TestParseInstanceReplaceDisksRequest(unittest.TestCase):
})
class TestParseModifyGroupRequest(unittest.TestCase):
def setUp(self):
self.Parse = rlib2._ParseModifyGroupRequest
def test(self):
name = "group6002"
for policy in constants.VALID_ALLOC_POLICIES:
data = {
"alloc_policy": policy,
}
op = self.Parse(name, data)
self.assert_(isinstance(op, opcodes.OpGroupSetParams))
self.assertEqual(op.group_name, name)
self.assertEqual(op.alloc_policy, policy)
def testUnknownPolicy(self):
data = {
"alloc_policy": "_unknown_policy_",
}
self.assertRaises(http.HttpBadRequest, self.Parse, "name", data)
def testDefaults(self):
name = "group6679"
data = {}
op = self.Parse(name, data)
self.assert_(isinstance(op, opcodes.OpGroupSetParams))
self.assertEqual(op.group_name, name)
self.assertFalse(hasattr(op, "alloc_policy"))
if __name__ == '__main__':
testutils.GanetiTestProgram()
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