node-remove post on removed node
authorLuca Bigliardi <shammash@google.com>
Mon, 24 Aug 2009 16:48:43 +0000 (17:48 +0100)
committerLuca Bigliardi <shammash@google.com>
Tue, 25 Aug 2009 11:40:38 +0000 (12:40 +0100)
Run post phase of node-remove on the removed node as well.

Signed-off-by: Luca Bigliardi <shammash@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

doc/hooks.rst
lib/cmdlib.py
lib/mcpu.py

index ecd6c9e..829ee33 100644 (file)
@@ -128,12 +128,13 @@ Adds a node to the cluster.
 OP_REMOVE_NODE
 ++++++++++++++
 
-Removes a node from the cluster.
+Removes a node from the cluster. On the removed node the hooks are called
+during the execution of the operation and not after its completion.
 
 :directory: node-remove
 :env. vars: NODE_NAME
 :pre-execution: all existing nodes except the removed node
-:post-execution: all existing nodes except the removed node
+:post-execution: all existing nodes
 
 OP_NODE_SET_PARAMS
 ++++++++++++++++++
index 02a5128..9ba3dcc 100644 (file)
@@ -2155,7 +2155,8 @@ class LURemoveNode(LogicalUnit):
       "NODE_NAME": self.op.node_name,
       }
     all_nodes = self.cfg.GetNodeList()
-    all_nodes.remove(self.op.node_name)
+    if self.op.node_name in all_nodes:
+      all_nodes.remove(self.op.node_name)
     return env, all_nodes, all_nodes
 
   def CheckPrereq(self):
@@ -2198,6 +2199,26 @@ class LURemoveNode(LogicalUnit):
 
     self.context.RemoveNode(node.name)
 
+    # Run post hooks on the node before it's removed
+    hm = self.proc.hmclass(self.rpc.call_hooks_runner, self)
+    try:
+      h_results = hm.RunPhase(constants.HOOKS_PHASE_POST, [node.name])
+    finally:
+      res = h_results[node.name]
+      if res.fail_msg:
+        if not res.offline:
+          self.LogError("Failed to start hooks on %s: %s" %
+                        (node.name, res.fail_msg))
+      for script, hkr, output in res.payload:
+        if hkr != constants.HKR_FAIL:
+         continue
+        if output:
+          self.LogWarning("On %s script %s failed, output:  %s" %
+                          (node.name, script, output))
+        else:
+         self.LogWarning("On %s script %s failed (no output)." %
+                          (node.name, script))
+
     result = self.rpc.call_node_leave_cluster(node.name)
     msg = result.fail_msg
     if msg:
index 5ee50fa..5cd3566 100644 (file)
@@ -111,6 +111,7 @@ class Processor(object):
     self._feedback_fn = None
     self.exclusive_BGL = False
     self.rpc = rpc.RpcRunner(context.cfg)
+    self.hmclass = HooksMaster
 
   def _ExecLU(self, lu):
     """Logical Unit execution sequence.