From: Douglas Bagnall Date: Fri, 6 Mar 2015 02:28:29 +0000 (+1300) Subject: KCC: improve log legibility with colour; make more dot graphs X-Git-Tag: tevent-0.9.25~388 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cee3f52d7829d279c137fa493be336e5794f559c;p=thirdparty%2Fsamba.git KCC: improve log legibility with colour; make more dot graphs To see the colours in less, use -R. bin/samba_kcc --debug -H whatever/sam.ldb | less -R Signed-off-by: Douglas Bagnall Reviewed-by: Garming Sam Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/kcc_utils.py b/python/samba/kcc_utils.py index 6072fa5eedf..d9b8ec882cb 100644 --- a/python/samba/kcc_utils.py +++ b/python/samba/kcc_utils.py @@ -29,6 +29,24 @@ from samba.dcerpc import ( from samba.common import dsdb_Dn from samba.ndr import (ndr_unpack, ndr_pack) +#colours for prettier logs +C_NORMAL = "\033[00m" +DARK_RED = "\033[00;31m" +RED = "\033[01;31m" +DARK_GREEN = "\033[00;32m" +GREEN = "\033[01;32m" +YELLOW = "\033[01;33m" +DARK_YELLOW = "\033[00;33m" +DARK_BLUE = "\033[00;34m" +BLUE = "\033[01;34m" +PURPLE = "\033[00;35m" +MAGENTA = "\033[01;35m" +DARK_CYAN = "\033[00;36m" +CYAN = "\033[01;36m" +GREY = "\033[00;37m" +WHITE = "\033[01;37m" +REV_RED = "\033[01;41m" + class KCCError(Exception): pass @@ -55,7 +73,7 @@ class NamingContext(object): def __str__(self): '''Debug dump string output of class''' - text = "%s:" % self.__class__.__name__ + text = "%s%s%s:" % (CYAN, self.__class__.__name__, C_NORMAL) text = text + "\n\tnc_dnstr=%s" % self.nc_dnstr text = text + "\n\tnc_guid=%s" % str(self.nc_guid) @@ -2328,17 +2346,20 @@ def combine_repl_info(info_a, info_b, info_c): return True -def write_dot_file(basename, edge_list, label=None, destdir=None): +def write_dot_file(basename, edge_list, label=None, destdir=None, reformat_labels=True, directed=False): from tempfile import NamedTemporaryFile if label: basename += '_' + label.translate(None, ', ') #fix DN, guid labels f = NamedTemporaryFile(suffix='.dot', prefix=basename + '_', delete=False, dir=destdir) graphname = ''.join(x for x in basename if x.isalnum()) - print >>f, 'graph %s {' % graphname - print >>f, 'label="%s";\nfontsize=20' % (label or graphname) + print >>f, '%s %s {' % ('digraph' if directed else 'graph', graphname) + print >>f, 'label="%s";\nfontsize=20;' % (label or graphname) for a, b in edge_list: - print >>f, '"%s" -- "%s"' % (a, b) + if reformat_labels: + a = a.replace(',', '\\n') + b = b.replace(',', '\\n') + line = '->' if directed else '--' + print >>f, '"%s" %s "%s";' % (a, line, b) print >>f, '}' - f.close() diff --git a/source4/scripting/bin/samba_kcc b/source4/scripting/bin/samba_kcc index c5e0b9674a7..6dd6b87f38c 100755 --- a/source4/scripting/bin/samba_kcc +++ b/source4/scripting/bin/samba_kcc @@ -457,9 +457,9 @@ class KCC(object): if mydsa.is_ro() or opts.readonly: for dnstr, connect in mydsa.connect_table.items(): if connect.to_be_deleted: - logger.info("TO BE DELETED:\n%s" % connect) + DEBUG_GREEN("TO BE DELETED:\n%s" % connect) if connect.to_be_added: - logger.info("TO BE ADDED:\n%s" % connect) + DEBUG_GREEN("TO BE ADDED:\n%s" % connect) # Peform deletion from our tables but perform # no database modification @@ -1460,7 +1460,7 @@ class KCC(object): for t_guid, transport in self.transport_table.items(): if transport.name != 'IP': continue - logger.debug(t_guid) + DEBUG_RED(t_guid) # FLAG_CR_NTDS_DOMAIN 0x00000002 if (vertex.is_red() and transport.name != "IP" and vertex.part.system_flags & 0x00000002): @@ -1871,7 +1871,7 @@ class KCC(object): # partition (NC x) then continue needed, ro, partial = nc_x.should_be_present(dc_local) - logger.debug("construct_intrasite_graph(): enter" + + DEBUG_YELLOW("construct_intrasite_graph(): enter" + "\n\tgc_only=%d" % gc_only + "\n\tdetect_stale=%d" % detect_stale + "\n\tneeded=%s" % needed + @@ -1880,6 +1880,8 @@ class KCC(object): "\n%s" % nc_x) if not needed: + DEBUG_RED("%s lacks 'should be present' status, aborting construct_intersite_graph!" % + nc_x.nc_dnstr) return # Create a NCReplica that matches what the local replica @@ -2233,6 +2235,44 @@ class KCC(object): self.load_all_transports() self.load_all_sitelinks() + if True: + dot_edges = [] + for site in self.site_table.values(): + for dsa in site.dsa_table.values(): + for con in dsa.connect_table.values(): + dot_edges.append((dsa.dsa_dnstr, con.from_dnstr)) + + write_dot_file('dsa_initial', dot_edges, directed=True) + + + dot_edges = [] + for site in self.site_table.values(): + for dsa in site.dsa_table.values(): + c_rep = get_dsa_config_rep(dsa) + c_rep.load_repsFrom(self.samdb) + for x in c_rep.rep_repsFrom: + #print dir(x) + dot_edges.append((c_rep.rep_dsa_dnstr, x.nc_dnstr)) + + write_dot_file('config_repsFrom_initial', dot_edges, directed=True) + + dot_edges = [] + for site in self.site_table.values(): + for dsa in site.dsa_table.values(): + for x in dsa.current_rep_table: + dot_edges.append((dsa.dsa_dnstr, x)) + + write_dot_file('dsa_repsFrom_initial', dot_edges, directed=True) + + dot_edges = [] + for link in self.sitelink_table.values(): + for a, b in itertools.combinations(link.site_list, 2): + dot_edges.append((str(a), str(b))) + + write_dot_file('dsa_sitelink_initial', dot_edges, directed=False) + + + # These are the published steps (in order) for the # MS-TECH description of the KCC algorithm ([MS-ADTS] 6.2.2) @@ -2263,7 +2303,7 @@ class KCC(object): for con in dsa.connect_table.values(): dot_edges.append((dsa.dsa_dnstr, con.from_dnstr)) - write_dot_file('dsa_final', dot_edges) + write_dot_file('dsa_final', dot_edges, directed=True) except: raise @@ -2954,6 +2994,13 @@ logger = logging.getLogger("samba_kcc") logger.addHandler(logging.StreamHandler(sys.stdout)) DEBUG = logger.debug +def DEBUG_RED(*args): + DEBUG('%s%s%s' % (RED, args[0], C_NORMAL), *args[1:]) +def DEBUG_GREEN(*args): + DEBUG('%s%s%s' % (GREEN, args[0], C_NORMAL), *args[1:]) +def DEBUG_YELLOW(*args): + DEBUG('%s%s%s' % (YELLOW, args[0], C_NORMAL), *args[1:]) + lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True)