packaging/RHEL-CTDB: untangle the various %doc entries to single lines
[Samba/gbeck.git] / wintest / test-s4-howto.py
blob8f57553929bc673d3c654e67e07272c36b1d9a61
1 #!/usr/bin/env python
3 '''automated testing of the steps of the Samba4 HOWTO'''
5 import sys, os
6 import optparse
7 import wintest, pexpect
9 def check_prerequesites(t):
10 t.info("Checking prerequesites")
11 t.setvar('HOSTNAME', t.cmd_output("hostname -s").strip())
12 if os.getuid() != 0:
13 raise Exception("You must run this script as root")
14 t.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
15 t.run_cmd('ifconfig ${INTERFACE} ${INTERFACE_NET} up')
16 if t.getvar('INTERFACE_IPV6'):
17 t.run_cmd('ifconfig ${INTERFACE} inet6 del ${INTERFACE_IPV6}/64', checkfail=False)
18 t.run_cmd('ifconfig ${INTERFACE} inet6 add ${INTERFACE_IPV6}/64 up')
21 def build_s4(t):
22 '''build samba4'''
23 t.info('Building s4')
24 t.chdir('${SOURCETREE}/source4')
25 t.putenv('CC', 'ccache gcc')
26 t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
27 t.run_cmd('make -j')
28 t.run_cmd('rm -rf ${PREFIX}')
29 t.run_cmd('make -j install')
32 def provision_s4(t, func_level="2008"):
33 '''provision s4 as a DC'''
34 t.info('Provisioning s4')
35 t.chdir('${PREFIX}')
36 t.del_files(["var", "private"])
37 t.run_cmd("rm -f etc/smb.conf")
38 provision=['sbin/provision',
39 '--realm=${LCREALM}',
40 '--domain=${DOMAIN}',
41 '--adminpass=${PASSWORD1}',
42 '--server-role=domain controller',
43 '--function-level=%s' % func_level,
44 '-d${DEBUGLEVEL}',
45 '--option=interfaces=${INTERFACE}',
46 '--host-ip=${INTERFACE_IP}',
47 '--option=bind interfaces only=yes',
48 '--option=rndc command=${RNDC} -c${PREFIX}/etc/rndc.conf']
49 if t.getvar('INTERFACE_IPV6'):
50 provision.append('--host-ip6=${INTERFACE_IPV6}')
51 t.run_cmd(provision)
52 t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
53 t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
54 t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
57 def start_s4(t):
58 '''startup samba4'''
59 t.info('Starting Samba4')
60 t.chdir("${PREFIX}")
61 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
62 t.run_cmd(['sbin/samba',
63 '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
64 t.port_wait("${INTERFACE_IP}", 139)
66 def test_smbclient(t):
67 '''test smbclient'''
68 t.info('Testing smbclient')
69 t.chdir('${PREFIX}')
70 t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
71 t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
72 child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
73 child.expect("smb:")
74 child.sendline("dir")
75 child.expect("blocks available")
76 child.sendline("mkdir testdir")
77 child.expect("smb:")
78 child.sendline("cd testdir")
79 child.expect('testdir')
80 child.sendline("cd ..")
81 child.sendline("rmdir testdir")
84 def create_shares(t):
85 '''create some test shares'''
86 t.info("Adding test shares")
87 t.chdir('${PREFIX}')
88 t.write_file("etc/smb.conf", '''
89 [test]
90 path = ${PREFIX}/test
91 read only = no
92 [profiles]
93 path = ${PREFIX}/var/profiles
94 read only = no
95 ''',
96 mode='a')
97 t.run_cmd("mkdir -p test")
98 t.run_cmd("mkdir -p var/profiles")
101 def set_nameserver(t, nameserver):
102 '''set the nameserver in resolv.conf'''
103 t.write_file("/etc/resolv.conf.wintest", '''
104 # Generated by wintest, the Samba v Windows automated testing system
105 nameserver %s
107 # your original resolv.conf appears below:
108 ''' % t.substitute(nameserver))
109 child = t.pexpect_spawn("cat /etc/resolv.conf", crlf=False)
110 i = child.expect(['your original resolv.conf appears below:', pexpect.EOF])
111 if i == 0:
112 child.expect(pexpect.EOF)
113 contents = child.before.lstrip().replace('\r', '')
114 t.write_file('/etc/resolv.conf.wintest', contents, mode='a')
115 t.write_file('/etc/resolv.conf.wintest-bak', contents)
116 t.run_cmd("mv -f /etc/resolv.conf.wintest /etc/resolv.conf")
117 t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
120 def restore_resolv_conf(t):
121 '''restore the /etc/resolv.conf after testing is complete'''
122 if getattr(t, 'resolv_conf_backup', False):
123 t.info("restoring /etc/resolv.conf")
124 t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
126 def rndc_cmd(t, cmd, checkfail=True):
127 '''run a rndc command'''
128 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf %s" % cmd, checkfail=checkfail)
131 def restart_bind(t):
132 '''restart the test environment version of bind'''
133 t.info("Restarting bind9")
134 t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
135 t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
136 t.chdir('${PREFIX}')
137 t.run_cmd("mkdir -p var/named/data")
138 t.run_cmd("chown -R ${BIND_USER} var/named")
140 nameserver = t.get_nameserver()
141 if nameserver == t.getvar('INTERFACE_IP'):
142 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration" % nameserver)
143 t.setvar('DNSSERVER', nameserver)
145 if t.getvar('INTERFACE_IPV6'):
146 ipv6_listen = 'listen-on-v6 port 53 { ${INTERFACE_IPV6}; };'
147 else:
148 ipv6_listen = ''
149 t.setvar('BIND_LISTEN_IPV6', ipv6_listen)
151 t.write_file("etc/named.conf", '''
152 options {
153 listen-on port 53 { ${INTERFACE_IP}; };
154 ${BIND_LISTEN_IPV6}
155 directory "${PREFIX}/var/named";
156 dump-file "${PREFIX}/var/named/data/cache_dump.db";
157 pid-file "${PREFIX}/var/named/named.pid";
158 statistics-file "${PREFIX}/var/named/data/named_stats.txt";
159 memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
160 allow-query { any; };
161 recursion yes;
162 tkey-gssapi-credential "DNS/${HOSTNAME}.${LCREALM}";
163 tkey-domain "${REALM}";
164 max-cache-ttl 10;
165 max-ncache-ttl 10;
167 forward only;
168 forwarders {
169 ${DNSSERVER};
174 key "rndc-key" {
175 algorithm hmac-md5;
176 secret "lA/cTrno03mt5Ju17ybEYw==";
179 controls {
180 inet ${INTERFACE_IP} port 953
181 allow { any; } keys { "rndc-key"; };
184 include "${PREFIX}/private/named.conf";
185 ''')
187 # add forwarding for the windows domains
188 domains = t.get_domains()
189 for d in domains:
190 t.write_file('etc/named.conf',
192 zone "%s" IN {
193 type forward;
194 forward only;
195 forwarders {
199 ''' % (d, domains[d]),
200 mode='a')
203 t.write_file("etc/rndc.conf", '''
204 # Start of rndc.conf
205 key "rndc-key" {
206 algorithm hmac-md5;
207 secret "lA/cTrno03mt5Ju17ybEYw==";
210 options {
211 default-key "rndc-key";
212 default-server ${INTERFACE_IP};
213 default-port 953;
215 ''')
217 set_nameserver(t, t.getvar('INTERFACE_IP'))
219 rndc_cmd(t, "stop", checkfail=False)
220 t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
221 t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
223 t.port_wait("${INTERFACE_IP}", 53)
224 rndc_cmd(t, "flush")
227 def test_dns(t):
228 '''test that DNS is OK'''
229 t.info("Testing DNS")
230 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
231 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
232 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
233 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
234 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
235 ['${HOSTNAME}.${LCREALM} has address'])
237 def test_kerberos(t):
238 '''test that kerberos is OK'''
239 t.info("Testing kerberos")
240 t.run_cmd("kdestroy")
241 t.kinit("administrator@${REALM}", "${PASSWORD1}")
242 # this copes with the differences between MIT and Heimdal klist
243 t.cmd_contains("klist", ["rincipal", "administrator@${REALM}"])
246 def test_dyndns(t):
247 '''test that dynamic DNS is working'''
248 t.chdir('${PREFIX}')
249 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
250 rndc_cmd(t, "flush")
253 def run_winjoin(t, vm):
254 '''join a windows box to our domain'''
255 t.setwinvars(vm)
257 t.info("Joining a windows box to the domain")
258 t.vm_poweroff("${WIN_VM}", checkfail=False)
259 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
260 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
261 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
262 child.expect("The command completed successfully")
263 child.expect("C:")
264 child.sendline("shutdown /r -t 0")
265 t.wait_reboot()
266 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
267 child.sendline("ipconfig /registerdns")
268 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")
269 child.expect("C:")
271 def test_winjoin(t, vm):
272 t.info("Checking the windows join is OK")
273 t.chdir('${PREFIX}')
274 t.port_wait("${WIN_IP}", 139)
275 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
276 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
277 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
278 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
279 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
280 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
281 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
282 child.expect("The command completed successfully")
283 t.vm_poweroff("${WIN_VM}")
286 def run_dcpromo(t, vm):
287 '''run a dcpromo on windows'''
288 t.setwinvars(vm)
290 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
291 t.vm_poweroff("${WIN_VM}", checkfail=False)
292 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
293 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
294 child.sendline("copy /Y con answers.txt")
295 child.sendline('''
296 [DCINSTALL]
297 RebootOnSuccess=Yes
298 RebootOnCompletion=Yes
299 ReplicaOrNewDomain=Replica
300 ReplicaDomainDNSName=${LCREALM}
301 SiteName=Default-First-Site-Name
302 InstallDNS=No
303 ConfirmGc=Yes
304 CreateDNSDelegation=No
305 UserDomain=${LCREALM}
306 UserName=${LCREALM}\\administrator
307 Password=${PASSWORD1}
308 DatabasePath="C:\Windows\NTDS"
309 LogPath="C:\Windows\NTDS"
310 SYSVOLPath="C:\Windows\SYSVOL"
311 SafeModeAdminPassword=${PASSWORD1}
312 \x1a
313 ''')
314 child.expect("copied.")
315 child.expect("C:")
316 child.expect("C:")
317 child.sendline("dcpromo /answer:answers.txt")
318 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
319 if i == 1 or i == 2:
320 raise Exception("dcpromo failed")
321 t.wait_reboot()
324 def test_dcpromo(t, vm):
325 '''test that dcpromo worked'''
326 t.info("Checking the dcpromo join is OK")
327 t.chdir('${PREFIX}')
328 t.port_wait("${WIN_IP}", 139)
329 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
330 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
331 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
333 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
334 t.cmd_contains("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
336 t.kinit("administrator@${REALM}", "${PASSWORD1}")
338 # the first replication will transfer the dnsHostname attribute
339 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME} CN=Configuration,${BASEDN} -k yes", ["was successful"])
341 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
342 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
343 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
345 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
346 [ "INBOUND NEIGHBORS",
347 "${BASEDN}",
348 "Last attempt .* was successful",
349 "CN=Configuration,${BASEDN}",
350 "Last attempt .* was successful",
351 "CN=Configuration,${BASEDN}", # cope with either order
352 "Last attempt .* was successful",
353 "OUTBOUND NEIGHBORS",
354 "${BASEDN}",
355 "Last success",
356 "CN=Configuration,${BASEDN}",
357 "Last success",
358 "CN=Configuration,${BASEDN}",
359 "Last success"],
360 ordered=True,
361 regex=True)
363 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
364 [ "INBOUND NEIGHBORS",
365 "${BASEDN}",
366 "Last attempt .* was successful",
367 "CN=Configuration,${BASEDN}",
368 "Last attempt .* was successful",
369 "CN=Configuration,${BASEDN}",
370 "Last attempt .* was successful",
371 "OUTBOUND NEIGHBORS",
372 "${BASEDN}",
373 "Last success",
374 "CN=Configuration,${BASEDN}",
375 "Last success",
376 "CN=Configuration,${BASEDN}",
377 "Last success" ],
378 ordered=True,
379 regex=True)
381 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
382 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
383 child.expect("The command completed successfully")
385 t.run_net_time(child)
387 t.info("Checking if showrepl is happy")
388 child.sendline("repadmin /showrepl")
389 child.expect("${BASEDN}")
390 child.expect("was successful")
391 child.expect("CN=Configuration,${BASEDN}")
392 child.expect("was successful")
393 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
394 child.expect("was successful")
396 t.info("Checking if new users propogate to windows")
397 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
398 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
399 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
401 t.info("Checking if new users on windows propogate to samba")
402 child.sendline("net user test3 ${PASSWORD3} /add")
403 while True:
404 i = child.expect(["The command completed successfully",
405 "The directory service was unable to allocate a relative identifier"])
406 if i == 0:
407 break
408 time.sleep(2)
410 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
411 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
413 t.info("Checking propogation of user deletion")
414 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
415 child.sendline("net user test3 /del")
416 child.expect("The command completed successfully")
418 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
419 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
420 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
421 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
422 t.vm_poweroff("${WIN_VM}")
425 def run_dcpromo_rodc(t, vm):
426 '''run a RODC dcpromo to join a windows DC to the samba domain'''
427 t.setwinvars(vm)
428 t.info("Joining a w2k8 box to the domain as a RODC")
429 t.vm_poweroff("${WIN_VM}", checkfail=False)
430 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
431 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
432 child.sendline("copy /Y con answers.txt")
433 child.sendline('''
434 [DCInstall]
435 ReplicaOrNewDomain=ReadOnlyReplica
436 ReplicaDomainDNSName=${LCREALM}
437 PasswordReplicationDenied="BUILTIN\Administrators"
438 PasswordReplicationDenied="BUILTIN\Server Operators"
439 PasswordReplicationDenied="BUILTIN\Backup Operators"
440 PasswordReplicationDenied="BUILTIN\Account Operators"
441 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
442 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
443 DelegatedAdmin="${DOMAIN}\\Administrator"
444 SiteName=Default-First-Site-Name
445 InstallDNS=No
446 ConfirmGc=Yes
447 CreateDNSDelegation=No
448 UserDomain=${LCREALM}
449 UserName=${LCREALM}\\administrator
450 Password=${PASSWORD1}
451 DatabasePath="C:\Windows\NTDS"
452 LogPath="C:\Windows\NTDS"
453 SYSVOLPath="C:\Windows\SYSVOL"
454 SafeModeAdminPassword=${PASSWORD1}
455 RebootOnCompletion=No
456 \x1a
457 ''')
458 child.expect("copied.")
459 child.sendline("dcpromo /answer:answers.txt")
460 i = child.expect(["You must restart this computer", "failed"], timeout=120)
461 if i != 0:
462 raise Exception("dcpromo failed")
463 child.sendline("shutdown -r -t 0")
464 t.wait_reboot()
468 def test_dcpromo_rodc(t, vm):
469 '''test the RODC dcpromo worked'''
470 t.info("Checking the w2k8 RODC join is OK")
471 t.chdir('${PREFIX}')
472 t.port_wait("${WIN_IP}", 139)
473 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
474 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
475 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
476 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
477 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
478 child.expect("The command completed successfully")
480 t.info("Checking if showrepl is happy")
481 child.sendline("repadmin /showrepl")
482 child.expect("${BASEDN}")
483 child.expect("was successful")
484 child.expect("CN=Configuration,${BASEDN}")
485 child.expect("was successful")
486 child.expect("CN=Configuration,${BASEDN}")
487 child.expect("was successful")
489 t.info("Checking if new users are available on windows")
490 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
491 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
492 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
493 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN} -k yes", ["was successful"])
494 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
495 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
496 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
497 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
498 t.vm_poweroff("${WIN_VM}")
501 def join_as_dc(t, vm):
502 '''join a windows domain as a DC'''
503 t.setwinvars(vm)
504 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
505 t.chdir('${PREFIX}')
506 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
507 t.vm_poweroff("${WIN_VM}", checkfail=False)
508 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
509 rndc_cmd(t, 'flush')
510 t.run_cmd("rm -rf etc/smb.conf private")
511 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
512 t.get_ipconfig(child)
513 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
514 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
515 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
518 def test_join_as_dc(t, vm):
519 '''test the join of a windows domain as a DC'''
520 t.info("Checking the DC join is OK")
521 t.chdir('${PREFIX}')
522 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
523 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
524 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
526 t.info("Forcing kcc runs, and replication")
527 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
528 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
530 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
531 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
532 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
533 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
535 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
536 child.expect("The command completed successfully")
538 t.info("Checking if showrepl is happy")
539 child.sendline("repadmin /showrepl")
540 child.expect("${WIN_BASEDN}")
541 child.expect("was successful")
542 child.expect("CN=Configuration,${WIN_BASEDN}")
543 child.expect("was successful")
544 child.expect("CN=Configuration,${WIN_BASEDN}")
545 child.expect("was successful")
547 t.info("Checking if new users propogate to windows")
548 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
549 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
550 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
552 t.info("Checking if new users on windows propogate to samba")
553 child.sendline("net user test3 ${PASSWORD3} /add")
554 child.expect("The command completed successfully")
555 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
556 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
558 t.info("Checking propogation of user deletion")
559 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
560 child.sendline("net user test3 /del")
561 child.expect("The command completed successfully")
563 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
564 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
565 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
566 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
567 t.vm_poweroff("${WIN_VM}")
570 def join_as_rodc(t, vm):
571 '''join a windows domain as a RODC'''
572 t.setwinvars(vm)
573 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
574 t.chdir('${PREFIX}')
575 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
576 t.vm_poweroff("${WIN_VM}", checkfail=False)
577 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
578 rndc_cmd(t, 'flush')
579 t.run_cmd("rm -rf etc/smb.conf private")
580 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
581 t.get_ipconfig(child)
582 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
583 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
584 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
587 def test_join_as_rodc(t, vm):
588 '''test a windows domain RODC join'''
589 t.info("Checking the RODC join is OK")
590 t.chdir('${PREFIX}')
591 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
592 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
593 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
595 t.info("Forcing kcc runs, and replication")
596 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
597 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
599 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
600 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
601 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
603 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
604 child.expect("The command completed successfully")
606 t.info("Checking if showrepl is happy")
607 child.sendline("repadmin /showrepl")
608 child.expect("DSA invocationID")
610 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
611 [ "INBOUND NEIGHBORS",
612 "OUTBOUND NEIGHBORS",
613 "${WIN_BASEDN}",
614 "Last attempt .* was successful",
615 "CN=Configuration,${WIN_BASEDN}",
616 "Last attempt .* was successful",
617 "CN=Configuration,${WIN_BASEDN}",
618 "Last attempt .* was successful" ],
619 ordered=True,
620 regex=True)
622 t.info("Checking if new users on windows propogate to samba")
623 child.sendline("net user test3 ${PASSWORD3} /add")
624 child.expect("The command completed successfully")
625 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
626 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
628 # should this work?
629 t.info("Checking if new users propogate to windows")
630 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
632 t.info("Checking propogation of user deletion")
633 child.sendline("net user test3 /del")
634 child.expect("The command completed successfully")
636 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
637 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
638 t.vm_poweroff("${WIN_VM}")
641 def test_howto(t):
642 '''test the Samba4 howto'''
644 check_prerequesites(t)
646 # we don't need fsync safety in these tests
647 t.putenv('TDB_NO_FSYNC', '1')
649 if not t.skip("build"):
650 build_s4(t)
652 if not t.skip("provision"):
653 provision_s4(t)
655 if not t.skip("create-shares"):
656 create_shares(t)
658 if not t.skip("starts4"):
659 start_s4(t)
660 if not t.skip("smbclient"):
661 test_smbclient(t)
662 if not t.skip("startbind"):
663 restart_bind(t)
664 if not t.skip("dns"):
665 test_dns(t)
666 if not t.skip("kerberos"):
667 test_kerberos(t)
668 if not t.skip("dyndns"):
669 test_dyndns(t)
671 if t.have_var('WINDOWS7_VM') and not t.skip("windows7"):
672 run_winjoin(t, "WINDOWS7")
673 test_winjoin(t, "WINDOWS7")
675 if t.have_var('WINXP_VM') and not t.skip("winxp"):
676 run_winjoin(t, "WINXP")
677 test_winjoin(t, "WINXP")
679 if t.have_var('W2K8R2C_VM') and not t.skip("dcpromo_rodc"):
680 t.info("Testing w2k8r2 RODC dcpromo")
681 run_dcpromo_rodc(t, "W2K8R2C")
682 test_dcpromo_rodc(t, "W2K8R2C")
684 if t.have_var('W2K8R2B_VM') and not t.skip("dcpromo_w2k8r2"):
685 t.info("Testing w2k8r2 dcpromo")
686 run_dcpromo(t, "W2K8R2B")
687 test_dcpromo(t, "W2K8R2B")
689 if t.have_var('W2K8B_VM') and not t.skip("dcpromo_w2k8"):
690 t.info("Testing w2k8 dcpromo")
691 run_dcpromo(t, "W2K8B")
692 test_dcpromo(t, "W2K8B")
694 if t.have_var('W2K3B_VM') and not t.skip("dcpromo_w2k3"):
695 t.info("Testing w2k3 dcpromo")
696 t.info("Changing to 2003 functional level")
697 provision_s4(t, func_level='2003')
698 create_shares(t)
699 start_s4(t)
700 test_smbclient(t)
701 restart_bind(t)
702 test_dns(t)
703 test_kerberos(t)
704 test_dyndns(t)
705 run_dcpromo(t, "W2K3B")
706 test_dcpromo(t, "W2K3B")
708 if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
709 join_as_dc(t, "W2K8R2A")
710 create_shares(t)
711 start_s4(t)
712 test_dyndns(t)
713 test_join_as_dc(t, "W2K8R2A")
715 if t.have_var('W2K8R2A_VM') and not t.skip("join_rodc"):
716 join_as_rodc(t, "W2K8R2A")
717 create_shares(t)
718 start_s4(t)
719 test_dyndns(t)
720 test_join_as_rodc(t, "W2K8R2A")
722 if t.have_var('W2K3A_VM') and not t.skip("join_w2k3"):
723 join_as_dc(t, "W2K3A")
724 create_shares(t)
725 start_s4(t)
726 test_dyndns(t)
727 test_join_as_dc(t, "W2K3A")
729 t.info("Howto test: All OK")
732 def test_cleanup(t):
733 '''cleanup after tests'''
734 t.info("Cleaning up ...")
735 restore_resolv_conf(t)
736 if getattr(t, 'bind_child', False):
737 t.bind_child.kill()
740 if __name__ == '__main__':
741 parser = optparse.OptionParser("test-howto.py")
742 parser.add_option("--conf", type='string', default='', help='config file')
743 parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
744 parser.add_option("--list", action='store_true', default=False, help='list the available steps')
745 parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
746 parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
747 parser.add_option("--prefix", type='string', default=None, help='override install prefix')
748 parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
749 parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
751 opts, args = parser.parse_args()
753 if not opts.conf:
754 print("Please specify a config file with --conf")
755 sys.exit(1)
757 t = wintest.wintest()
758 t.load_config(opts.conf)
759 t.set_skip(opts.skip)
761 if opts.list:
762 t.list_steps_mode()
764 if opts.prefix:
765 t.setvar('PREFIX', opts.prefix)
767 if opts.sourcetree:
768 t.setvar('SOURCETREE', opts.sourcetree)
770 if opts.rebase:
771 t.info('rebasing')
772 t.chdir('${SOURCETREE}')
773 t.run_cmd('git pull --rebase')
775 if opts.clean:
776 t.info('rebasing')
777 t.chdir('${SOURCETREE}/source4')
778 t.run_cmd('rm -rf bin')
780 try:
781 test_howto(t)
782 except:
783 if not opts.nocleanup:
784 test_cleanup(t)
785 raise
787 if not opts.nocleanup:
788 test_cleanup(t)
789 t.info("S4 howto test: All OK")