Typos in wintest
[kai/samba.git] / wintest / test-s4-howto.py
index 6afea1a89bb28a0344aa3e26aacedde341a64a70..cb9862b8b92bc303a8224a9715035c6a37d4daf0 100755 (executable)
@@ -3,18 +3,10 @@
 '''automated testing of the steps of the Samba4 HOWTO'''
 
 import sys, os
-import optparse
-import wintest
-
-vars = {}
-
-def check_prerequesites(t):
-    t.info("Checking prerequesites")
-    t.setvar('HOSTNAME', t.cmd_output("hostname -s").strip())
-    if os.getuid() != 0:
-        raise Exception("You must run this script as root")
-    t.cmd_contains("grep 127.0.0.1 /etc/resolv.conf", ["nameserver 127.0.0.1"])
+import wintest, pexpect, time, subprocess
 
+def set_krb5_conf(t):
+    t.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
 
 def build_s4(t):
     '''build samba4'''
@@ -26,35 +18,48 @@ def build_s4(t):
     t.run_cmd('rm -rf ${PREFIX}')
     t.run_cmd('make -j install')
 
-def provision_s4(t, func_level="2008", interfaces=None):
+
+def provision_s4(t, func_level="2008"):
     '''provision s4 as a DC'''
     t.info('Provisioning s4')
     t.chdir('${PREFIX}')
-    t.run_cmd("rm -rf etc private")
-    t.run_cmd("find var -type f | xargs rm -f")
-    options=' --function-level=%s -d${DEBUGLEVEL}' % func_level
-    if interfaces:
-        options += ' --option=interfaces=%s' % interfaces
-    t.run_cmd('sbin/provision --realm=${LCREALM} --domain=${DOMAIN} --adminpass=${PASSWORD1} --server-role="domain controller"' + options)
+    t.del_files(["var", "private"])
+    t.run_cmd("rm -f etc/smb.conf")
+    provision=['sbin/provision',
+               '--realm=${LCREALM}',
+               '--domain=${DOMAIN}',
+               '--adminpass=${PASSWORD1}',
+               '--server-role=domain controller',
+               '--function-level=%s' % func_level,
+               '-d${DEBUGLEVEL}',
+               '--option=interfaces=${INTERFACE}',
+               '--host-ip=${INTERFACE_IP}',
+               '--option=bind interfaces only=yes',
+               '--option=rndc command=${RNDC} -c${PREFIX}/etc/rndc.conf']
+    if t.getvar('INTERFACE_IPV6'):
+        provision.append('--host-ip6=${INTERFACE_IPV6}')
+    t.run_cmd(provision)
     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, interfaces=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' % interfaces])
-    t.port_wait("localhost", 139)
+             '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
+    t.port_wait("${INTERFACE_IP}", 139)
 
 def test_smbclient(t):
+    '''test smbclient against localhost'''
     t.info('Testing smbclient')
     t.chdir('${PREFIX}')
     t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
-    t.retry_cmd('bin/smbclient -L localhost -U%', ["netlogon", "sysvol", "IPC Service"])
-    child = t.pexpect_spawn('bin/smbclient //localhost/netlogon -Uadministrator%${PASSWORD1}')
+    t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
+    child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
     child.expect("smb:")
     child.sendline("dir")
     child.expect("blocks available")
@@ -65,36 +70,26 @@ def test_smbclient(t):
     child.sendline("cd ..")
     child.sendline("rmdir testdir")
 
+
 def create_shares(t):
+    '''create some test shares'''
     t.info("Adding test shares")
     t.chdir('${PREFIX}')
-    f = open("etc/smb.conf", mode='a')
-    f.write(t.substitute('''
+    t.write_file("etc/smb.conf", '''
 [test]
        path = ${PREFIX}/test
        read only = no
 [profiles]
        path = ${PREFIX}/var/profiles
        read only = no
-    '''))
-    f.close()
+    ''',
+                 mode='a')
     t.run_cmd("mkdir -p test")
     t.run_cmd("mkdir -p var/profiles")
 
 
-def restart_bind(t):
-    t.info("Restarting bind9")
-    t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
-    t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
-    t.run_cmd('killall -9 -q named', checkfail=False)
-    t.port_wait("localhost", 53, wait_for_fail=True)
-    t.run_cmd("${BIND9}")
-    t.port_wait("localhost", 53)
-    t.run_cmd("${RNDC} flush")
-    t.run_cmd("${RNDC} freeze")
-    t.run_cmd("${RNDC} thaw")
-
 def test_dns(t):
+    '''test that DNS is OK'''
     t.info("Testing DNS")
     t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
                  ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
@@ -104,39 +99,32 @@ def test_dns(t):
                  ['${HOSTNAME}.${LCREALM} has address'])
 
 def test_kerberos(t):
+    '''test that kerberos is OK'''
     t.info("Testing kerberos")
     t.run_cmd("kdestroy")
     t.kinit("administrator@${REALM}", "${PASSWORD1}")
-    t.cmd_contains("klist -e", ["Ticket cache", "Default principal", "Valid starting"])
+    # this copes with the differences between MIT and Heimdal klist
+    t.cmd_contains("klist", ["rincipal", "administrator@${REALM}"])
 
 
 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} flush")
+    t.rndc_cmd("flush")
 
 
 def run_winjoin(t, vm):
+    '''join a windows box to our domain'''
     t.setwinvars(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)
-    child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
-    child.expect("The command completed successfully")
-    child.sendline("shutdown /r -t 0")
-    t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
-    t.port_wait("${WIN_HOSTNAME}", 139)
-
+    t.run_winjoin(t, "${LCREALM}")
 
 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.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
+    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"])
     t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
@@ -144,7 +132,6 @@ def test_winjoin(t, vm):
     child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
     child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
     child.expect("The command completed successfully")
-    t.vm_poweroff("${WIN_VM}")
 
 
 def run_dcpromo(t, vm):
@@ -152,10 +139,7 @@ def run_dcpromo(t, vm):
     t.setwinvars(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}")
+    child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True, set_noexpire=True)
     child.sendline("copy /Y con answers.txt")
     child.sendline('''
 [DCINSTALL]
@@ -180,31 +164,37 @@ SafeModeAdminPassword=${PASSWORD1}
     child.expect("C:")
     child.expect("C:")
     child.sendline("dcpromo /answer:answers.txt")
-    i = child.expect(["You must restart this computer", "failed", "C:"], timeout=120)
-    if i == 1:
+    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.wait_reboot()
 
 
 def test_dcpromo(t, vm):
-    t.setwinvars(vm)
+    '''test that dcpromo worked'''
     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("host -t A ${WIN_HOSTNAME}.${LCREALM}. ${INTERFACE_IP}",
+                ['${WIN_HOSTNAME}.${LCREALM} has address'],
+                retries=30, delay=10, casefold=True)
     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"])
 
-    t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
-    t.cmd_contains("bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
+    t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
+    t.retry_cmd("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
 
     t.kinit("administrator@${REALM}", "${PASSWORD1}")
+
+    # the first replication will transfer the dnsHostname attribute
+    t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME} CN=Configuration,${BASEDN} -k yes", ["was successful"])
+
     for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
-        t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME} %s -k yes" % nc, ["was successful"])
-        t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
+        t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
+        t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
 
-    t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME} -k yes",
+    t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
                  [ "INBOUND NEIGHBORS",
                    "${BASEDN}",
                    "Last attempt .* was successful",
@@ -222,7 +212,7 @@ def test_dcpromo(t, vm):
                    ordered=True,
                    regex=True)
 
-    t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -k yes",
+    t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
                  [ "INBOUND NEIGHBORS",
                    "${BASEDN}",
                    "Last attempt .* was successful",
@@ -242,7 +232,15 @@ def test_dcpromo(t, vm):
 
     child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
     child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
-    child.expect("The command completed successfully")
+
+    retries = 10
+    i = child.expect(["The command completed successfully", "The network path was not found"])
+    while i == 1 and retries > 0:
+        child.expect("C:")
+        time.sleep(2)
+        child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
+        i = child.expect(["The command completed successfully", "The network path was not found"])
+        retries -=1
 
     t.run_net_time(child)
 
@@ -256,9 +254,9 @@ def test_dcpromo(t, vm):
     child.expect("was successful")
 
     t.info("Checking if new users propogate to windows")
-    t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
+    t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
 
     t.info("Checking if new users on windows propogate to samba")
     child.sendline("net user test3 ${PASSWORD3} /add")
@@ -269,28 +267,28 @@ def test_dcpromo(t, vm):
             break
         time.sleep(2)
 
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
 
     t.info("Checking propogation of user deletion")
     t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
     child.sendline("net user test3 /del")
     child.expect("The command completed successfully")
 
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
     t.vm_poweroff("${WIN_VM}")
 
 
 def run_dcpromo_rodc(t, vm):
+    '''run a RODC dcpromo to join a windows DC to the samba domain'''
     t.setwinvars(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}")
+    child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
     child.sendline("copy /Y con answers.txt")
     child.sendline('''
 [DCInstall]
@@ -323,20 +321,20 @@ 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.wait_reboot()
 
 
 
 def test_dcpromo_rodc(t, vm):
-    t.setwinvars(vm)
+    '''test the RODC dcpromo worked'''
     t.info("Checking the w2k8 RODC join is OK")
     t.chdir('${PREFIX}')
-    t.port_wait("${WIN_HOSTNAME}", 139)
+    t.port_wait("${WIN_IP}", 139)
+    child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
+    child.sendline("ipconfig /registerdns")
     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"])
-    child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
     child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
     child.expect("The command completed successfully")
 
@@ -349,32 +347,56 @@ def test_dcpromo_rodc(t, vm):
     child.expect("CN=Configuration,${BASEDN}")
     child.expect("was successful")
 
+    for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
+        t.cmd_contains("bin/samba-tool drs replicate --add-ref ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s" % nc, ["was successful"])
+
+    t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM}",
+                 [ "INBOUND NEIGHBORS",
+                   "OUTBOUND NEIGHBORS",
+                   "${BASEDN}",
+                   "Last attempt.*was successful",
+                   "CN=Configuration,${BASEDN}",
+                   "Last attempt.*was successful",
+                   "CN=Configuration,${BASEDN}",
+                   "Last attempt.*was successful" ],
+                   ordered=True,
+                   regex=True)
+
     t.info("Checking if new users are available on windows")
     t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
+    t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN}", ["was successful"])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
     t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2}", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
     t.vm_poweroff("${WIN_VM}")
 
 
+def prep_join_as_dc(t, vm):
+    '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
+    t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
+    t.chdir('${PREFIX}')
+    t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
+    t.rndc_cmd('flush')
+    t.run_cmd("rm -rf etc/smb.conf private")
+    child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
+    t.get_ipconfig(child)
+
 def join_as_dc(t, vm):
+    '''join a windows domain as a DC'''
     t.setwinvars(vm)
     t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
-    t.chdir('${PREFIX}')
-    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} flush')
-    t.run_cmd("rm -rf etc private")
-    t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
-    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 drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
+    t.port_wait("${WIN_IP}", 389)
+    t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
+
+    t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
+    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}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
 
 def test_join_as_dc(t, vm):
-    t.setwinvars(vm)
+    '''test the join of a windows domain as a DC'''
     t.info("Checking the DC join is OK")
     t.chdir('${PREFIX}')
     t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
@@ -382,16 +404,23 @@ def test_join_as_dc(t, vm):
     child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
 
     t.info("Forcing kcc runs, and replication")
-    t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
-    t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
+    t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
+    t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
     t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
     for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
-        t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME} %s -k yes" % nc, ["was successful"])
-        t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
-
-    child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
-    child.expect("The command completed successfully")
+        t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
+        t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
+
+    retries = 10
+    i = 1
+    while i == 1 and retries > 0:
+        child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
+        i = child.expect(["The command completed successfully", "The network path was not found"])
+        child.expect("C:")
+        if i == 1:
+            time.sleep(2)
+        retries -=1
 
     t.info("Checking if showrepl is happy")
     child.sendline("repadmin /showrepl")
@@ -403,45 +432,41 @@ def test_join_as_dc(t, vm):
     child.expect("was successful")
 
     t.info("Checking if new users propogate to windows")
-    t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
+    t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
 
     t.info("Checking if new users on windows propogate to samba")
     child.sendline("net user test3 ${PASSWORD3} /add")
     child.expect("The command completed successfully")
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
 
     t.info("Checking propogation of user deletion")
     t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
     child.sendline("net user test3 /del")
     child.expect("The command completed successfully")
 
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
     t.vm_poweroff("${WIN_VM}")
 
 
 def join_as_rodc(t, vm):
+    '''join a windows domain as a RODC'''
     t.setwinvars(vm)
     t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
-    t.chdir('${PREFIX}')
-    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} flush')
-    t.run_cmd("rm -rf etc private")
-    t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
-    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 drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
+    t.port_wait("${WIN_IP}", 389)
+    t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
+    t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
+    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}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
 
 def test_join_as_rodc(t, vm):
-    t.setwinvars(vm)
+    '''test a windows domain RODC join'''
     t.info("Checking the RODC join is OK")
     t.chdir('${PREFIX}')
     t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
@@ -449,15 +474,22 @@ def test_join_as_rodc(t, vm):
     child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
 
     t.info("Forcing kcc runs, and replication")
-    t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
-    t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
+    t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
+    t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
     t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
     for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
-        t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME} %s -k yes" % nc, ["was successful"])
-
-    child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
-    child.expect("The command completed successfully")
+        t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
+
+    retries = 10
+    i = 1
+    while i == 1 and retries > 0:
+        child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
+        i = child.expect(["The command completed successfully", "The network path was not found"])
+        child.expect("C:")
+        if i == 1:
+            time.sleep(2)
+        retries -=1
 
     t.info("Checking if showrepl is happy")
     child.sendline("repadmin /showrepl")
@@ -478,8 +510,8 @@ def test_join_as_rodc(t, vm):
     t.info("Checking if new users on windows propogate to samba")
     child.sendline("net user test3 ${PASSWORD3} /add")
     child.expect("The command completed successfully")
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
 
     # should this work?
     t.info("Checking if new users propogate to windows")
@@ -489,34 +521,46 @@ def test_join_as_rodc(t, vm):
     child.sendline("net user test3 /del")
     child.expect("The command completed successfully")
 
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
-    t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
+    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
     t.vm_poweroff("${WIN_VM}")
 
 
 def test_howto(t):
     '''test the Samba4 howto'''
 
-    check_prerequesites(t)
+    t.setvar("SAMBA_VERSION", "Version 4")
+    t.check_prerequesites()
 
     # we don't need fsync safety in these tests
     t.putenv('TDB_NO_FSYNC', '1')
 
+    if not t.skip("configure_bind"):
+        t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
+    if not t.skip("stop_bind"):
+        t.stop_bind()
+    if not t.skip("stop_vms"):
+        t.stop_vms()
+
     if not t.skip("build"):
         build_s4(t)
 
     if not t.skip("provision"):
         provision_s4(t)
 
+    set_krb5_conf(t)
+
     if not t.skip("create-shares"):
         create_shares(t)
 
     if not t.skip("starts4"):
-        start_s4(t, interfaces='${INTERFACES}')
+        start_s4(t)
     if not t.skip("smbclient"):
         test_smbclient(t)
-    if not t.skip("startbind"):
-        restart_bind(t)
+    if not t.skip("configure_bind2"):
+        t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
+    if not t.skip("start_bind"):
+        t.start_bind()
     if not t.skip("dns"):
         test_dns(t)
     if not t.skip("kerberos"):
@@ -524,95 +568,109 @@ def test_howto(t):
     if not t.skip("dyndns"):
         test_dyndns(t)
 
-    if t.have_var('WINDOWS7_VM') and not t.skip("windows7"):
+    if t.have_vm('WINDOWS7') and not t.skip("windows7"):
+        t.start_winvm("WINDOWS7")
+        t.test_remote_smbclient("WINDOWS7")
         run_winjoin(t, "WINDOWS7")
         test_winjoin(t, "WINDOWS7")
+        t.vm_poweroff("${WIN_VM}")
 
-    if t.have_var('WINXP_VM') and not t.skip("winxp"):
+    if t.have_vm('WINXP') and not t.skip("winxp"):
+        t.start_winvm("WINXP")
         run_winjoin(t, "WINXP")
         test_winjoin(t, "WINXP")
+        t.test_remote_smbclient("WINXP", "administrator", "${PASSWORD1}")
+        t.vm_poweroff("${WIN_VM}")
 
-    if t.have_var('W2K8R2C_VM') and not t.skip("dcpromo_rodc"):
+    if t.have_vm('W2K8R2C') and not t.skip("dcpromo_rodc"):
         t.info("Testing w2k8r2 RODC dcpromo")
+        t.start_winvm("W2K8R2C")
+        t.test_remote_smbclient('W2K8R2C')
         run_dcpromo_rodc(t, "W2K8R2C")
         test_dcpromo_rodc(t, "W2K8R2C")
 
-    if t.have_var('W2K8R2B_VM') and not t.skip("dcpromo_w2k8r2"):
+    if t.have_vm('W2K8R2B') and not t.skip("dcpromo_w2k8r2"):
         t.info("Testing w2k8r2 dcpromo")
+        t.start_winvm("W2K8R2B")
+        t.test_remote_smbclient('W2K8R2B')
         run_dcpromo(t, "W2K8R2B")
         test_dcpromo(t, "W2K8R2B")
 
-    if t.have_var('W2K8B_VM') and not t.skip("dcpromo_w2k8"):
+    if t.have_vm('W2K8B') and not t.skip("dcpromo_w2k8"):
         t.info("Testing w2k8 dcpromo")
+        t.start_winvm("W2K8B")
+        t.test_remote_smbclient('W2K8B')
         run_dcpromo(t, "W2K8B")
         test_dcpromo(t, "W2K8B")
 
-    if t.have_var('W2K3B_VM') and not t.skip("dcpromo_w2k3"):
+    if t.have_vm('W2K3B') 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)
+        t.restart_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
         test_dns(t)
         test_kerberos(t)
         test_dyndns(t)
+        t.start_winvm("W2K3B")
+        t.test_remote_smbclient('W2K3B')
         run_dcpromo(t, "W2K3B")
         test_dcpromo(t, "W2K3B")
 
-    if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
+    if t.have_vm('W2K8R2A') and not t.skip("join_w2k8r2"):
+        t.start_winvm("W2K8R2A")
+        prep_join_as_dc(t, "W2K8R2A")
+        t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
         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"):
+    if t.have_vm('W2K8R2A') and not t.skip("join_rodc"):
+        t.start_winvm("W2K8R2A")
+        prep_join_as_dc(t, "W2K8R2A")
+        t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
         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"):
+    if t.have_vm('W2K3A') and not t.skip("join_w2k3"):
+        prep_join_as_dc(t, "W2K3A")
+        t.run_dcpromo_as_first_dc("W2K3A", func_level='2003')
         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")
 
     t.info("Howto test: All OK")
 
 
+def test_cleanup(t):
+    '''cleanup after tests'''
+    t.info("Cleaning up ...")
+    t.restore_resolv_conf()
+    if getattr(t, 'bind_child', False):
+        t.bind_child.kill()
+
+
 if __name__ == '__main__':
-    parser = optparse.OptionParser("test-howto.py")
-    parser.add_option("--conf", type='string', default='', help='config file')
-    parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
-    parser.add_option("--list", action='store_true', default=False, help='list the available steps')
-    parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
-    parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
+    t = wintest.wintest()
 
-    opts, args = parser.parse_args()
+    t.setup("test-s4-howto.py", "source4")
 
-    if not opts.conf:
-        t.info("Please specify a config file with --conf")
-        sys.exit(1)
+    try:
+        test_howto(t)
+    except:
+        if not t.opts.nocleanup:
+            test_cleanup(t)
+        raise
 
-    t = wintest.wintest()
-    t.load_config(opts.conf)
-    t.set_skip(opts.skip)
-    if opts.list:
-        t.list_steps_mode()
-
-    if opts.rebase:
-        t.info('rebasing')
-        t.chdir('${SOURCETREE}')
-        t.run_cmd('git pull --rebase')
-
-    if opts.clean:
-        t.info('rebasing')
-        t.chdir('${SOURCETREE}/source4')
-        t.run_cmd('rm -rf bin')
-
-    test_howto(t)
+    if not t.opts.nocleanup:
+        test_cleanup(t)
+    t.info("S4 howto test: All OK")