Adding gnt-node health
authorRené Nussbaumer <rn@google.com>
Thu, 20 Jan 2011 09:56:54 +0000 (10:56 +0100)
committerRené Nussbaumer <rn@google.com>
Mon, 31 Jan 2011 15:45:25 +0000 (16:45 +0100)
Signed-off-by: René Nussbaumer <rn@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/client/gnt_node.py
man/gnt-node.rst
qa/qa_node.py

index 7e818db..6186295 100644 (file)
@@ -523,6 +523,51 @@ def PowerNode(opts, args):
   return constants.EXIT_SUCCESS
 
 
+def Health(opts, args):
+  """Show health of a node using OOB.
+
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: should contain only one element, the name of
+      the node to be removed
+  @rtype: int
+  @return: the desired exit code
+
+  """
+  op = opcodes.OpOobCommand(node_names=args, command=constants.OOB_HEALTH)
+  result = SubmitOpCode(op, opts=opts)
+
+  if opts.no_headers:
+    headers = None
+  else:
+    headers = {"node": "Node", "status": "Status"}
+
+  errs = 0
+  data = []
+  for node_result in result:
+    (node_tuple, data_tuple) = node_result
+    (_, node_name) = node_tuple
+    (data_status, data_node) = data_tuple
+    if data_status == constants.RS_NORMAL:
+      data.append([node_name, "%s=%s" % tuple(data_node[0])])
+      for item, status in data_node[1:]:
+        data.append(["", "%s=%s" % (item, status)])
+    else:
+      errs += 1
+      data.append([node_name, cli.FormatResultError(data_status)])
+
+  data = GenerateTable(separator=opts.separator, headers=headers,
+                       fields=["node", "status"], data=data)
+
+  for line in data:
+    ToStdout(line)
+
+  if errs:
+    return constants.EXIT_FAILURE
+  else:
+    return constants.EXIT_SUCCESS
+
+
 def ListVolumes(opts, args):
   """List logical volumes on node(s).
 
@@ -812,6 +857,10 @@ commands = {
     RemoveTags, [ArgNode(min=1, max=1), ArgUnknown()],
     [TAG_SRC_OPT, PRIORITY_OPT],
     "<node_name> tag...", "Remove tags from the given node"),
+  "health": (
+    Health, ARGS_MANY_NODES,
+    [NOHDR_OPT, SEP_OPT, SUBMIT_OPT, PRIORITY_OPT],
+    "[<node_name>...]", "List health of node(s) using out-of-band"),
   }
 
 
index 01b4e72..06ec955 100644 (file)
@@ -606,3 +606,15 @@ POWER
 This commands calls out to out-of-band management to change the power
 state of given node. With ``status`` you get the power status as reported
 by the out-of-band managment script.
+
+HEALTH
+~~~~~~
+
+**health** [*nodes*]
+
+This commands calls out to out-pf-band management to ask for the health status
+of all or given nodes. The health contains the node name and then the items
+element with their status in a ``item=status`` manner. Where ``item`` is script
+specific and ``status`` can be one of ``OK``, ``WARNING``, ``CRITICAL`` or
+``UNKNOWN``. Items with status ``WARNING`` or ``CRITICAL`` are logged and
+annotated in the command line output.
index cffa969..30e5853 100644 (file)
@@ -280,18 +280,34 @@ def TestOutOfBand():
     AssertCommand(["gnt-node", "power", "cycle", node_name])
     _AssertOobCall(verify_path, "power-cycle %s" % full_node_name)
 
-    # This command should fail as it expects output which isn't provided yet
-    # But it should have called the oob helper nevermind
+    # Those commands should fail as they expect output which isn't provided yet
+    # But they should have called the oob helper nevermind
     AssertCommand(["gnt-node", "power", "status", node_name],
                   fail=True)
     _AssertOobCall(verify_path, "power-status %s" % full_node_name)
 
-    # Data, exit 0
+    AssertCommand(["gnt-node", "health", node_name],
+                  fail=True)
+    _AssertOobCall(verify_path, "health %s" % full_node_name)
+
+    AssertCommand(["gnt-node", "health"], fail=True)
+
+    # Correct Data, exit 0
     _UpdateOobFile(data_path, serializer.DumpJson({ "powered": True }))
 
     AssertCommand(["gnt-node", "power", "status", node_name])
     _AssertOobCall(verify_path, "power-status %s" % full_node_name)
 
+    _UpdateOobFile(data_path, serializer.DumpJson([["temp", "OK"],
+                                                   ["disk0", "CRITICAL"]]))
+
+    AssertCommand(["gnt-node", "health", node_name])
+    _AssertOobCall(verify_path, "health %s" % full_node_name)
+
+    AssertCommand(["gnt-node", "health"])
+
+
+    # Those commands should fail as they expect no data regardless of exit 0
     AssertCommand(["gnt-node", "power", "on", node_name], fail=True)
     _AssertOobCall(verify_path, "power-on %s" % full_node_name)
 
@@ -323,6 +339,12 @@ def TestOutOfBand():
                   fail=True)
     _AssertOobCall(verify_path, "power-status %s" % full_node_name)
 
+    AssertCommand(["gnt-node", "health", node_name],
+                  fail=True)
+    _AssertOobCall(verify_path, "health %s" % full_node_name)
+
+    AssertCommand(["gnt-node", "health"], fail=True)
+
     # No data, exit 1 (all should fail)
     _UpdateOobFile(data_path, "")
     AssertCommand(["gnt-node", "power", "on", node_name], fail=True)
@@ -341,6 +363,12 @@ def TestOutOfBand():
                   fail=True)
     _AssertOobCall(verify_path, "power-status %s" % full_node_name)
 
+    AssertCommand(["gnt-node", "health", node_name],
+                  fail=True)
+    _AssertOobCall(verify_path, "health %s" % full_node_name)
+
+    AssertCommand(["gnt-node", "health"], fail=True)
+
     # Different OOB script for node
     verify_path2 = qa_utils.UploadData(master["primary"], "")
     oob_script = ("#!/bin/sh\n"