Commit b07a9f05 authored by Guido Trotter's avatar Guido Trotter
Browse files

Refactor DiagnoseOS

The new version debugs Hidden OSes as well.


Reviewed-by: iustinp
parent 0c434948
......@@ -66,6 +66,38 @@ def ListOS(opts, args):
return 0
def _DiagnoseOSValid(obj):
"""Verify whether an OS diagnose object represents a valid OS
Args:
obj: an diagnostic object as returned by OpDiagnoseOS
Returns:
bool: OS validity status
"""
if isinstance(obj, objects.OS):
return True
elif isinstance(obj, errors.InvalidOS):
return False
else:
raise errors.ProgrammerError('unknown OS diagnose type')
def _DiagnoseOSStatus(obj):
"""Generate a status message for an OS diagnose object.
Args:
obj: an diagnostic object as returned by OpDiagnoseOS
Returns:
string: a description of the OS status
"""
if _DiagnoseOSValid(obj):
return "valid (path: %s)" % obj.path
else:
return "%s (path: %s)" % (obj.args[2], obj.args[1])
def DiagnoseOS(opts, args):
"""Analyse all OSes on this cluster.
......@@ -106,18 +138,18 @@ def DiagnoseOS(opts, args):
'Details'))
for os_name in all_os:
nodes_valid = []
nodes_valid = {}
nodes_bad = {}
for node_name in node_data:
if node_name in all_os[os_name]:
nos = all_os[os_name][node_name]
if isinstance(nos[0], objects.OS):
nodes_valid.append(node_name)
elif isinstance(nos[0], errors.InvalidOS):
nodes_bad[node_name] = ("%s (path: %s)" %
(nos[0].args[2], nos[0].args[1]))
first_os = all_os[os_name][node_name].pop(0)
first_os_status = _DiagnoseOSStatus(first_os)
if _DiagnoseOSValid(first_os):
nodes_valid[node_name] = first_os_status
else:
nodes_bad[node_name] = first_os_status
else:
nodes_bad[node_name] = "os dir not found"
nodes_bad[node_name] = "OS not found"
if nodes_valid and not nodes_bad:
status = "valid"
......@@ -126,15 +158,23 @@ def DiagnoseOS(opts, args):
else:
status = "partial valid"
def _OutputNodeHiddenOSStatus(dobj_list):
for dobj in dobj_list:
logger.ToStdout(format % (max_name, "", max_node, "",
"[hidden] %s" %
_DiagnoseOSStatus(dobj)))
def _OutputPerNodeOSStatus(status_map):
map_k = utils.NiceSort(status_map.keys())
for node_name in map_k:
logger.ToStdout(format % (max_name, "", max_node,
node_name, status_map[node_name]))
if node_name in all_os[os_name]:
_OutputNodeHiddenOSStatus(all_os[os_name][node_name])
logger.ToStdout(format % (max_name, os_name, max_node, status, ""))
nodes_valid = utils.NiceSort(nodes_valid)
for node_name in nodes_valid:
logger.ToStdout(format % (max_name, "", max_node, node_name,
"valid (path: %s)" % all_os[os_name][node_name][0].path))
nbk = utils.NiceSort(nodes_bad.keys())
for node_name in nbk:
logger.ToStdout(format % (max_name, "", max_node,
node_name, nodes_bad[node_name]))
_OutputPerNodeOSStatus(nodes_valid)
_OutputPerNodeOSStatus(nodes_bad)
commands = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment