Commit 7be048f0 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

rlib2: Use constants for disk and NIC parameters

These constants were added in commit bd061c35

, but the parsing code
was not updated. This also fixes a bug where a NIC's MAC address
wasn't used.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 5f55173b
......@@ -508,22 +508,22 @@ def _ParseInstanceCreateRequestVersion1(data, dry_run):
# Size is mandatory
try:
size = i["size"]
size = i[constants.IDISK_SIZE]
except KeyError:
raise http.HttpBadRequest("Disk %d specification wrong: missing disk"
" size" % idx)
disk = {
"size": size,
constants.IDISK_SIZE: size,
}
# Optional disk access mode
try:
disk_access = i["mode"]
disk_access = i[constants.IDISK_MODE]
except KeyError:
pass
else:
disk["mode"] = disk_access
disk[constants.IDISK_MODE] = disk_access
disks.append(disk)
......@@ -538,7 +538,7 @@ def _ParseInstanceCreateRequestVersion1(data, dry_run):
nic = {}
for field in ["mode", "ip", "link", "bridge"]:
for field in constants.INIC_PARAMS:
try:
value = i[field]
except KeyError:
......
......@@ -67,7 +67,9 @@ class TestParseInstanceCreateRequestVersion1(testutils.GanetiTestCase):
# Two NICs
[
{ "ip": "1.2.3.4", "mode": constants.NIC_MODE_ROUTED, },
{ "ip": "1.2.3.4", "mode": constants.NIC_MODE_ROUTED,
"mac": "01:23:45:67:68:9A",
},
{ "mode": constants.NIC_MODE_BRIDGED, "link": "n0", "bridge": "br1", },
],
......@@ -122,21 +124,16 @@ class TestParseInstanceCreateRequestVersion1(testutils.GanetiTestCase):
self.assertEqual(len(op.disks), len(disks))
self.assertEqual(len(op.nics), len(nics))
self.assert_(compat.all(opdisk.get("size") ==
disk.get("size") and
opdisk.get("mode") ==
disk.get("mode") and
"unknown" not in opdisk
for opdisk, disk in zip(op.disks,
disks)))
self.assert_(compat.all(opnic.get("size") ==
nic.get("size") and
opnic.get("mode") ==
nic.get("mode") and
"unknown" not in opnic and
"foobar" not in opnic
for opnic, nic in zip(op.nics, nics)))
for opdisk, disk in zip(op.disks, disks):
for key in constants.IDISK_PARAMS:
self.assertEqual(opdisk.get(key), disk.get(key))
self.assertFalse("unknown" in opdisk)
for opnic, nic in zip(op.nics, nics):
for key in constants.INIC_PARAMS:
self.assertEqual(opnic.get(key), nic.get(key))
self.assertFalse("unknown" in opnic)
self.assertFalse("foobar" in opnic)
if beparams is None:
self.assertEqualValues(op.beparams, {})
......
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