Commit 421ab83e authored by Yuto KAWAMURA(kawamuray)'s avatar Yuto KAWAMURA(kawamuray) Committed by Klaus Aehlig

Check the return value of query in ConnectToInstanceConsole

When running gnt-instance console for an instance name that doesn't
exist, I got the following raw error:

...
    cl.QueryInstances([instance_name], ["console", "oper_state"], False)
ValueError: need more than 0 values to unpack

In this case we should raise the OpPrereqError to notify that the
instance which having that name doesn't exist.
This patch adds a check for the return value of the QueryInstances and
raise the OpPrereqError when the result of the query is a blank list.
Signed-off-by: default avatarYuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 0e83bab6
......@@ -851,14 +851,17 @@ def ConnectToInstanceConsole(opts, args):
cl = GetClient()
try:
cluster_name = cl.QueryConfigValues(["cluster_name"])[0]
((console_data, oper_state), ) = \
cl.QueryInstances([instance_name], ["console", "oper_state"], False)
idata = cl.QueryInstances([instance_name], ["console", "oper_state"], False)
if not idata:
raise errors.OpPrereqError("Instance '%s' does not exist" % instance_name,
errors.ECODE_NOENT)
finally:
# Ensure client connection is closed while external commands are run
cl.Close()
del cl
((console_data, oper_state), ) = idata
if not console_data:
if oper_state:
# Instance is running
......
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