1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

kcc.graph_utils: shift debug noise out of verify()

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Douglas Bagnall 2018-03-15 12:01:10 +13:00 committed by Andrew Bartlett
parent 35ab60b82a
commit e5d092ea54
2 changed files with 24 additions and 30 deletions

View File

@ -184,10 +184,13 @@ def get_spanning_tree_edges(graph, my_site, label=None, verify=False,
vertices=graph_nodes, label=label)
if verify:
verify_graph('spanning tree edge set %s' % edgeType,
graph_edges, vertices=graph_nodes,
properties=('complete', 'connected'),
debug=DEBUG)
errors = verify_graph(graph_edges, vertices=graph_nodes,
properties=('complete', 'connected'))
if errors:
DEBUG('spanning tree edge set %s FAILED' % edgeType)
for p, e in errors:
DEBUG("%18s: %s" % (p, e))
raise KCCError("spanning tree failed")
# Run dijkstra's algorithm with just the red vertices as seeds
# Seed from the full replicas

View File

@ -274,12 +274,8 @@ def verify_graph_directed_double_ring_or_small(edges, vertices, edge_vertices):
return verify_graph_directed_double_ring(edges, vertices, edge_vertices)
def verify_graph(title, edges, vertices=None, directed=False, properties=(),
fatal=True, debug=null_debug):
def verify_graph(edges, vertices=None, directed=False, properties=()):
errors = []
debug("%sStarting verify_graph for %s%s%s" % (PURPLE, MAGENTA, title,
C_NORMAL))
properties = [x.replace(' ', '_') for x in properties]
edge_vertices = set()
@ -291,31 +287,16 @@ def verify_graph(title, edges, vertices=None, directed=False, properties=(),
vertices = edge_vertices
else:
vertices = set(vertices)
if vertices != edge_vertices:
debug("vertices in edges don't match given vertices:\n %s != %s" %
(sorted(edge_vertices), sorted(vertices)))
for p in properties:
fn = 'verify_graph_%s' % p
try:
f = globals()[fn]
except KeyError:
errors.append((p, "There is no verification check for '%s'" % p))
f = globals()[fn]
try:
f(edges, vertices, edge_vertices)
debug(" %s%18s:%s verified!" % (DARK_GREEN, p, C_NORMAL))
except GraphError as e:
errors.append((p, e))
if errors:
if fatal:
raise GraphError("The '%s' graph lacks the following properties:"
"\n%s" %
(title, '\n'.join('%s: %s' % x for x in errors)))
debug(("%s%s%s FAILED:" % (MAGENTA, title, RED)))
for p, e in errors:
debug(" %18s: %s%s%s" % (p, DARK_YELLOW, e, RED))
debug(C_NORMAL)
return errors
def verify_and_dot(basename, edges, vertices=None, label=None,
@ -325,10 +306,6 @@ def verify_and_dot(basename, edges, vertices=None, label=None,
edge_colors=None, edge_labels=None,
vertex_colors=None):
title = '%s %s' % (basename, label or '')
if verify:
verify_graph(title, edges, vertices, properties=properties,
fatal=fatal, debug=debug)
if dot_file_dir is not None:
write_dot_file(basename, edges, vertices=vertices, label=label,
dot_file_dir=dot_file_dir,
@ -336,6 +313,20 @@ def verify_and_dot(basename, edges, vertices=None, label=None,
debug=debug, edge_colors=edge_colors,
edge_labels=edge_labels, vertex_colors=vertex_colors)
if verify:
errors = verify_graph(edges, vertices,
properties=properties)
if errors:
title = '%s %s' % (basename, label or '')
debug(("%s%s%s FAILED:" % (MAGENTA, title, RED)))
for p, e in errors:
debug(" %18s: %s%s%s" % (p, DARK_YELLOW, e, RED))
if fatal:
raise GraphError("The '%s' graph lacks the following "
"properties:\n%s" %
(title, '\n'.join('%s: %s' % x
for x in errors)))
def list_verify_tests():
for k, v in sorted(globals().items()):