From c1ce76bb45105d83a4f83e990cb38d2d94fadec0 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 17 Jun 2009 15:42:09 +0200 Subject: [PATCH] Fix handling of 'vcpus' in instance list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- lib/cli.py | 2 ++ lib/cmdlib.py | 7 +++++-- scripts/gnt-instance | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 17dc47c17..d351f2f77 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -676,6 +676,8 @@ def FormatError(err): " job submissions until old jobs are archived\n") elif isinstance(err, errors.TypeEnforcementError): 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): obuf.write("Unhandled Ganeti error: %s" % msg) elif isinstance(err, luxi.NoMasterError): diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 1c2ffbbec..28c51f83f 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -3410,6 +3410,8 @@ class LUQueryInstances(NoHooksLU): val = live_data[instance.name].get("memory", "?") else: val = "-" + elif field == "vcpus": + val = i_be[constants.BE_VCPUS] elif field == "disk_template": val = instance.disk_template elif field == "ip": @@ -3493,9 +3495,10 @@ class LUQueryInstances(NoHooksLU): else: assert False, "Unhandled NIC parameter" else: - assert False, "Unhandled variable parameter" + assert False, ("Declared but unhandled variable parameter '%s'" % + field) else: - raise errors.ParameterError(field) + assert False, "Declared but unhandled parameter '%s'" % field iout.append(val) output.append(iout) diff --git a/scripts/gnt-instance b/scripts/gnt-instance index def14bd7c..e7990baf6 100755 --- a/scripts/gnt-instance +++ b/scripts/gnt-instance @@ -219,6 +219,7 @@ def ListInstances(opts, args): "hvparams": "Hypervisor_parameters", "be/memory": "Configured_memory", "be/vcpus": "VCPUs", + "vcpus": "VCPUs", "be/auto_balance": "Auto_balance", "disk.count": "Disks", "disk.sizes": "Disk_sizes", "nic.count": "NICs", "nic.ips": "NIC_IPs", -- GitLab