Commit 527fbde8 authored by Michael Hanselmann's avatar Michael Hanselmann

RAPI: Use FillOpCode for adding node group

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 8a08be3b
......@@ -412,8 +412,10 @@ Returns: a job ID that can be used later for polling.
Body parameters:
``name`` (string, required)
Node group name.
.. opcode_params:: OP_GROUP_ADD
Earlier versions used a parameter named ``name`` which, while still
supported, has been renamed to ``group_name``.
``/2/groups/[group_name]``
......
......@@ -555,12 +555,16 @@ def _ParseCreateGroupRequest(data, dry_run):
@return: Group creation opcode
"""
group_name = baserlib.CheckParameter(data, "name")
alloc_policy = baserlib.CheckParameter(data, "alloc_policy", default=None)
override = {
"dry_run": dry_run,
}
return opcodes.OpGroupAdd(group_name=group_name,
alloc_policy=alloc_policy,
dry_run=dry_run)
rename = {
"name": "group_name",
}
return baserlib.FillOpcode(opcodes.OpGroupAdd, data, override,
rename=rename)
class R_2_groups(baserlib.R_Generic):
......
......@@ -551,5 +551,54 @@ class TestParseModifyGroupRequest(unittest.TestCase):
self.assertFalse(hasattr(op, "alloc_policy"))
class TestParseCreateGroupRequest(unittest.TestCase):
def setUp(self):
self.Parse = rlib2._ParseCreateGroupRequest
def test(self):
name = "group3618"
for policy in constants.VALID_ALLOC_POLICIES:
data = {
"group_name": name,
"alloc_policy": policy,
}
op = self.Parse(data, False)
self.assert_(isinstance(op, opcodes.OpGroupAdd))
self.assertEqual(op.group_name, name)
self.assertEqual(op.alloc_policy, policy)
self.assertFalse(op.dry_run)
def testUnknownPolicy(self):
data = {
"alloc_policy": "_unknown_policy_",
}
self.assertRaises(http.HttpBadRequest, self.Parse, "name", data)
def testDefaults(self):
name = "group15395"
data = {
"group_name": name,
}
op = self.Parse(data, True)
self.assert_(isinstance(op, opcodes.OpGroupAdd))
self.assertEqual(op.group_name, name)
self.assertFalse(hasattr(op, "alloc_policy"))
self.assertTrue(op.dry_run)
def testLegacyName(self):
name = "group29852"
data = {
"name": name,
}
op = self.Parse(data, True)
self.assert_(isinstance(op, opcodes.OpGroupAdd))
self.assertEqual(op.group_name, name)
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