samba-tool visualize: use correct DC in graph label
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 19 Apr 2018 22:52:31 +0000 (10:52 +1200)
committerNoel Power <npower@samba.org>
Mon, 30 Apr 2018 13:43:18 +0000 (15:43 +0200)
We have been using a random DC (depending to hash order, which was not
random enough on Python 2.7 to affect the tests).

Reported-by: Noel Power <noel.power@suse.com>
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Noel Power <noel.power@suse.com>
python/samba/netcmd/visualize.py
python/samba/tests/samba_tool/visualize.py

index b983e1891a94d621ab9b269450df67595ee8c5b5..6f880ae61e82beb39654ddb30596d65d225be34d 100644 (file)
@@ -392,7 +392,7 @@ class cmd_ntdsconn(GraphCommand):
         lp = sambaopts.get_loadparm()
         creds = credopts.get_credentials(lp, fallback_machine=True)
         local_kcc, dsas = self.get_kcc_and_dsas(H, lp, creds)
         lp = sambaopts.get_loadparm()
         creds = credopts.get_credentials(lp, fallback_machine=True)
         local_kcc, dsas = self.get_kcc_and_dsas(H, lp, creds)
-
+        local_dsa_dn = local_kcc.my_dsa_dnstr.split(',', 1)[1]
         vertices = set()
         attested_edges = []
         for dsa_dn in dsas:
         vertices = set()
         attested_edges = []
         for dsa_dn in dsas:
@@ -452,7 +452,7 @@ class cmd_ntdsconn(GraphCommand):
                 # If we are not talking to remote servers, we list all
                 # the connections.
                 graph_edges = edges.keys()
                 # If we are not talking to remote servers, we list all
                 # the connections.
                 graph_edges = edges.keys()
-                title = 'NTDS Connections known to %s' % dsa_dn
+                title = 'NTDS Connections known to %s' % local_dsa_dn
                 epilog = ''
 
             else:
                 epilog = ''
 
             else:
@@ -556,7 +556,7 @@ class cmd_ntdsconn(GraphCommand):
         if talk_to_remote:
             title = 'NTDS Connections'
         else:
         if talk_to_remote:
             title = 'NTDS Connections'
         else:
-            title = 'NTDS Connections known to %s' % dsa_dn
+            title = 'NTDS Connections known to %s' % local_dsa_dn
 
         s = dot_graph(sorted(vertices), dot_edges,
                       directed=True,
 
         s = dot_graph(sorted(vertices), dot_edges,
                       directed=True,
index c00c6ea63b08943daf6a44592a537b118643ce3b..a90c77364b727db11deaefcc37ffb568b33ea0c2 100644 (file)
@@ -205,12 +205,14 @@ class SambaToolVisualizeLdif(SambaToolCmdTest):
             self.assertTrue(c not in ascii, 'ASCII should not contain %s' % c)
 
     def test_forced_local_dsa(self):
             self.assertTrue(c not in ascii, 'ASCII should not contain %s' % c)
 
     def test_forced_local_dsa(self):
-        # the forced_local_dsa shouldn't make any difference
+        # the forced_local_dsa shouldn't make any difference, except
+        # for the title line.
         result, target, err = self.runsubcmd("visualize", "ntdsconn",
                                              '-H', self.dburl,
                                              '--color=no', '-S')
         self.assertCmdSuccess(result, target, err)
         files = []
         result, target, err = self.runsubcmd("visualize", "ntdsconn",
                                              '-H', self.dburl,
                                              '--color=no', '-S')
         self.assertCmdSuccess(result, target, err)
         files = []
+        target = target.strip().split('\n', 1)[1]
         for cn, site in MULTISITE_LDIF_DSAS:
             dsa = DN_TEMPLATE % (cn, site)
             samdb, dbfile = samdb_from_ldif(MULTISITE_LDIF,
         for cn, site in MULTISITE_LDIF_DSAS:
             dsa = DN_TEMPLATE % (cn, site)
             samdb, dbfile = samdb_from_ldif(MULTISITE_LDIF,
@@ -222,7 +224,10 @@ class SambaToolVisualizeLdif(SambaToolCmdTest):
                                               '-H', 'tdb://' + dbfile,
                                               '--color=no', '-S')
             self.assertCmdSuccess(result, out, err)
                                               '-H', 'tdb://' + dbfile,
                                               '--color=no', '-S')
             self.assertCmdSuccess(result, out, err)
-            self.assertStringsEqual(target, out)
+            # Separate out the title line, which will differ in the DN.
+            title, body = out.strip().split('\n', 1)
+            self.assertStringsEqual(target, body)
+            self.assertIn(cn, title)
             files.append(dbfile)
         self.remove_files(*files)
 
             files.append(dbfile)
         self.remove_files(*files)
 
@@ -342,7 +347,7 @@ class SambaToolVisualizeLdif(SambaToolCmdTest):
 
 EXPECTED_DOT_MULTISITE_NO_KEY = r"""/* generated by samba */
 digraph A_samba_tool_production {
 
 EXPECTED_DOT_MULTISITE_NO_KEY = r"""/* generated by samba */
 digraph A_samba_tool_production {
-label="NTDS Connections known to CN=WIN07,CN=Servers,CN=Site-4,CN=Sites,CN=Configuration,DC=ad,DC=samba,DC=example,DC=com";
+label="NTDS Connections known to CN=WIN01,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=ad,DC=samba,DC=example,DC=com";
 fontsize=10;
 
 node[fontname=Helvetica; fontsize=10];
 fontsize=10;
 
 node[fontname=Helvetica; fontsize=10];
@@ -382,7 +387,7 @@ node[fontname=Helvetica; fontsize=10];
 
 EXPECTED_DOT_NTDSCONN_DISCONNECTED = r"""/* generated by samba */
 digraph A_samba_tool_production {
 
 EXPECTED_DOT_NTDSCONN_DISCONNECTED = r"""/* generated by samba */
 digraph A_samba_tool_production {
-label="NTDS Connections known to CN=SERVER2,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com";
+label="NTDS Connections known to CN=LOCALDC,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com";
 fontsize=10;
 
 node[fontname=Helvetica; fontsize=10];
 fontsize=10;
 
 node[fontname=Helvetica; fontsize=10];
@@ -435,7 +440,7 @@ key_0__label -> elision0 [style=invis; weight=9]
 """
 
 EXPECTED_DISTANCE_GRAPH_WITH_KEY = """
 """
 
 EXPECTED_DISTANCE_GRAPH_WITH_KEY = """
-NTDS Connections known to CN=SERVER2,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com
+NTDS Connections known to CN=LOCALDC,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com
                             destination
                   ,-------- *,CN=CLIENT+
                   |,------- *,CN=LOCALDC+
                             destination
                   ,-------- *,CN=CLIENT+
                   |,------- *,CN=LOCALDC+