1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-23 09:57:40 +03:00

wintest Set the virtual machine IP to match it's dynamic IP, but don't use DHCP

The idea here is that the virtual machine stays on the address
allocated by DHCP, but is configured statically.  This avoids the need
to manually set the address on the host, but avoids the host being
instructed by DHCP not to do Dynamic DNS.

Andrew Bartlett
This commit is contained in:
Andrew Bartlett 2010-11-22 21:23:38 +11:00
parent c251c45e7f
commit 5767ee9663
2 changed files with 77 additions and 10 deletions

View File

@ -119,20 +119,25 @@ def run_winjoin(t, vm):
t.vm_poweroff("${WIN_VM}", checkfail=False) t.vm_poweroff("${WIN_VM}", checkfail=False)
t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}") t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
t.ping_wait("${WIN_HOSTNAME}") t.ping_wait("${WIN_HOSTNAME}")
child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True) child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator") child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
child.expect("The command completed successfully") child.expect("The command completed successfully")
child.expect("C:")
child.sendline("shutdown /r -t 0") child.sendline("shutdown /r -t 0")
t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True) t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
t.port_wait("${WIN_HOSTNAME}", 139) t.port_wait("${WIN_HOSTNAME}", 139)
child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
child.expect("C:")
child.sendline("ipconfig /registerdns")
child.expect("Registration of the DNS resource records for all adapters of this computer has been initiated. Any errors will be reported in the Event Viewer")
child.expect("C:")
def test_winjoin(t, vm): def test_winjoin(t, vm):
t.setwinvars(vm) t.setwinvars(vm)
t.info("Checking the windows join is OK") t.info("Checking the windows join is OK")
t.chdir('${PREFIX}') t.chdir('${PREFIX}')
t.port_wait("${WIN_HOSTNAME}", 139) t.port_wait("${WIN_HOSTNAME}", 139)
t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"]) 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("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} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"]) t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
@ -151,7 +156,7 @@ def run_dcpromo(t, vm):
t.vm_poweroff("${WIN_VM}", checkfail=False) t.vm_poweroff("${WIN_VM}", checkfail=False)
t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}") t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
t.ping_wait("${WIN_HOSTNAME}") 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("copy /Y con answers.txt")
child.sendline(''' child.sendline('''
[DCINSTALL] [DCINSTALL]
@ -286,7 +291,7 @@ def run_dcpromo_rodc(t, vm):
t.vm_poweroff("${WIN_VM}", checkfail=False) t.vm_poweroff("${WIN_VM}", checkfail=False)
t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}") t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
t.ping_wait("${WIN_HOSTNAME}") 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("copy /Y con answers.txt")
child.sendline(''' child.sendline('''
[DCInstall] [DCInstall]
@ -363,7 +368,7 @@ def join_as_dc(t, vm):
t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}") t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
t.run_cmd('${RNDC} flush') t.run_cmd('${RNDC} flush')
t.run_cmd("rm -rf etc private") t.run_cmd("rm -rf etc private")
t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True) t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True, set_ip=True)
t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] ) t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}') t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}')
t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}') t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
@ -430,7 +435,7 @@ def join_as_rodc(t, vm):
t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}") t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
t.run_cmd('${RNDC} flush') t.run_cmd('${RNDC} flush')
t.run_cmd("rm -rf etc private") t.run_cmd("rm -rf etc private")
t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True) t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True, set_ip=True)
t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] ) t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}') t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}')
t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}') t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')

View File

@ -240,22 +240,73 @@ class wintest():
time_tuple = time.localtime() time_tuple = time.localtime()
child.sendline("date") child.sendline("date")
child.expect("Enter the new date:") child.expect("Enter the new date:")
child.sendline(time.strftime("%m-%d-%y", time_tuple)) i = child.expect(["dd-mm-yy", "mm-dd-yy"])
if i == 0:
child.sendline(time.strftime("%d-%m-%y", time_tuple))
else:
child.sendline(time.strftime("%m-%d-%y", time_tuple))
child.expect("C:") child.expect("C:")
child.sendline("time") child.sendline("time")
child.expect("Enter the new time:") child.expect("Enter the new time:")
child.sendline(time.strftime("%H:%M:%S", time_tuple)) child.sendline(time.strftime("%H:%M:%S", time_tuple))
child.expect("C:") child.expect("C:")
def get_ipconfig(self, child):
'''get the IP configuration of the child'''
child.sendline("ipconfig")
child.expect('Ethernet adapter ')
child.expect("[\w\s]+")
self.setvar("WIN_NIC", child.after)
child.expect(['IPv4 Address', 'IP Address'])
child.expect('\d+.\d+.\d+.\d+')
self.setvar('WIN_IPV4_ADDRESS', child.after)
child.expect('Subnet Mask')
child.expect('\d+.\d+.\d+.\d+')
self.setvar('WIN_SUBNET_MASK', child.after)
child.expect('Default Gateway')
child.expect('\d+.\d+.\d+.\d+')
self.setvar('WIN_DEFAULT_GATEWAY', child.after)
def open_telnet(self, hostname, username, password, retries=60, delay=5, set_time=False): def disable_firewall(self, child):
'''remove the annoying firewall'''
child.sendline('netsh advfirewall set allprofiles state off')
i = child.expect(["Ok", "The following command was not found: advfirewall set allprofiles state off"])
child.expect("C:")
if i == 1:
child.sendline('netsh firewall set opmode mode = DISABLE profile = ALL')
child.expect("Ok")
child.expect("C:")
def set_ip(self, child):
'''fix the IP address to the same value it had when we
connected, but don't use DHCP, and force the DNS server to our
DNS server. This allows DNS updates to run'''
self.get_ipconfig(child)
child.sendline('netsh')
child.sendline('offline')
child.sendline('interface ip set dns "${WIN_NIC}" static ${DNSSERVER} primary')
child.sendline('interface ip set address "${WIN_NIC}" static ${WIN_IPV4_ADDRESS} ${WIN_SUBNET_MASK} ${WIN_DEFAULT_GATEWAY} 1 store=persistent')
i = child.expect(["The syntax supplied for this command is not valid. Check help for the correct syntax", pexpect.EOF, pexpect.TIMEOUT], timeout=5)
if i == 0:
child.sendline('interface ip set address "${WIN_NIC}" static ${WIN_IPV4_ADDRESS} ${WIN_SUBNET_MASK} ${WIN_DEFAULT_GATEWAY} 1')
child.sendline('routing ip add persistentroute dest=0.0.0.0 mask=0.0.0.0 name="${WIN_NIC}" nhop=${WIN_DEFAULT_GATEWAY}')
child.sendline('online')
child.sendline('commit')
child.sendline('exit')
child.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=5)
def open_telnet(self, hostname, username, password, retries=60, delay=5, set_time=False, set_ip=False, disable_firewall=True):
'''open a telnet connection to a windows server, return the pexpect child''' '''open a telnet connection to a windows server, return the pexpect child'''
set_route = False
while retries > 0: while retries > 0:
child = self.pexpect_spawn("telnet " + hostname + " -l '" + username + "'") child = self.pexpect_spawn("telnet " + hostname + " -l '" + username + "'")
i = child.expect(["Welcome to Microsoft Telnet Service", i = child.expect(["Welcome to Microsoft Telnet Service",
"Denying new connections due to the limit on number of connections",
"No more connections are allowed to telnet server", "No more connections are allowed to telnet server",
"Unable to connect to remote host", "Unable to connect to remote host",
"No route to host"]) "No route to host",
"Connection refused"])
if i != 0: if i != 0:
child.close() child.close()
time.sleep(delay) time.sleep(delay)
@ -264,8 +315,19 @@ class wintest():
child.expect("password:") child.expect("password:")
child.sendline(password) child.sendline(password)
child.expect("C:") child.expect("C:")
if set_route:
child.sendline('route add 0.0.0.0 mask 0.0.0.0 ${WIN_DEFAULT_GATEWAY}')
child.expect("C:")
if set_time: if set_time:
self.run_date_time(child, None) self.run_date_time(child, None)
if disable_firewall:
self.disable_firewall(child)
if set_ip:
self.set_ip(child)
set_ip = False
set_time = False
set_route = True
continue
return child return child
raise RuntimeError("Failed to connect with telnet") raise RuntimeError("Failed to connect with telnet")