Fix handling OS errors in AddOSToInstance
authorIustin Pop <iustin@google.com>
Mon, 9 Feb 2009 10:31:44 +0000 (10:31 +0000)
committerIustin Pop <iustin@google.com>
Mon, 9 Feb 2009 10:31:44 +0000 (10:31 +0000)
This patch fixes the error handling in the add OS to instance function
with regard to invalid OSes. Previously, we didn't handle any such
errors, with the end result that the user would have to look in the node
daemon log.

The patch also renames the name of the function to match the RPC call
name.

Reviewed-by: ultrotter

daemons/ganeti-noded
lib/backend.py

index 08984e9..93ca0de 100755 (executable)
@@ -364,7 +364,7 @@ class NodeHttpServer(http.server.HttpServer):
     """
     inst_s = params[0]
     inst = objects.Instance.FromDict(inst_s)
-    return backend.AddOSToInstance(inst)
+    return backend.InstanceOsAdd(inst)
 
   @staticmethod
   def perspective_instance_run_rename(params):
index e7558a5..6b64b42 100644 (file)
@@ -669,7 +669,7 @@ def GetAllInstancesInfo(hypervisor_list):
   return output
 
 
-def AddOSToInstance(instance):
+def InstanceOsAdd(instance):
   """Add an OS to an instance.
 
   @type instance: L{objects.Instance}
@@ -678,7 +678,15 @@ def AddOSToInstance(instance):
   @return: the success of the operation
 
   """
-  inst_os = OSFromDisk(instance.os)
+  try:
+    inst_os = OSFromDisk(instance.os)
+  except errors.InvalidOS, err:
+    os_name, os_dir, os_err = err.args
+    if os_dir is None:
+      return (False, "Can't find OS '%s': %s" % (os_name, os_err))
+    else:
+      return (False, "Error parsing OS '%s' in directory %s: %s" %
+              (os_name, os_dir, os_err))
 
   create_env = OSEnvironment(instance)