From 35fbcd118ab4bf34342212ade0fec37651035ea1 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 9 Jun 2009 12:13:02 +0200
Subject: [PATCH] Convert export_remove rpc to new style

This converts the export_remove rpc to new style result and also fixes
and old TODO by adding exception handling (and conversion to failure).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/backend.py |  9 +++++----
 lib/cmdlib.py  | 13 ++++++++-----
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index d9dce471d..b06e1f62b 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1979,11 +1979,12 @@ def RemoveExport(export):
   """
   target = os.path.join(constants.EXPORT_DIR, export)
 
-  shutil.rmtree(target)
-  # TODO: catch some of the relevant exceptions and provide a pretty
-  # error message if rmtree fails.
+  try:
+    shutil.rmtree(target)
+  except EnvironmentError, err:
+    _Fail("Error while removing the export: %s", err, exc=True)
 
-  return True
+  return True, None
 
 
 def BlockdevRename(devlist):
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index a83393bd8..28e4abfad 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -6516,15 +6516,17 @@ class LUExportInstance(LogicalUnit):
     # on one-node clusters nodelist will be empty after the removal
     # if we proceed the backup would be removed because OpQueryExports
     # substitutes an empty list with the full cluster node list.
+    iname = instance.name
     if nodelist:
       exportlist = self.rpc.call_export_list(nodelist)
       for node in exportlist:
         if exportlist[node].RemoteFailMsg():
           continue
-        if instance.name in exportlist[node].payload:
-          if not self.rpc.call_export_remove(node, instance.name):
+        if iname in exportlist[node].payload:
+          msg = self.rpc.call_export_remove(node, iname).RemoteFailMsg()
+          if msg:
             self.LogWarning("Could not remove older export for instance %s"
-                            " on node %s", instance.name, node)
+                            " on node %s: %s", iname, node, msg)
 
 
 class LURemoveExport(NoHooksLU):
@@ -6569,9 +6571,10 @@ class LURemoveExport(NoHooksLU):
       if instance_name in exportlist[node].payload:
         found = True
         result = self.rpc.call_export_remove(node, instance_name)
-        if result.failed or not result.data:
+        msg = result.RemoteFailMsg()
+        if msg:
           logging.error("Could not remove export for instance %s"
-                        " on node %s", instance_name, node)
+                        " on node %s: %s", instance_name, node, msg)
 
     if fqdn_warn and not found:
       feedback_fn("Export not found. If trying to remove an export belonging"
-- 
GitLab