From 78758f1e07799f5c4c527e780a863c2471e641c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com> Date: Thu, 16 Dec 2010 14:55:59 +0100 Subject: [PATCH] LUSetNodeParams/LUOobCommand respect offline/powered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch makes sure we cross verify the state the node is in with our view: power off -> Node has to be set offline modify -O no -> Node has to be powered Signed-off-by: RenΓ© Nussbaumer <rn@google.com> Reviewed-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/cmdlib.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 37bdda47c..774c236bc 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -94,6 +94,19 @@ _PMigrationMode = ("mode", None, _PMigrationLive = ("live", None, ht.TMaybeBool) +def _SupportsOob(cfg, node): + """Tells if node supports OOB. + + @type cfg: L{config.ConfigWriter} + @param cfg: The cluster configuration + @type node: L{objects.Node} + @param node: The node + @return: The OOB script if supported or an empty string otherwise + + """ + return cfg.GetNdParams(node)[constants.ND_OOB_PROGRAM] + + # End types class LogicalUnit(object): """Logical Unit base class. @@ -3271,12 +3284,16 @@ class LUOobCommand(NoHooksLU): if node is None: raise errors.OpPrereqError("Node %s not found" % self.op.node_name) - self.oob_program = self.cfg.GetNdParams(node)[constants.ND_OOB_PROGRAM] + self.oob_program = _SupportsOob(self.cfg, node) if not self.oob_program: raise errors.OpPrereqError("OOB is not supported for node %s" % self.op.node_name) + if self.op.command == constants.OOB_POWER_OFF and not node.offline: + raise errors.OpPrereqError(("Cannot power off node %s because it is" + " not marked offline") % self.op.node_name) + self.node = node def ExpandNames(self): @@ -4485,6 +4502,13 @@ class LUSetNodeParams(LogicalUnit): # Past this point, any flag change to False means a transition # away from the respective state, as only real changes are kept + # TODO: We might query the real power state if it supports OOB + if _SupportsOob(self.cfg, node) and (self.op.offline is False and + not node.powered): + raise errors.OpPrereqError(("Please power on node %s first before you" + " can reset offline state") % + self.op.node_name) + # If we're being deofflined/drained, we'll MC ourself if needed if (self.op.drained == False or self.op.offline == False or (self.op.master_capable and not node.master_capable)): -- GitLab