From 7be048f0198a6a01e2514c4eafff1a23cd0e38b4 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Mon, 12 Jul 2010 22:16:52 +0200 Subject: [PATCH] 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: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/rapi/rlib2.py | 10 +++++----- test/ganeti.rapi.rlib2_unittest.py | 29 +++++++++++++---------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py index e15546e8a..0c87efd88 100644 --- a/lib/rapi/rlib2.py +++ b/lib/rapi/rlib2.py @@ -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: diff --git a/test/ganeti.rapi.rlib2_unittest.py b/test/ganeti.rapi.rlib2_unittest.py index 70f163e3b..179da9c88 100755 --- a/test/ganeti.rapi.rlib2_unittest.py +++ b/test/ganeti.rapi.rlib2_unittest.py @@ -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, {}) -- GitLab