]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
KCC: improve log legibility with colour; make more dot graphs
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 6 Mar 2015 02:28:29 +0000 (15:28 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 28 May 2015 05:25:09 +0000 (07:25 +0200)
To see the colours in less, use -R.

  bin/samba_kcc --debug  -H whatever/sam.ldb | less -R

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>
python/samba/kcc_utils.py
source4/scripting/bin/samba_kcc

index 6072fa5eedffac5b3a37d5fb9308c0772f27a927..d9b8ec882cb6140a2b69a51ca45528f22c46e991 100644 (file)
@@ -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()
index c5e0b9674a7ff2f4163387fd918c66e57565b76f..6dd6b87f38c2ec11fa975ec996fde39505a4a9c2 100755 (executable)
@@ -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)