selftest: Map realm to IP address (instead of iface)
authorTim Beale <timbeale@catalyst.net.nz>
Wed, 20 Feb 2019 03:34:23 +0000 (16:34 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 5 Mar 2019 23:27:31 +0000 (23:27 +0000)
The code is more readable if the hashmap translates between realm and
DC-name, rather than realm-to-iface. We already have a function to map
between DC-name and iface (and since we're doing this, we might as well
map straight to IP address).

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

index 3f8a38fc4d915290ea49e02dc549d8ff32694eed..324e1bfb90dd1f31cf43670216c2bc06bd4afc82 100644 (file)
@@ -387,30 +387,30 @@ sub mk_mitkdc_conf($$)
 
 sub realm_to_ip_mappings
 {
-       # 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 the values in get_interface()
-       my %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
+       # this maps the DNS realms for the various testenvs to the corresponding
+       # PDC (i.e. the first DC created for that realm).
+       my %realm_to_pdc_mapping = (
+               'adnonssdom.samba.example.com'    => 'addc_no_nss',
+               'adnontlmdom.samba.example.com'   => 'addc_no_ntlm',
+               'samba2000.example.com'           => 'dc5',
+               'samba2003.example.com'           => 'dc6',
+               'samba2008r2.example.com'         => 'dc7',
+               'addom.samba.example.com'         => 'addc',
+               'sub.samba.example.com'           => 'localsubdc',
+               'chgdcpassword.samba.example.com' => 'chgdcpass',
+               'backupdom.samba.example.com'     => 'backupfromdc',
+               'renamedom.samba.example.com'     => 'renamedc',
+               'labdom.samba.example.com'        => 'labdc',
+               'samba.example.com'               => 'localdc',
        );
 
        my @mapping = ();
 
-       # convert the hashmap to a list of key=value strings
-       while (my ($key, $val) = each(%testenv_iface_mapping)) {
-               push(@mapping, "$key=$val");
+       # convert the hashmap to a list of key=value strings, where key is the
+       # realm and value is the IP address
+       while (my ($realm, $pdc) = each(%realm_to_pdc_mapping)) {
+               my $ipaddr = get_ipv4_addr($pdc);
+               push(@mapping, "$realm=$ipaddr");
        }
        # return the mapping as a single comma-separated string
        return join(',', @mapping);
index b0e2a2b7b670e559775bfc8c5b175fcc2a6fcd9d..00c1ebdbfb243cfbd2d181b62e0766b8373c4f8c 100755 (executable)
@@ -80,8 +80,7 @@ class DnsHandler(sserver.BaseRequestHandler):
 
         for realm in testenv_realms:
             if lookup_name.endswith(realm):
-                iface = testenv_iface_mapping[realm]
-                return '127.0.0.' + str(iface)
+                return testenv_iface_mapping[realm]
 
         return None