Commit c1ce76bb authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix handling of 'vcpus' in instance list



Currently running “gnt-instance list -o+vcpus” fails with a cryptic message:
  Unhandled Ganeti error: vcpus

This is due to multiple issues:
  - in some corner cases cmdlib.py raises an errors.ParameterError but
    this is not handled by cli.py
  - LUQueryInstances declares ‘vcpu’ as a supported field, but doesn't handle
    it, so instead of failing with unknown parameter, e.g.:
      Failure: prerequisites not met for this operation:
      Unknown output fields selected: vcpuscd
    it raises the ParameteError message

This patch:
  - adds handling of 'vcpus' to LUQueryInstances
  - adds handling of the ParameterError exception to cli.py
  - changes the 'else: raise errors.ParameterError' in the field handling of
    LUQueryInstance to an assert, since it's a programmer error if we reached
    this step

With this, a future unhandled parameter will show:
  gnt-instance list -o+vcpus
  Unhandled protocol error while talking to the master daemon:
  Caught exception: Declared but unhandled parameter 'vcpus'
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 6dfad215
...@@ -676,6 +676,8 @@ def FormatError(err): ...@@ -676,6 +676,8 @@ def FormatError(err):
" job submissions until old jobs are archived\n") " job submissions until old jobs are archived\n")
elif isinstance(err, errors.TypeEnforcementError): elif isinstance(err, errors.TypeEnforcementError):
obuf.write("Parameter Error: %s" % msg) obuf.write("Parameter Error: %s" % msg)
elif isinstance(err, errors.ParameterError):
obuf.write("Failure: unknown/wrong parameter name '%s'" % msg)
elif isinstance(err, errors.GenericError): elif isinstance(err, errors.GenericError):
obuf.write("Unhandled Ganeti error: %s" % msg) obuf.write("Unhandled Ganeti error: %s" % msg)
elif isinstance(err, luxi.NoMasterError): elif isinstance(err, luxi.NoMasterError):
......
...@@ -3410,6 +3410,8 @@ class LUQueryInstances(NoHooksLU): ...@@ -3410,6 +3410,8 @@ class LUQueryInstances(NoHooksLU):
val = live_data[instance.name].get("memory", "?") val = live_data[instance.name].get("memory", "?")
else: else:
val = "-" val = "-"
elif field == "vcpus":
val = i_be[constants.BE_VCPUS]
elif field == "disk_template": elif field == "disk_template":
val = instance.disk_template val = instance.disk_template
elif field == "ip": elif field == "ip":
...@@ -3493,9 +3495,10 @@ class LUQueryInstances(NoHooksLU): ...@@ -3493,9 +3495,10 @@ class LUQueryInstances(NoHooksLU):
else: else:
assert False, "Unhandled NIC parameter" assert False, "Unhandled NIC parameter"
else: else:
assert False, "Unhandled variable parameter" assert False, ("Declared but unhandled variable parameter '%s'" %
field)
else: else:
raise errors.ParameterError(field) assert False, "Declared but unhandled parameter '%s'" % field
iout.append(val) iout.append(val)
output.append(iout) output.append(iout)
......
...@@ -219,6 +219,7 @@ def ListInstances(opts, args): ...@@ -219,6 +219,7 @@ def ListInstances(opts, args):
"hvparams": "Hypervisor_parameters", "hvparams": "Hypervisor_parameters",
"be/memory": "Configured_memory", "be/memory": "Configured_memory",
"be/vcpus": "VCPUs", "be/vcpus": "VCPUs",
"vcpus": "VCPUs",
"be/auto_balance": "Auto_balance", "be/auto_balance": "Auto_balance",
"disk.count": "Disks", "disk.sizes": "Disk_sizes", "disk.count": "Disks", "disk.sizes": "Disk_sizes",
"nic.count": "NICs", "nic.ips": "NIC_IPs", "nic.count": "NICs", "nic.ips": "NIC_IPs",
......
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