wintest: fixed interface handling and DNS forwarding
[kai/samba.git] / wintest / test-s4-howto.py
index ec96581e81323a303e235a0cf06a7b8d1c694ada..70a24189d7faeef2fe571236c751bc830b481dd3 100755 (executable)
@@ -12,7 +12,7 @@ def check_prerequesites(t):
     if os.getuid() != 0:
         raise Exception("You must run this script as root")
     t.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
-    t.run_cmd('ifconfig ${INTERFACE} ${INTERFACE_IP} up')
+    t.run_cmd('ifconfig ${INTERFACE} ${INTERFACE_NET} up')
 
 
 def build_s4(t):
@@ -26,29 +26,27 @@ def build_s4(t):
     t.run_cmd('make -j install')
 
 
-def provision_s4(t, func_level="2008", interface=None):
+def provision_s4(t, func_level="2008"):
     '''provision s4 as a DC'''
     t.info('Provisioning s4')
     t.chdir('${PREFIX}')
     t.del_files(["var", "etc", "private"])
     options=' --function-level=%s -d${DEBUGLEVEL}' % func_level
-    if interface:
-        options += ' --option=interfaces=%s' % interface
-        options += ' --host-ip=%s' % interface
+    options += ' --option=interfaces=${INTERFACE}'
+    options += ' --host-ip=${INTERFACE_IP} --host-ip6="::"'
     t.run_cmd('sbin/provision --realm=${LCREALM} --domain=${DOMAIN} --adminpass=${PASSWORD1} --server-role="domain controller"' + options)
     t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
     t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
     t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
 
 
-def start_s4(t, interface=None):
+def start_s4(t):
     '''startup samba4'''
     t.info('Starting Samba4')
     t.chdir("${PREFIX}")
     t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
     t.run_cmd(['sbin/samba',
-             '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"',
-             '--option', 'interfaces=%s' % interface])
+             '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
     t.port_wait("localhost", 139)
 
 
@@ -87,6 +85,31 @@ def create_shares(t):
     t.run_cmd("mkdir -p var/profiles")
 
 
+def set_nameserver(t, nameserver):
+    '''set the nameserver in resolv.conf'''
+    if not getattr(t, 'resolv_conf_backup', False):
+        t.run_cmd("mv -f /etc/resolv.conf /etc/resolv.conf.wintest-bak")
+    t.write_file("/etc/resolv.conf", '''
+# Generated by wintest, the Samba v Windows automated testing system
+nameserver %s
+
+# your original resolv.conf appears below:
+
+''' % t.substitute(nameserver))
+    t.run_cmd('cat /etc/resolv.conf.wintest-bak >> /etc/resolv.conf')
+    t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
+
+
+def restore_resolv_conf(t):
+    '''restore the /etc/resolv.conf after testing is complete'''
+    if getattr(t, 'resolv_conf_backup', False):
+        t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
+
+def rndc_cmd(t, cmd, checkfail=True):
+    '''run a rndc command'''
+    t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf %s" % cmd, checkfail=checkfail)
+
+
 def restart_bind(t):
     '''restart the test environment version of bind'''
     t.info("Restarting bind9")
@@ -127,13 +150,29 @@ key "rndc-key" {
 };
  
 controls {
-       inet ${INTERFACE_IP}
+       inet ${INTERFACE_IP} port 953
        allow { 127.0.0.0/8; ${INTERFACE_NET}; } keys { "rndc-key"; };
 };
 
 include "${PREFIX}/private/named.conf";
 ''')
 
+    # add forwarding for the windows domains
+    domains = t.get_domains()
+    for d in domains:
+        t.write_file('etc/named.conf',
+                     '''
+zone "%s" IN {
+      type forward;
+      forward only;
+      forwarders {
+         %s;
+      };
+};
+''' % (d, domains[d]),
+                     mode='a')
+
+
     t.write_file("etc/rndc.conf", '''
 # Start of rndc.conf
 key "rndc-key" {
@@ -148,34 +187,14 @@ options {
 };
 ''')
 
-    t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf stop", checkfail=False)
+    set_nameserver(t, t.getvar('INTERFACE_IP'))
+
+    rndc_cmd(t, "stop", checkfail=False)
     t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
     t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
 
-    t.run_cmd("mv -f /etc/resolv.conf /etc/resolv.conf.wintest-bak")
-    t.write_file("/etc/resolv.conf", '''
-# Generated by wintest, the Samba v Windows automated testing system
-
-nameserver ${INTERFACE_IP}
-
-# your original resolv.conf appears below:
-
-''')
-
-    t.run_cmd('cat /etc/resolv.conf.wintest-bak >> /etc/resolv.conf')
-
-    t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
-                 
     t.port_wait("${INTERFACE_IP}", 53)
-    t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf flush")
-    t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf freeze")
-    t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf thaw")
-
-
-def restore_resolv_conf(t):
-    '''restore the /etc/resolv.conf after testing is complete'''
-    if getattr(t, 'resolv_conf_backup', False):
-        t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
+    rndc_cmd(t, "flush")
 
 
 def test_dns(t):
@@ -200,7 +219,7 @@ def test_dyndns(t):
     '''test that dynamic DNS is working'''
     t.chdir('${PREFIX}')
     t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
-    t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf flush")
+    rndc_cmd(t, "flush")
 
 
 def run_winjoin(t, vm):
@@ -210,14 +229,13 @@ def run_winjoin(t, vm):
     t.info("Joining a windows box to the domain")
     t.vm_poweroff("${WIN_VM}", checkfail=False)
     t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
-    t.ping_wait("${WIN_HOSTNAME}")
     child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
     child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
     child.expect("The command completed successfully")
     child.expect("C:")
     child.sendline("shutdown /r -t 0")
-    t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
-    t.port_wait("${WIN_HOSTNAME}", 139)
+    t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
+    t.port_wait("${WIN_IP}", 139)
     child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
     child.sendline("ipconfig /registerdns")
     child.expect("Registration of the DNS resource records for all adapters of this computer has been initiated. Any errors will be reported in the Event Viewer")
@@ -227,7 +245,7 @@ def test_winjoin(t, vm):
     t.setwinvars(vm)
     t.info("Checking the windows join is OK")
     t.chdir('${PREFIX}')
-    t.port_wait("${WIN_HOSTNAME}", 139)
+    t.port_wait("${WIN_IP}", 139)
     t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
     t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
     t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
@@ -246,7 +264,6 @@ def run_dcpromo(t, vm):
     t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
     t.vm_poweroff("${WIN_VM}", checkfail=False)
     t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
-    t.ping_wait("${WIN_HOSTNAME}")
     child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
     child.sendline("copy /Y con answers.txt")
     child.sendline('''
@@ -275,8 +292,8 @@ SafeModeAdminPassword=${PASSWORD1}
     i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
     if i == 1 or i == 2:
         raise Exception("dcpromo failed")
-    t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
-    t.port_wait("${WIN_HOSTNAME}", 139)
+    t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
+    t.port_wait("${WIN_IP}", 139)
 
 
 def test_dcpromo(t, vm):
@@ -284,7 +301,7 @@ def test_dcpromo(t, vm):
     t.setwinvars(vm)
     t.info("Checking the dcpromo join is OK")
     t.chdir('${PREFIX}')
-    t.port_wait("${WIN_HOSTNAME}", 139)
+    t.port_wait("${WIN_IP}", 139)
     t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
     t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
     t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
@@ -383,7 +400,6 @@ def run_dcpromo_rodc(t, vm):
     t.info("Joining a w2k8 box to the domain as a RODC")
     t.vm_poweroff("${WIN_VM}", checkfail=False)
     t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
-    t.ping_wait("${WIN_HOSTNAME}")
     child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
     child.sendline("copy /Y con answers.txt")
     child.sendline('''
@@ -417,8 +433,8 @@ RebootOnCompletion=No
     if i != 0:
         raise Exception("dcpromo failed")
     child.sendline("shutdown -r -t 0")
-    t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
-    t.port_wait("${WIN_HOSTNAME}", 139)
+    t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
+    t.port_wait("${WIN_IP}", 139)
 
 
 
@@ -427,7 +443,7 @@ def test_dcpromo_rodc(t, vm):
     t.setwinvars(vm)
     t.info("Checking the w2k8 RODC join is OK")
     t.chdir('${PREFIX}')
-    t.port_wait("${WIN_HOSTNAME}", 139)
+    t.port_wait("${WIN_IP}", 139)
     t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
     t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
     t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
@@ -464,11 +480,12 @@ def join_as_dc(t, vm):
     t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
     t.vm_poweroff("${WIN_VM}", checkfail=False)
     t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
-    t.run_cmd('${RNDC} -c ${PREFIX}/etc/rndc.conf flush')
+    rndc_cmd(t, 'flush')
     t.run_cmd("rm -rf etc private")
-    t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True, set_ip=True)
+    child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
+    t.get_ipconfig(child)
     t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
-    t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}')
+    t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
     t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
 
@@ -533,11 +550,12 @@ def join_as_rodc(t, vm):
     t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
     t.vm_poweroff("${WIN_VM}", checkfail=False)
     t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
-    t.run_cmd('${RNDC} -c ${PREFIX}/etc/rndc.conf flush')
+    rndc_cmd(t, 'flush')
     t.run_cmd("rm -rf etc private")
-    t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True, set_ip=True)
+    child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
+    t.get_ipconfig(child)
     t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
-    t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}')
+    t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
     t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
 
@@ -608,13 +626,13 @@ def test_howto(t):
         build_s4(t)
 
     if not t.skip("provision"):
-        provision_s4(t, interface='${INTERFACE_IP}')
+        provision_s4(t)
 
     if not t.skip("create-shares"):
         create_shares(t)
 
     if not t.skip("starts4"):
-        start_s4(t, interface='${INTERFACE_IP}')
+        start_s4(t)
     if not t.skip("smbclient"):
         test_smbclient(t)
     if not t.skip("startbind"):
@@ -652,9 +670,9 @@ def test_howto(t):
     if t.have_var('W2K3B_VM') and not t.skip("dcpromo_w2k3"):
         t.info("Testing w2k3 dcpromo")
         t.info("Changing to 2003 functional level")
-        provision_s4(t, func_level='2003', interfaces='${INTERFACES}')
+        provision_s4(t, func_level='2003')
         create_shares(t)
-        start_s4(t, interfaces='${INTERFACES}')
+        start_s4(t)
         test_smbclient(t)
         restart_bind(t)
         test_dns(t)
@@ -666,21 +684,21 @@ def test_howto(t):
     if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
         join_as_dc(t, "W2K8R2A")
         create_shares(t)
-        start_s4(t, interfaces='${INTERFACES}')
+        start_s4(t)
         test_dyndns(t)
         test_join_as_dc(t, "W2K8R2A")
 
     if t.have_var('W2K8R2A_VM') and not t.skip("join_rodc"):
         join_as_rodc(t, "W2K8R2A")
         create_shares(t)
-        start_s4(t, interfaces='${INTERFACES}')
+        start_s4(t)
         test_dyndns(t)
         test_join_as_rodc(t, "W2K8R2A")
 
     if t.have_var('W2K3A_VM') and not t.skip("join_w2k3"):
         join_as_dc(t, "W2K3A")
         create_shares(t)
-        start_s4(t, interfaces='${INTERFACES}')
+        start_s4(t)
         test_dyndns(t)
         test_join_as_dc(t, "W2K3A")