selftest: Try to tie dns_hub IP mapping to Samba.pm better
authorTim Beale <timbeale@catalyst.net.nz>
Thu, 14 Feb 2019 02:38:54 +0000 (15:38 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 5 Mar 2019 23:27:30 +0000 (23:27 +0000)
dns_hub.py maps the testenv realm to an IP and Samba.pm maps the testenv
NetBIOS name to an IP. We need to keep the two places consistent, as we
add or remove testenvs.

This patch changes dns_hub.py so that it uses a similar hashmap to
Samba.pm. We now have a hashmap with the same name in 2 different
places, so hopefully that's easier to tie them together and keep them in
sync.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
selftest/target/dns_hub.py

index e440e72577a9f5569719c24228e0d7146a6ca99b..14a58b1c31cdc8f08b2c2c15b18693e76c2fe71c 100755 (executable)
@@ -83,30 +83,35 @@ class DnsHandler(sserver.BaseRequestHandler):
             return 'torture'
         if lname.endswith('torturedom.samba.example.com'):
             return 'torture'
-        if lname.endswith('adnonssdom.samba.example.com'):
-            return '127.0.0.17'
-        if lname.endswith('adnontlmdom.samba.example.com'):
-            return '127.0.0.18'
-        if lname.endswith('samba2000.example.com'):
-            return '127.0.0.25'
-        if lname.endswith('samba2003.example.com'):
-            return '127.0.0.26'
-        if lname.endswith('samba2008r2.example.com'):
-            return '127.0.0.27'
-        if lname.endswith('addom.samba.example.com'):
-            return '127.0.0.30'
-        if lname.endswith('sub.samba.example.com'):
-            return '127.0.0.31'
-        if lname.endswith('chgdcpassword.samba.example.com'):
-            return '127.0.0.32'
-        if lname.endswith('backupdom.samba.example.com'):
-            return '127.0.0.40'
-        if lname.endswith('renamedom.samba.example.com'):
-            return '127.0.0.42'
-        if lname.endswith('labdom.samba.example.com'):
-            return '127.0.0.43'
-        if lname.endswith('samba.example.com'):
-            return '127.0.0.21'
+
+        # this maps the SOCKET_WRAPPER_DEFAULT_IFACE value (which is the
+        # last byte of the IP address) for the various testenv PDCs to the
+        # corresponding DNS realm.
+        # This should always match %testenv_iface_mapping in Samba.pm.
+        testenv_iface_mapping = {
+            'adnonssdom.samba.example.com': 17,     # addc_no_nss
+            'adnontlmdom.samba.example.com': 18,    # addc_no_ntlm
+            'samba2000.example.com': 25,            # dc5
+            'samba2003.example.com': 26,            # dc6
+            'samba2008r2.example.com': 27,          # dc7
+            'addom.samba.example.com': 30,          # addc
+            'sub.samba.example.com': 31,            # localsubdc
+            'chgdcpassword.samba.example.com': 32,  # chgdcpass
+            'backupdom.samba.example.com': 40,      # backupfromdc
+            'renamedom.samba.example.com': 42,      # renamedc
+            'labdom.samba.example.com': 43,         # labdc
+            'samba.example.com': 21,                # localdc
+        }
+
+        # sort the realms so we find the longest-match first
+        testenv_realms = sorted(testenv_iface_mapping.keys(), key=len)
+        testenv_realms.reverse()
+
+        for realm in testenv_realms:
+            if lname.endswith(realm):
+                iface = testenv_iface_mapping[realm]
+                return '127.0.0.' + str(iface)
+
         return None
 
     def handle(self):