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).
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"),
}
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)
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)
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"