From 1268d6fde96368aa6574afa762857932b3624f64 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 9 Feb 2009 10:31:44 +0000
Subject: [PATCH] Fix handling OS errors in AddOSToInstance

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 |  2 +-
 lib/backend.py       | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
index 08984e957..93ca0de62 100755
--- a/daemons/ganeti-noded
+++ b/daemons/ganeti-noded
@@ -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):
diff --git a/lib/backend.py b/lib/backend.py
index e7558a5cf..6b64b4261 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -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)
 
-- 
GitLab