Signed-off-by: Michael Hanselmann <[email protected]>
---
lib/rapi/client.py | 78 +--------------------------------
test/ganeti.rapi.client_unittest.py | 82 +----------------------------------
2 files changed, 3 insertions(+), 157 deletions(-)
diff --git a/lib/rapi/client.py b/lib/rapi/client.py
index 10f1975..f1a157d 100644
--- a/lib/rapi/client.py
+++ b/lib/rapi/client.py
@@ -675,82 +675,8 @@ class GanetiRapiClient(object): # pylint: disable-msg=R0904
body.update((key, value) for key, value in kwargs.iteritems()
if key != "dry_run")
else:
- # Old request format (version 0)
-
- # The following code must make sure that an exception is raised when an
- # unsupported setting is requested by the caller. Otherwise this can lead
- # to bugs difficult to find. The interface of this function must stay
- # exactly the same for version 0 and 1 (e.g. they aren't allowed to
- # require different data types).
-
- # Validate disks
- for idx, disk in enumerate(disks):
- unsupported = set(disk.keys()) - _INST_CREATE_V0_DISK_PARAMS
- if unsupported:
- raise GanetiApiError("Server supports request version 0 only, but"
- " disk %s specifies the unsupported parameters"
- " %s, allowed are %s" %
- (idx, unsupported,
- list(_INST_CREATE_V0_DISK_PARAMS)))
-
- assert (len(_INST_CREATE_V0_DISK_PARAMS) == 1 and
- "size" in _INST_CREATE_V0_DISK_PARAMS)
- disk_sizes = [disk["size"] for disk in disks]
-
- # Validate NICs
- if not nics:
- raise GanetiApiError("Server supports request version 0 only, but"
- " no NIC specified")
- elif len(nics) > 1:
- raise GanetiApiError("Server supports request version 0 only, but"
- " more than one NIC specified")
-
- assert len(nics) == 1
-
- unsupported = set(nics[0].keys()) - _INST_NIC_PARAMS
- if unsupported:
- raise GanetiApiError("Server supports request version 0 only, but"
- " NIC 0 specifies the unsupported parameters %s,"
- " allowed are %s" %
- (unsupported, list(_INST_NIC_PARAMS)))
-
- # Validate other parameters
- unsupported = (set(kwargs.keys()) - _INST_CREATE_V0_PARAMS -
- _INST_CREATE_V0_DPARAMS)
- if unsupported:
- allowed = _INST_CREATE_V0_PARAMS.union(_INST_CREATE_V0_DPARAMS)
- raise GanetiApiError("Server supports request version 0 only, but"
- " the following unsupported parameters are"
- " specified: %s, allowed are %s" %
- (unsupported, list(allowed)))
-
- # All required fields for request data version 0
- body = {
- _REQ_DATA_VERSION_FIELD: 0,
- "name": name,
- "disk_template": disk_template,
- "disks": disk_sizes,
- }
-
- # NIC fields
- assert len(nics) == 1
- assert not (set(body.keys()) & set(nics[0].keys()))
- body.update(nics[0])
-
- # Copy supported fields
- assert not (set(body.keys()) & set(kwargs.keys()))
- body.update(dict((key, value) for key, value in kwargs.items()
- if key in _INST_CREATE_V0_PARAMS))
-
- # Merge dictionaries
- for i in (value for key, value in kwargs.items()
- if key in _INST_CREATE_V0_DPARAMS):
- assert not (set(body.keys()) & set(i.keys()))
- body.update(i)
-
- assert not (set(kwargs.keys()) -
- (_INST_CREATE_V0_PARAMS | _INST_CREATE_V0_DPARAMS))
- assert not (set(body.keys()) & _INST_CREATE_V0_DPARAMS)
+ raise GanetiApiError("Server does not support new-style (version 1)"
+ " instance creation requests")
return self._SendRequest(HTTP_POST, "/%s/instances" % GANETI_RAPI_VERSION,
query, body)
diff --git a/test/ganeti.rapi.client_unittest.py
b/test/ganeti.rapi.client_unittest.py
index 9c41b08..3f9f2b8 100755
--- a/test/ganeti.rapi.client_unittest.py
+++ b/test/ganeti.rapi.client_unittest.py
@@ -510,92 +510,12 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
self.assertQuery("static", ["1"])
def testCreateInstanceOldVersion(self):
- # No NICs
+ # The old request format, version 0, is no longer supported
self.rapi.AddResponse(None, code=404)
self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
"create", "inst1.example.com", "plain", [], [])
self.assertEqual(self.rapi.CountPending(), 0)
- # More than one NIC
- self.rapi.AddResponse(None, code=404)
- self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
- "create", "inst1.example.com", "plain", [],
- [{}, {}, {}])
- self.assertEqual(self.rapi.CountPending(), 0)
-
- # Unsupported NIC fields
- self.rapi.AddResponse(None, code=404)
- self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
- "create", "inst1.example.com", "plain", [],
- [{"x": True, "y": False}])
- self.assertEqual(self.rapi.CountPending(), 0)
-
- # Unsupported disk fields
- self.rapi.AddResponse(None, code=404)
- self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
- "create", "inst1.example.com", "plain",
- [{}, {"moo": "foo",}], [{}])
- self.assertEqual(self.rapi.CountPending(), 0)
-
- # Unsupported fields
- self.rapi.AddResponse(None, code=404)
- self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
- "create", "inst1.example.com", "plain", [], [{}],
- hello_world=123)
- self.assertEqual(self.rapi.CountPending(), 0)
-
- self.rapi.AddResponse(None, code=404)
- self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
- "create", "inst1.example.com", "plain", [], [{}],
- memory=128)
- self.assertEqual(self.rapi.CountPending(), 0)
-
- # Normal creation
- testnics = [
- [{}],
- [{ "mac": constants.VALUE_AUTO, }],
- [{ "ip": "192.0.2.99", "mode": constants.NIC_MODE_ROUTED, }],
- ]
-
- testdisks = [
- [],
- [{ "size": 128, }],
- [{ "size": 321, }, { "size": 4096, }],
- ]
-
- for idx, nics in enumerate(testnics):
- for disks in testdisks:
- beparams = {
- constants.BE_MEMORY: 512,
- constants.BE_AUTO_BALANCE: False,
- }
- hvparams = {
- constants.HV_MIGRATION_PORT: 9876,
- constants.HV_VNC_TLS: True,
- }
-
- self.rapi.AddResponse(None, code=404)
- self.rapi.AddResponse(serializer.DumpJson(3122617 + idx))
- job_id = self.client.CreateInstance("create", "inst1.example.com",
- "plain", disks, nics,
- pnode="node99", dry_run=True,
- hvparams=hvparams,
- beparams=beparams)
- self.assertEqual(job_id, 3122617 + idx)
- self.assertHandler(rlib2.R_2_instances)
- self.assertDryRun()
- self.assertEqual(self.rapi.CountPending(), 0)
-
- data = serializer.LoadJson(self.rapi.GetLastRequestData())
- self.assertEqual(data["name"], "inst1.example.com")
- self.assertEqual(data["disk_template"], "plain")
- self.assertEqual(data["pnode"], "node99")
- self.assertEqual(data[constants.BE_MEMORY], 512)
- self.assertEqual(data[constants.BE_AUTO_BALANCE], False)
- self.assertEqual(data[constants.HV_MIGRATION_PORT], 9876)
- self.assertEqual(data[constants.HV_VNC_TLS], True)
- self.assertEqual(data["disks"], [disk["size"] for disk in disks])
-
def testCreateInstance(self):
self.rapi.AddResponse(serializer.DumpJson([rlib2._INST_CREATE_REQV1]))
self.rapi.AddResponse("23030")
--
1.7.3.5