Add QA tests for RAPI multi-instance allocation
[ganeti-local] / lib / rapi / rlib2.py
index 9b3dbaa..a3a7f19 100644 (file)
@@ -74,17 +74,18 @@ I_FIELDS = ["name", "admin_state", "os",
             "nic.ips", "nic.macs", "nic.modes", "nic.uuids", "nic.names",
             "nic.links", "nic.networks", "nic.networks.names", "nic.bridges",
             "network_port",
-            "disk.sizes", "disk_usage", "disk.uuids", "disk.names",
+            "disk.sizes", "disk.spindles", "disk_usage", "disk.uuids",
+            "disk.names",
             "beparams", "hvparams",
             "oper_state", "oper_ram", "oper_vcpus", "status",
             "custom_hvparams", "custom_beparams", "custom_nicparams",
             ] + _COMMON_FIELDS
 
 N_FIELDS = ["name", "offline", "master_candidate", "drained",
-            "dtotal", "dfree",
+            "dtotal", "dfree", "sptotal", "spfree",
             "mtotal", "mnode", "mfree",
             "pinst_cnt", "sinst_cnt",
-            "ctotal", "cnodes", "csockets",
+            "ctotal", "cnos", "cnodes", "csockets",
             "pip", "sip", "role",
             "pinst_list", "sinst_list",
             "master_capable", "vm_capable",
@@ -885,6 +886,27 @@ class R_2_groups_name_assign_nodes(baserlib.OpcodeResource):
       })
 
 
+def _ConvertUsbDevices(data):
+  """Convert in place the usb_devices string to the proper format.
+
+  In Ganeti 2.8.4 the separator for the usb_devices hvparam was changed from
+  comma to space because commas cannot be accepted on the command line
+  (they already act as the separator between different hvparams). RAPI
+  should be able to accept commas for backwards compatibility, but we want
+  it to also accept the new space separator. Therefore, we convert
+  spaces into commas here and keep the old parsing logic elsewhere.
+
+  """
+  try:
+    hvparams = data["hvparams"]
+    usb_devices = hvparams[constants.HV_USB_DEVICES]
+    hvparams[constants.HV_USB_DEVICES] = usb_devices.replace(" ", ",")
+    data["hvparams"] = hvparams
+  except KeyError:
+    #No usb_devices, no modification required
+    pass
+
+
 class R_2_instances(baserlib.OpcodeResource):
   """/2/instances resource.
 
@@ -934,6 +956,8 @@ class R_2_instances(baserlib.OpcodeResource):
     # Remove "__version__"
     data.pop(_REQ_DATA_VERSION, None)
 
+    _ConvertUsbDevices(data)
+
     return (data, {
       "dry_run": self.dryRun(),
       })
@@ -956,12 +980,19 @@ class R_2_instances_multi_alloc(baserlib.OpcodeResource):
       raise http.HttpBadRequest("Request is missing required 'instances' field"
                                 " in body")
 
-    op_id = {
-      "OP_ID": self.POST_OPCODE.OP_ID, # pylint: disable=E1101
-      }
+    # Unlike most other RAPI calls, this one is composed of individual opcodes,
+    # and we have to do the filling ourselves
+    OPCODE_RENAME = {
+      "os": "os_type",
+      "name": "instance_name",
+    }
+
     body = objects.FillDict(self.request_body, {
-      "instances": [objects.FillDict(inst, op_id)
-                    for inst in self.request_body["instances"]],
+      "instances": [
+        baserlib.FillOpcode(opcodes.OpInstanceCreate, inst, {},
+                            rename=OPCODE_RENAME)
+        for inst in self.request_body["instances"]
+        ],
       })
 
     return (body, {
@@ -1327,7 +1358,10 @@ class R_2_instances_name_modify(baserlib.OpcodeResource):
     """Changes parameters of an instance.
 
     """
-    return (self.request_body, {
+    data = self.request_body.copy()
+    _ConvertUsbDevices(data)
+
+    return (data, {
       "instance_name": self.items[0],
       })