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): ...@@ -508,22 +508,22 @@ def _ParseInstanceCreateRequestVersion1(data, dry_run):
# Size is mandatory # Size is mandatory
try: try:
size = i["size"] size = i[constants.IDISK_SIZE]
except KeyError: except KeyError:
raise http.HttpBadRequest("Disk %d specification wrong: missing disk" raise http.HttpBadRequest("Disk %d specification wrong: missing disk"
" size" % idx) " size" % idx)
disk = { disk = {
"size": size, constants.IDISK_SIZE: size,
} }
# Optional disk access mode # Optional disk access mode
try: try:
disk_access = i["mode"] disk_access = i[constants.IDISK_MODE]
except KeyError: except KeyError:
pass pass
else: else:
disk["mode"] = disk_access disk[constants.IDISK_MODE] = disk_access
disks.append(disk) disks.append(disk)
...@@ -538,7 +538,7 @@ def _ParseInstanceCreateRequestVersion1(data, dry_run): ...@@ -538,7 +538,7 @@ def _ParseInstanceCreateRequestVersion1(data, dry_run):
nic = {} nic = {}
for field in ["mode", "ip", "link", "bridge"]: for field in constants.INIC_PARAMS:
try: try:
value = i[field] value = i[field]
except KeyError: except KeyError:
......
...@@ -67,7 +67,9 @@ class TestParseInstanceCreateRequestVersion1(testutils.GanetiTestCase): ...@@ -67,7 +67,9 @@ class TestParseInstanceCreateRequestVersion1(testutils.GanetiTestCase):
# Two NICs # 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", }, { "mode": constants.NIC_MODE_BRIDGED, "link": "n0", "bridge": "br1", },
], ],
...@@ -122,21 +124,16 @@ class TestParseInstanceCreateRequestVersion1(testutils.GanetiTestCase): ...@@ -122,21 +124,16 @@ class TestParseInstanceCreateRequestVersion1(testutils.GanetiTestCase):
self.assertEqual(len(op.disks), len(disks)) self.assertEqual(len(op.disks), len(disks))
self.assertEqual(len(op.nics), len(nics)) self.assertEqual(len(op.nics), len(nics))
self.assert_(compat.all(opdisk.get("size") == for opdisk, disk in zip(op.disks, disks):
disk.get("size") and for key in constants.IDISK_PARAMS:
opdisk.get("mode") == self.assertEqual(opdisk.get(key), disk.get(key))
disk.get("mode") and self.assertFalse("unknown" in opdisk)
"unknown" not in opdisk
for opdisk, disk in zip(op.disks, for opnic, nic in zip(op.nics, nics):
disks))) for key in constants.INIC_PARAMS:
self.assertEqual(opnic.get(key), nic.get(key))
self.assert_(compat.all(opnic.get("size") == self.assertFalse("unknown" in opnic)
nic.get("size") and self.assertFalse("foobar" in opnic)
opnic.get("mode") ==
nic.get("mode") and
"unknown" not in opnic and
"foobar" not in opnic
for opnic, nic in zip(op.nics, nics)))
if beparams is None: if beparams is None:
self.assertEqualValues(op.beparams, {}) 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