Commit e5ff1a47 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

Populate the instance dict with opcode infos

This is needed so we can load it as an opcode. However, this information
should not be available on the client, so we inject that info when we
receive the request.

Provided unittest to verify behaviour.
Signed-off-by: default avatarRené Nussbaumer <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 3a6a89d7
......@@ -56,6 +56,7 @@ PUT should be prefered over POST.
# C0103: Invalid name, since the R_* names are not conforming
from ganeti import opcodes
from ganeti import objects
from ganeti import http
from ganeti import constants
from ganeti import cli
......@@ -825,7 +826,19 @@ class R_2_instances_multi_alloc(baserlib.OpcodeResource):
return (self.request_body, {
if "instances" not in self.request_body:
raise http.HttpBadRequest("Request is missing required 'instances' field"
" in body")
op_id = {
"OP_ID": self.POST_OPCODE.OP_ID, # pylint: disable=E1101
body = objects.FillDict(self.request_body, {
"instances": [objects.FillDict(inst, op_id)
for inst in self.request_body["instances"]],
return (body, {
"dry_run": self.dryRun(),
......@@ -1734,5 +1734,24 @@ class TestClusterInfo(unittest.TestCase):
self.assertEqual(result, cl.cluster_info)
class TestInstancesMultiAlloc(unittest.TestCase):
def testInstanceUpdate(self):
clfactory = _FakeClientFactory(_FakeClient)
data = {
"instances": [{
"instance_name": "bar",
"mode": "create",
}, {
"instance_name": "foo",
"mode": "create",
handler = _CreateHandler(rlib2.R_2_instances_multi_alloc, [], {}, data,
(body, _) = handler.GetPostOpInput()
self.assertTrue(compat.all([inst["OP_ID"] == handler.POST_OPCODE.OP_ID
for inst in body["instances"]]))
if __name__ == '__main__':
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