Instance info might return an empty dictionary in case the instance
does not exist.  Fix 'IsInstanceRunning' to handle that fact.

Signed-off-by: Jose A. Lopes <[email protected]>
---
 lib/cmdlib/common.py | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/lib/cmdlib/common.py b/lib/cmdlib/common.py
index 0419953..9889a67 100644
--- a/lib/cmdlib/common.py
+++ b/lib/cmdlib/common.py
@@ -1034,18 +1034,21 @@ def IsInstanceRunning(lu, instance, 
check_user_shutdown=False):
   if instance.name not in instance_list.payload:
     return False
 
-  if check_user_shutdown:
-    # One more check to be made - whether the instance was shutdown by the user
-    full_hvparams = lu.cfg.GetClusterInfo().FillHV(instance)
-    inst_info = lu.rpc.call_instance_info(pnode_uuid, instance.name,
-                                          instance.hypervisor, full_hvparams)
-    inst_info.Raise("Can't retrieve instance information for instance %s" %
-                    instance.name, prereq=True, ecode=errors.ECODE_ENVIRON)
+  if not check_user_shutdown:
+    return True
+
+  # One more check to be made - whether the instance was shutdown by the user
+  full_hvparams = lu.cfg.GetClusterInfo().FillHV(instance)
+  inst_info = lu.rpc.call_instance_info(pnode_uuid, instance.name,
+                                        instance.hypervisor, full_hvparams)
+  inst_info.Raise("Can't retrieve instance information for instance %s" %
+                  instance.name, prereq=True, ecode=errors.ECODE_ENVIRON)
 
+  if inst_info.payload:
     return inst_info.payload["state"] != \
-           hypervisor.hv_base.HvInstanceState.SHUTDOWN
+        hypervisor.hv_base.HvInstanceState.SHUTDOWN
   else:
-    return True
+    return False
 
 
 def CheckInstanceState(lu, instance, req_states, msg=None):
-- 
1.9.1.423.g4596e3a

Reply via email to