1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-08 21:18:16 +03:00

KCC: add an option to list the graph verification options

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Douglas Bagnall 2015-03-12 10:19:51 +13:00 committed by Andrew Bartlett
parent d474bfa3c3
commit 7c39344767
2 changed files with 23 additions and 2 deletions

View File

@ -2376,6 +2376,8 @@ class KCCGraphError(Exception):
pass pass
def verify_graph_fully_connected(edges, vertices, edge_vertices): def verify_graph_fully_connected(edges, vertices, edge_vertices):
"""The graph is complete, which is to say there is an edge between
every pair of nodes."""
for v in vertices: for v in vertices:
remotes = set() remotes = set()
for a, b in edges: for a, b in edges:
@ -2388,6 +2390,7 @@ def verify_graph_fully_connected(edges, vertices, edge_vertices):
def verify_graph_connected(edges, vertices, edge_vertices): def verify_graph_connected(edges, vertices, edge_vertices):
"""There is a path between any two nodes."""
if not edges: if not edges:
if len(vertices) <= 1: if len(vertices) <= 1:
return return
@ -2418,6 +2421,8 @@ def verify_graph_connected(edges, vertices, edge_vertices):
def verify_graph_forest(edges, vertices, edge_vertices): def verify_graph_forest(edges, vertices, edge_vertices):
"""The graph contains no loops. A forest that is also connected is a
tree."""
trees = [set(e) for e in edges] trees = [set(e) for e in edges]
while True: while True:
for a, b in itertools.combinations(trees, 2): for a, b in itertools.combinations(trees, 2):
@ -2467,12 +2472,14 @@ def verify_graph_multi_edge_forest(edges, vertices, edge_vertices):
def verify_graph_no_lonely_vertices(edges, vertices, edge_vertices): def verify_graph_no_lonely_vertices(edges, vertices, edge_vertices):
"""There are no vertices without edges."""
lonely = vertices - edge_vertices lonely = vertices - edge_vertices
if lonely: if lonely:
raise KCCGraphError("some vertices are not connected:\n%s" % '\n'.join(sorted(lonely))) raise KCCGraphError("some vertices are not connected:\n%s" % '\n'.join(sorted(lonely)))
def verify_graph_no_unknown_vertices(edges, vertices, edge_vertices): def verify_graph_no_unknown_vertices(edges, vertices, edge_vertices):
"""The edge endpoints contain no vertices that are otherwise unknown."""
unknown = edge_vertices - vertices unknown = edge_vertices - vertices
if unknown: if unknown:
raise KCCGraphError("some edge vertices are seemingly unknown:\n%s" % '\n'.join(sorted(unknown))) raise KCCGraphError("some edge vertices are seemingly unknown:\n%s" % '\n'.join(sorted(unknown)))
@ -2534,3 +2541,12 @@ def verify_and_dot(basename, edges, vertices=None, label=None, destdir=None,
if dot_files: if dot_files:
write_dot_file(basename, edges, vertices=vertices, label=label, destdir=destdir, write_dot_file(basename, edges, vertices=vertices, label=label, destdir=destdir,
reformat_labels=reformat_labels, directed=directed) reformat_labels=reformat_labels, directed=directed)
def list_verify_tests():
for k, v in sorted(globals().items()):
if k.startswith('verify_graph_'):
print k.replace('verify_graph_', '')
if v.__doc__:
print ' %s%s%s' %(GREY, v.__doc__, C_NORMAL)
else:
print

View File

@ -3080,6 +3080,10 @@ parser.add_option("--verify",
help="verify that assorted invariants are kept", help="verify that assorted invariants are kept",
action="store_true") action="store_true")
parser.add_option("--list-verify-tests",
help="list what verification actions are available and do nothing else",
action="store_true")
parser.add_option("--no-dot-files", dest='dot_files', parser.add_option("--no-dot-files", dest='dot_files',
help="Don't write dot graph files in /tmp", help="Don't write dot graph files in /tmp",
default=True, action="store_false") default=True, action="store_false")
@ -3133,8 +3137,9 @@ creds = credopts.get_credentials(lp, fallback_machine=True)
opts, args = parser.parse_args() opts, args = parser.parse_args()
if opts.readonly is None: if opts.list_verify_tests:
opts.readonly = False list_verify_tests()
sys.exit(0)
if opts.debug: if opts.debug:
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)