Improve error handling when looking up instances
authorHelga Velroyen <helgav@google.com>
Mon, 23 Mar 2015 17:16:51 +0000 (18:16 +0100)
committerHelga Velroyen <helgav@google.com>
Tue, 24 Mar 2015 11:44:23 +0000 (12:44 +0100)
When looking up configuration data of instances which don't
exist, the code so far fails with a cryptic error messages
about NoneType not having an attribute. Although actually
this situation should not happen, let's at least throw an
exception with a proper description.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>

lib/cmdlib/cluster.py
lib/config.py

index 30e35c4..6cb1401 100644 (file)
@@ -2892,7 +2892,7 @@ class LUClusterVerifyGroup(LogicalUnit, _VerifyErrors):
     if test:
       nimg.hyp_fail = True
     else:
-      nimg.instances = [inst.uuid for (_, inst) in
+      nimg.instances = [uuid for (uuid, _) in
                         self.cfg.GetMultiInstanceInfoByName(idata)]
 
   def _UpdateNodeInfo(self, ninfo, nresult, nimg, vg_name):
index b6f1373..7729cda 100644 (file)
@@ -1782,7 +1782,11 @@ class ConfigWriter(object):
     result = []
     for name in inst_names:
       instance = self._UnlockedGetInstanceInfoByName(name)
-      result.append((instance.uuid, instance))
+      if instance:
+        result.append((instance.uuid, instance))
+      else:
+        raise errors.ConfigurationError("Instance data of instance '%s'"
+                                        " not found." % name)
     return result
 
   @locking.ssynchronized(_config_lock, shared=1)