s3-docs: Update 3.2 features.
[Samba/gbeck.git] / wintest / test-s4-howto.py
blobec96581e81323a303e235a0cf06a7b8d1c694ada
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
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_IP} up')
18 def build_s4(t):
19 '''build samba4'''
20 t.info('Building s4')
21 t.chdir('${SOURCETREE}/source4')
22 t.putenv('CC', 'ccache gcc')
23 t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
24 t.run_cmd('make -j')
25 t.run_cmd('rm -rf ${PREFIX}')
26 t.run_cmd('make -j install')
29 def provision_s4(t, func_level="2008", interface=None):
30 '''provision s4 as a DC'''
31 t.info('Provisioning s4')
32 t.chdir('${PREFIX}')
33 t.del_files(["var", "etc", "private"])
34 options=' --function-level=%s -d${DEBUGLEVEL}' % func_level
35 if interface:
36 options += ' --option=interfaces=%s' % interface
37 options += ' --host-ip=%s' % interface
38 t.run_cmd('sbin/provision --realm=${LCREALM} --domain=${DOMAIN} --adminpass=${PASSWORD1} --server-role="domain controller"' + options)
39 t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
40 t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
41 t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
44 def start_s4(t, interface=None):
45 '''startup samba4'''
46 t.info('Starting Samba4')
47 t.chdir("${PREFIX}")
48 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
49 t.run_cmd(['sbin/samba',
50 '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"',
51 '--option', 'interfaces=%s' % interface])
52 t.port_wait("localhost", 139)
55 def test_smbclient(t):
56 '''test smbclient'''
57 t.info('Testing smbclient')
58 t.chdir('${PREFIX}')
59 t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
60 t.retry_cmd('bin/smbclient -L localhost -U%', ["netlogon", "sysvol", "IPC Service"])
61 child = t.pexpect_spawn('bin/smbclient //localhost/netlogon -Uadministrator%${PASSWORD1}')
62 child.expect("smb:")
63 child.sendline("dir")
64 child.expect("blocks available")
65 child.sendline("mkdir testdir")
66 child.expect("smb:")
67 child.sendline("cd testdir")
68 child.expect('testdir')
69 child.sendline("cd ..")
70 child.sendline("rmdir testdir")
73 def create_shares(t):
74 '''create some test shares'''
75 t.info("Adding test shares")
76 t.chdir('${PREFIX}')
77 t.write_file("etc/smb.conf", '''
78 [test]
79 path = ${PREFIX}/test
80 read only = no
81 [profiles]
82 path = ${PREFIX}/var/profiles
83 read only = no
84 ''',
85 mode='a')
86 t.run_cmd("mkdir -p test")
87 t.run_cmd("mkdir -p var/profiles")
90 def restart_bind(t):
91 '''restart the test environment version of bind'''
92 t.info("Restarting bind9")
93 t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
94 t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
95 t.chdir('${PREFIX}')
96 t.run_cmd("mkdir -p var/named/data")
97 t.run_cmd("chown -R ${BIND_USER} var/named")
99 nameserver = t.get_nameserver()
100 if nameserver == t.getvar('INTERFACE_IP'):
101 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration")
102 t.setvar('DNSSERVER', nameserver)
104 t.write_file("etc/named.conf", '''
105 options {
106 listen-on port 53 { ${INTERFACE_IP}; };
107 directory "${PREFIX}/var/named";
108 dump-file "${PREFIX}/var/named/data/cache_dump.db";
109 pid-file "${PREFIX}/var/named/named.pid";
110 statistics-file "${PREFIX}/var/named/data/named_stats.txt";
111 memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
112 allow-query { ${INTERFACE_NET}; 127.0.0.0/8; };
113 recursion yes;
114 tkey-gssapi-credential "DNS/${LCREALM}";
115 tkey-domain "${REALM}";
117 forward only;
118 forwarders {
119 ${DNSSERVER};
124 key "rndc-key" {
125 algorithm hmac-md5;
126 secret "lA/cTrno03mt5Ju17ybEYw==";
129 controls {
130 inet ${INTERFACE_IP}
131 allow { 127.0.0.0/8; ${INTERFACE_NET}; } keys { "rndc-key"; };
134 include "${PREFIX}/private/named.conf";
135 ''')
137 t.write_file("etc/rndc.conf", '''
138 # Start of rndc.conf
139 key "rndc-key" {
140 algorithm hmac-md5;
141 secret "lA/cTrno03mt5Ju17ybEYw==";
144 options {
145 default-key "rndc-key";
146 default-server ${INTERFACE_IP};
147 default-port 953;
149 ''')
151 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf stop", checkfail=False)
152 t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
153 t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
155 t.run_cmd("mv -f /etc/resolv.conf /etc/resolv.conf.wintest-bak")
156 t.write_file("/etc/resolv.conf", '''
157 # Generated by wintest, the Samba v Windows automated testing system
159 nameserver ${INTERFACE_IP}
161 # your original resolv.conf appears below:
163 ''')
165 t.run_cmd('cat /etc/resolv.conf.wintest-bak >> /etc/resolv.conf')
167 t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
169 t.port_wait("${INTERFACE_IP}", 53)
170 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf flush")
171 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf freeze")
172 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf thaw")
175 def restore_resolv_conf(t):
176 '''restore the /etc/resolv.conf after testing is complete'''
177 if getattr(t, 'resolv_conf_backup', False):
178 t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
181 def test_dns(t):
182 '''test that DNS is OK'''
183 t.info("Testing DNS")
184 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
185 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
186 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
187 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
188 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
189 ['${HOSTNAME}.${LCREALM} has address'])
191 def test_kerberos(t):
192 '''test that kerberos is OK'''
193 t.info("Testing kerberos")
194 t.run_cmd("kdestroy")
195 t.kinit("administrator@${REALM}", "${PASSWORD1}")
196 t.cmd_contains("klist -e", ["Ticket cache", "Default principal", "Valid starting"])
199 def test_dyndns(t):
200 '''test that dynamic DNS is working'''
201 t.chdir('${PREFIX}')
202 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
203 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf flush")
206 def run_winjoin(t, vm):
207 '''join a windows box to our domain'''
208 t.setwinvars(vm)
210 t.info("Joining a windows box to the domain")
211 t.vm_poweroff("${WIN_VM}", checkfail=False)
212 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
213 t.ping_wait("${WIN_HOSTNAME}")
214 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
215 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
216 child.expect("The command completed successfully")
217 child.expect("C:")
218 child.sendline("shutdown /r -t 0")
219 t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
220 t.port_wait("${WIN_HOSTNAME}", 139)
221 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
222 child.sendline("ipconfig /registerdns")
223 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")
224 child.expect("C:")
226 def test_winjoin(t, vm):
227 t.setwinvars(vm)
228 t.info("Checking the windows join is OK")
229 t.chdir('${PREFIX}')
230 t.port_wait("${WIN_HOSTNAME}", 139)
231 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
232 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
233 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
234 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
235 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
236 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
237 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
238 child.expect("The command completed successfully")
239 t.vm_poweroff("${WIN_VM}")
242 def run_dcpromo(t, vm):
243 '''run a dcpromo on windows'''
244 t.setwinvars(vm)
246 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
247 t.vm_poweroff("${WIN_VM}", checkfail=False)
248 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
249 t.ping_wait("${WIN_HOSTNAME}")
250 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
251 child.sendline("copy /Y con answers.txt")
252 child.sendline('''
253 [DCINSTALL]
254 RebootOnSuccess=Yes
255 RebootOnCompletion=Yes
256 ReplicaOrNewDomain=Replica
257 ReplicaDomainDNSName=${LCREALM}
258 SiteName=Default-First-Site-Name
259 InstallDNS=No
260 ConfirmGc=Yes
261 CreateDNSDelegation=No
262 UserDomain=${LCREALM}
263 UserName=${LCREALM}\\administrator
264 Password=${PASSWORD1}
265 DatabasePath="C:\Windows\NTDS"
266 LogPath="C:\Windows\NTDS"
267 SYSVOLPath="C:\Windows\SYSVOL"
268 SafeModeAdminPassword=${PASSWORD1}
269 \x1a
270 ''')
271 child.expect("copied.")
272 child.expect("C:")
273 child.expect("C:")
274 child.sendline("dcpromo /answer:answers.txt")
275 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
276 if i == 1 or i == 2:
277 raise Exception("dcpromo failed")
278 t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
279 t.port_wait("${WIN_HOSTNAME}", 139)
282 def test_dcpromo(t, vm):
283 '''test that dcpromo worked'''
284 t.setwinvars(vm)
285 t.info("Checking the dcpromo join is OK")
286 t.chdir('${PREFIX}')
287 t.port_wait("${WIN_HOSTNAME}", 139)
288 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
289 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
290 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
292 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
293 t.cmd_contains("bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
295 t.kinit("administrator@${REALM}", "${PASSWORD1}")
296 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
297 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME} %s -k yes" % nc, ["was successful"])
298 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
300 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME} -k yes",
301 [ "INBOUND NEIGHBORS",
302 "${BASEDN}",
303 "Last attempt .* was successful",
304 "CN=Configuration,${BASEDN}",
305 "Last attempt .* was successful",
306 "CN=Configuration,${BASEDN}", # cope with either order
307 "Last attempt .* was successful",
308 "OUTBOUND NEIGHBORS",
309 "${BASEDN}",
310 "Last success",
311 "CN=Configuration,${BASEDN}",
312 "Last success",
313 "CN=Configuration,${BASEDN}",
314 "Last success"],
315 ordered=True,
316 regex=True)
318 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -k yes",
319 [ "INBOUND NEIGHBORS",
320 "${BASEDN}",
321 "Last attempt .* was successful",
322 "CN=Configuration,${BASEDN}",
323 "Last attempt .* was successful",
324 "CN=Configuration,${BASEDN}",
325 "Last attempt .* was successful",
326 "OUTBOUND NEIGHBORS",
327 "${BASEDN}",
328 "Last success",
329 "CN=Configuration,${BASEDN}",
330 "Last success",
331 "CN=Configuration,${BASEDN}",
332 "Last success" ],
333 ordered=True,
334 regex=True)
336 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
337 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
338 child.expect("The command completed successfully")
340 t.run_net_time(child)
342 t.info("Checking if showrepl is happy")
343 child.sendline("repadmin /showrepl")
344 child.expect("${BASEDN}")
345 child.expect("was successful")
346 child.expect("CN=Configuration,${BASEDN}")
347 child.expect("was successful")
348 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
349 child.expect("was successful")
351 t.info("Checking if new users propogate to windows")
352 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
353 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
354 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
356 t.info("Checking if new users on windows propogate to samba")
357 child.sendline("net user test3 ${PASSWORD3} /add")
358 while True:
359 i = child.expect(["The command completed successfully",
360 "The directory service was unable to allocate a relative identifier"])
361 if i == 0:
362 break
363 time.sleep(2)
365 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
366 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
368 t.info("Checking propogation of user deletion")
369 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
370 child.sendline("net user test3 /del")
371 child.expect("The command completed successfully")
373 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
374 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
375 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
376 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
377 t.vm_poweroff("${WIN_VM}")
380 def run_dcpromo_rodc(t, vm):
381 '''run a RODC dcpromo to join a windows DC to the samba domain'''
382 t.setwinvars(vm)
383 t.info("Joining a w2k8 box to the domain as a RODC")
384 t.vm_poweroff("${WIN_VM}", checkfail=False)
385 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
386 t.ping_wait("${WIN_HOSTNAME}")
387 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
388 child.sendline("copy /Y con answers.txt")
389 child.sendline('''
390 [DCInstall]
391 ReplicaOrNewDomain=ReadOnlyReplica
392 ReplicaDomainDNSName=${LCREALM}
393 PasswordReplicationDenied="BUILTIN\Administrators"
394 PasswordReplicationDenied="BUILTIN\Server Operators"
395 PasswordReplicationDenied="BUILTIN\Backup Operators"
396 PasswordReplicationDenied="BUILTIN\Account Operators"
397 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
398 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
399 DelegatedAdmin="${DOMAIN}\\Administrator"
400 SiteName=Default-First-Site-Name
401 InstallDNS=No
402 ConfirmGc=Yes
403 CreateDNSDelegation=No
404 UserDomain=${LCREALM}
405 UserName=${LCREALM}\\administrator
406 Password=${PASSWORD1}
407 DatabasePath="C:\Windows\NTDS"
408 LogPath="C:\Windows\NTDS"
409 SYSVOLPath="C:\Windows\SYSVOL"
410 SafeModeAdminPassword=${PASSWORD1}
411 RebootOnCompletion=No
412 \x1a
413 ''')
414 child.expect("copied.")
415 child.sendline("dcpromo /answer:answers.txt")
416 i = child.expect(["You must restart this computer", "failed"], timeout=120)
417 if i != 0:
418 raise Exception("dcpromo failed")
419 child.sendline("shutdown -r -t 0")
420 t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
421 t.port_wait("${WIN_HOSTNAME}", 139)
425 def test_dcpromo_rodc(t, vm):
426 '''test the RODC dcpromo worked'''
427 t.setwinvars(vm)
428 t.info("Checking the w2k8 RODC join is OK")
429 t.chdir('${PREFIX}')
430 t.port_wait("${WIN_HOSTNAME}", 139)
431 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
432 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
433 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
434 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
435 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
436 child.expect("The command completed successfully")
438 t.info("Checking if showrepl is happy")
439 child.sendline("repadmin /showrepl")
440 child.expect("${BASEDN}")
441 child.expect("was successful")
442 child.expect("CN=Configuration,${BASEDN}")
443 child.expect("was successful")
444 child.expect("CN=Configuration,${BASEDN}")
445 child.expect("was successful")
447 t.info("Checking if new users are available on windows")
448 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
449 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
450 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
451 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME} ${HOSTNAME} ${BASEDN} -k yes", ["was successful"])
452 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
453 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
454 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
455 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
456 t.vm_poweroff("${WIN_VM}")
459 def join_as_dc(t, vm):
460 '''join a windows domain as a DC'''
461 t.setwinvars(vm)
462 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
463 t.chdir('${PREFIX}')
464 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
465 t.vm_poweroff("${WIN_VM}", checkfail=False)
466 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
467 t.run_cmd('${RNDC} -c ${PREFIX}/etc/rndc.conf flush')
468 t.run_cmd("rm -rf etc private")
469 t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True, set_ip=True)
470 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
471 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}')
472 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
475 def test_join_as_dc(t, vm):
476 '''test the join of a windows domain as a DC'''
477 t.setwinvars(vm)
478 t.info("Checking the DC join is OK")
479 t.chdir('${PREFIX}')
480 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
481 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
482 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
484 t.info("Forcing kcc runs, and replication")
485 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
486 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
488 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
489 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
490 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME} %s -k yes" % nc, ["was successful"])
491 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
493 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
494 child.expect("The command completed successfully")
496 t.info("Checking if showrepl is happy")
497 child.sendline("repadmin /showrepl")
498 child.expect("${WIN_BASEDN}")
499 child.expect("was successful")
500 child.expect("CN=Configuration,${WIN_BASEDN}")
501 child.expect("was successful")
502 child.expect("CN=Configuration,${WIN_BASEDN}")
503 child.expect("was successful")
505 t.info("Checking if new users propogate to windows")
506 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
507 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
508 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
510 t.info("Checking if new users on windows propogate to samba")
511 child.sendline("net user test3 ${PASSWORD3} /add")
512 child.expect("The command completed successfully")
513 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
514 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
516 t.info("Checking propogation of user deletion")
517 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
518 child.sendline("net user test3 /del")
519 child.expect("The command completed successfully")
521 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
522 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
523 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
524 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
525 t.vm_poweroff("${WIN_VM}")
528 def join_as_rodc(t, vm):
529 '''join a windows domain as a RODC'''
530 t.setwinvars(vm)
531 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
532 t.chdir('${PREFIX}')
533 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
534 t.vm_poweroff("${WIN_VM}", checkfail=False)
535 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
536 t.run_cmd('${RNDC} -c ${PREFIX}/etc/rndc.conf flush')
537 t.run_cmd("rm -rf etc private")
538 t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True, set_ip=True)
539 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
540 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}')
541 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
544 def test_join_as_rodc(t, vm):
545 '''test a windows domain RODC join'''
546 t.setwinvars(vm)
547 t.info("Checking the RODC join is OK")
548 t.chdir('${PREFIX}')
549 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
550 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
551 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
553 t.info("Forcing kcc runs, and replication")
554 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
555 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
557 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
558 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
559 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME} %s -k yes" % nc, ["was successful"])
561 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
562 child.expect("The command completed successfully")
564 t.info("Checking if showrepl is happy")
565 child.sendline("repadmin /showrepl")
566 child.expect("DSA invocationID")
568 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
569 [ "INBOUND NEIGHBORS",
570 "OUTBOUND NEIGHBORS",
571 "${WIN_BASEDN}",
572 "Last attempt .* was successful",
573 "CN=Configuration,${WIN_BASEDN}",
574 "Last attempt .* was successful",
575 "CN=Configuration,${WIN_BASEDN}",
576 "Last attempt .* was successful" ],
577 ordered=True,
578 regex=True)
580 t.info("Checking if new users on windows propogate to samba")
581 child.sendline("net user test3 ${PASSWORD3} /add")
582 child.expect("The command completed successfully")
583 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
584 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
586 # should this work?
587 t.info("Checking if new users propogate to windows")
588 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
590 t.info("Checking propogation of user deletion")
591 child.sendline("net user test3 /del")
592 child.expect("The command completed successfully")
594 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
595 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
596 t.vm_poweroff("${WIN_VM}")
599 def test_howto(t):
600 '''test the Samba4 howto'''
602 check_prerequesites(t)
604 # we don't need fsync safety in these tests
605 t.putenv('TDB_NO_FSYNC', '1')
607 if not t.skip("build"):
608 build_s4(t)
610 if not t.skip("provision"):
611 provision_s4(t, interface='${INTERFACE_IP}')
613 if not t.skip("create-shares"):
614 create_shares(t)
616 if not t.skip("starts4"):
617 start_s4(t, interface='${INTERFACE_IP}')
618 if not t.skip("smbclient"):
619 test_smbclient(t)
620 if not t.skip("startbind"):
621 restart_bind(t)
622 if not t.skip("dns"):
623 test_dns(t)
624 if not t.skip("kerberos"):
625 test_kerberos(t)
626 if not t.skip("dyndns"):
627 test_dyndns(t)
629 if t.have_var('WINDOWS7_VM') and not t.skip("windows7"):
630 run_winjoin(t, "WINDOWS7")
631 test_winjoin(t, "WINDOWS7")
633 if t.have_var('WINXP_VM') and not t.skip("winxp"):
634 run_winjoin(t, "WINXP")
635 test_winjoin(t, "WINXP")
637 if t.have_var('W2K8R2C_VM') and not t.skip("dcpromo_rodc"):
638 t.info("Testing w2k8r2 RODC dcpromo")
639 run_dcpromo_rodc(t, "W2K8R2C")
640 test_dcpromo_rodc(t, "W2K8R2C")
642 if t.have_var('W2K8R2B_VM') and not t.skip("dcpromo_w2k8r2"):
643 t.info("Testing w2k8r2 dcpromo")
644 run_dcpromo(t, "W2K8R2B")
645 test_dcpromo(t, "W2K8R2B")
647 if t.have_var('W2K8B_VM') and not t.skip("dcpromo_w2k8"):
648 t.info("Testing w2k8 dcpromo")
649 run_dcpromo(t, "W2K8B")
650 test_dcpromo(t, "W2K8B")
652 if t.have_var('W2K3B_VM') and not t.skip("dcpromo_w2k3"):
653 t.info("Testing w2k3 dcpromo")
654 t.info("Changing to 2003 functional level")
655 provision_s4(t, func_level='2003', interfaces='${INTERFACES}')
656 create_shares(t)
657 start_s4(t, interfaces='${INTERFACES}')
658 test_smbclient(t)
659 restart_bind(t)
660 test_dns(t)
661 test_kerberos(t)
662 test_dyndns(t)
663 run_dcpromo(t, "W2K3B")
664 test_dcpromo(t, "W2K3B")
666 if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
667 join_as_dc(t, "W2K8R2A")
668 create_shares(t)
669 start_s4(t, interfaces='${INTERFACES}')
670 test_dyndns(t)
671 test_join_as_dc(t, "W2K8R2A")
673 if t.have_var('W2K8R2A_VM') and not t.skip("join_rodc"):
674 join_as_rodc(t, "W2K8R2A")
675 create_shares(t)
676 start_s4(t, interfaces='${INTERFACES}')
677 test_dyndns(t)
678 test_join_as_rodc(t, "W2K8R2A")
680 if t.have_var('W2K3A_VM') and not t.skip("join_w2k3"):
681 join_as_dc(t, "W2K3A")
682 create_shares(t)
683 start_s4(t, interfaces='${INTERFACES}')
684 test_dyndns(t)
685 test_join_as_dc(t, "W2K3A")
687 t.info("Howto test: All OK")
690 def test_cleanup(t):
691 '''cleanup after tests'''
692 restore_resolv_conf(t)
693 if getattr(t, 'bind_child', False):
694 t.bind_child.kill()
697 if __name__ == '__main__':
698 parser = optparse.OptionParser("test-howto.py")
699 parser.add_option("--conf", type='string', default='', help='config file')
700 parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
701 parser.add_option("--list", action='store_true', default=False, help='list the available steps')
702 parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
703 parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
704 parser.add_option("--prefix", type='string', default=None, help='override install prefix')
705 parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
706 parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
708 opts, args = parser.parse_args()
710 if not opts.conf:
711 print("Please specify a config file with --conf")
712 sys.exit(1)
714 t = wintest.wintest()
715 t.load_config(opts.conf)
716 t.set_skip(opts.skip)
718 if opts.list:
719 t.list_steps_mode()
721 if opts.prefix:
722 t.setvar('PREFIX', opts.prefix)
724 if opts.sourcetree:
725 t.setvar('SOURCETREE', opts.sourcetree)
727 if opts.rebase:
728 t.info('rebasing')
729 t.chdir('${SOURCETREE}')
730 t.run_cmd('git pull --rebase')
732 if opts.clean:
733 t.info('rebasing')
734 t.chdir('${SOURCETREE}/source4')
735 t.run_cmd('rm -rf bin')
737 try:
738 test_howto(t)
739 except Exception, str:
740 if not opts.nocleanup:
741 test_cleanup(t)
742 raise
744 if not opts.nocleanup:
745 test_cleanup(t)
746 t.info("S4 howto test: All OK")