summaryrefslogtreecommitdiff
path: root/wintest
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-11-24 13:36:21 +1100
committerAndrew Tridgell <tridge@samba.org>2010-11-24 16:42:52 +1100
commitf207cc185f228490860151a35e2b94066120f335 (patch)
tree3fd69daea688f0fd97f9c27cb649211e959b4266 /wintest
parentb1dacb8195a52b6cfce6ad60a839f7effd35b261 (diff)
downloadsamba-f207cc185f228490860151a35e2b94066120f335.tar.gz
samba-f207cc185f228490860151a35e2b94066120f335.tar.bz2
samba-f207cc185f228490860151a35e2b94066120f335.zip
wintest: fixed interface handling and DNS forwarding
- allow for _IP vars on VMs - resolve IPs using nmblookup - forward DNS requests for windows domains
Diffstat (limited to 'wintest')
-rw-r--r--wintest/conf/abartlet.conf2
-rw-r--r--wintest/conf/tridge.conf5
-rwxr-xr-xwintest/test-s4-howto.py136
-rw-r--r--wintest/wintest.py40
4 files changed, 118 insertions, 65 deletions
diff --git a/wintest/conf/abartlet.conf b/wintest/conf/abartlet.conf
index fb0a5909bf..b632c6e027 100644
--- a/wintest/conf/abartlet.conf
+++ b/wintest/conf/abartlet.conf
@@ -19,7 +19,7 @@ INTERFACE : virbr0:0
# this is an additional IP that will be used for named to listen
# on. It should not be the primary IP of the interface
INTERFACE_IP : 192.168.122.2
-INTERFACE_NET : 192.168.122.0/24
+INTERFACE_NET : 192.168.122.2/24
# how to run bind9
BIND9 : /usr/sbin/named
diff --git a/wintest/conf/tridge.conf b/wintest/conf/tridge.conf
index f5081ed4eb..1c7ed0bda7 100644
--- a/wintest/conf/tridge.conf
+++ b/wintest/conf/tridge.conf
@@ -19,7 +19,7 @@ INTERFACE : virbr0:0
# this is an additional IP that will be used for named to listen
# on. It should not be the primary IP of the interface
INTERFACE_IP : 10.0.0.2
-INTERFACE_NET : 10.0.0.0/24
+INTERFACE_NET : 10.0.0.2/24
# how to run bind9
BIND9 : /usr/sbin/named
@@ -57,6 +57,8 @@ W2K8R2A_REALM : v2.tridgell.net
W2K8R2A_DOMAIN : v2
W2K8R2A_PASS : p@ssw0rd5
W2K8R2A_SNAPSHOT : howto-test
+W2K8R2A_IP : 10.0.0.4
+
# this w2k8r2 VM will become a DC in the samba domain
W2K8R2B_HOSTNAME : w2k8r2b
@@ -78,6 +80,7 @@ W2K3A_REALM : vsofs3.com
W2K3A_DOMAIN : vsofs3
W2K3A_PASS : penguin
W2K3A_SNAPSHOT : howto-test
+W2K3A_IP : 10.0.0.3
# this w2k3 VM will become a DC in the samba domain
W2K3B_HOSTNAME : w2k3b
diff --git a/wintest/test-s4-howto.py b/wintest/test-s4-howto.py
index ec96581e81..70a24189d7 100755
--- a/wintest/test-s4-howto.py
+++ b/wintest/test-s4-howto.py
@@ -12,7 +12,7 @@ def check_prerequesites(t):
if os.getuid() != 0:
raise Exception("You must run this script as root")
t.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
- t.run_cmd('ifconfig ${INTERFACE} ${INTERFACE_IP} up')
+ t.run_cmd('ifconfig ${INTERFACE} ${INTERFACE_NET} up')
def build_s4(t):
@@ -26,29 +26,27 @@ def build_s4(t):
t.run_cmd('make -j install')
-def provision_s4(t, func_level="2008", interface=None):
+def provision_s4(t, func_level="2008"):
'''provision s4 as a DC'''
t.info('Provisioning s4')
t.chdir('${PREFIX}')
t.del_files(["var", "etc", "private"])
options=' --function-level=%s -d${DEBUGLEVEL}' % func_level
- if interface:
- options += ' --option=interfaces=%s' % interface
- options += ' --host-ip=%s' % interface
+ options += ' --option=interfaces=${INTERFACE}'
+ options += ' --host-ip=${INTERFACE_IP} --host-ip6="::"'
t.run_cmd('sbin/provision --realm=${LCREALM} --domain=${DOMAIN} --adminpass=${PASSWORD1} --server-role="domain controller"' + options)
t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
-def start_s4(t, interface=None):
+def start_s4(t):
'''startup samba4'''
t.info('Starting Samba4')
t.chdir("${PREFIX}")
t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
t.run_cmd(['sbin/samba',
- '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"',
- '--option', 'interfaces=%s' % interface])
+ '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
t.port_wait("localhost", 139)
@@ -87,6 +85,31 @@ def create_shares(t):
t.run_cmd("mkdir -p var/profiles")
+def set_nameserver(t, nameserver):
+ '''set the nameserver in resolv.conf'''
+ if not getattr(t, 'resolv_conf_backup', False):
+ t.run_cmd("mv -f /etc/resolv.conf /etc/resolv.conf.wintest-bak")
+ t.write_file("/etc/resolv.conf", '''
+# Generated by wintest, the Samba v Windows automated testing system
+nameserver %s
+
+# your original resolv.conf appears below:
+
+''' % t.substitute(nameserver))
+ t.run_cmd('cat /etc/resolv.conf.wintest-bak >> /etc/resolv.conf')
+ t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
+
+
+def restore_resolv_conf(t):
+ '''restore the /etc/resolv.conf after testing is complete'''
+ if getattr(t, 'resolv_conf_backup', False):
+ t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
+
+def rndc_cmd(t, cmd, checkfail=True):
+ '''run a rndc command'''
+ t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf %s" % cmd, checkfail=checkfail)
+
+
def restart_bind(t):
'''restart the test environment version of bind'''
t.info("Restarting bind9")
@@ -127,13 +150,29 @@ key "rndc-key" {
};
controls {
- inet ${INTERFACE_IP}
+ inet ${INTERFACE_IP} port 953
allow { 127.0.0.0/8; ${INTERFACE_NET}; } keys { "rndc-key"; };
};
include "${PREFIX}/private/named.conf";
''')
+ # add forwarding for the windows domains
+ domains = t.get_domains()
+ for d in domains:
+ t.write_file('etc/named.conf',
+ '''
+zone "%s" IN {
+ type forward;
+ forward only;
+ forwarders {
+ %s;
+ };
+};
+''' % (d, domains[d]),
+ mode='a')
+
+
t.write_file("etc/rndc.conf", '''
# Start of rndc.conf
key "rndc-key" {
@@ -148,34 +187,14 @@ options {
};
''')
- t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf stop", checkfail=False)
+ set_nameserver(t, t.getvar('INTERFACE_IP'))
+
+ rndc_cmd(t, "stop", checkfail=False)
t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
- t.run_cmd("mv -f /etc/resolv.conf /etc/resolv.conf.wintest-bak")
- t.write_file("/etc/resolv.conf", '''
-# Generated by wintest, the Samba v Windows automated testing system
-
-nameserver ${INTERFACE_IP}
-
-# your original resolv.conf appears below:
-
-''')
-
- t.run_cmd('cat /etc/resolv.conf.wintest-bak >> /etc/resolv.conf')
-
- t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
-
t.port_wait("${INTERFACE_IP}", 53)
- t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf flush")
- t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf freeze")
- t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf thaw")
-
-
-def restore_resolv_conf(t):
- '''restore the /etc/resolv.conf after testing is complete'''
- if getattr(t, 'resolv_conf_backup', False):
- t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
+ rndc_cmd(t, "flush")
def test_dns(t):
@@ -200,7 +219,7 @@ def test_dyndns(t):
'''test that dynamic DNS is working'''
t.chdir('${PREFIX}')
t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
- t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf flush")
+ rndc_cmd(t, "flush")
def run_winjoin(t, vm):
@@ -210,14 +229,13 @@ def run_winjoin(t, vm):
t.info("Joining a windows box to the domain")
t.vm_poweroff("${WIN_VM}", checkfail=False)
t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
- t.ping_wait("${WIN_HOSTNAME}")
child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
child.expect("The command completed successfully")
child.expect("C:")
child.sendline("shutdown /r -t 0")
- t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
- t.port_wait("${WIN_HOSTNAME}", 139)
+ t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
+ t.port_wait("${WIN_IP}", 139)
child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
child.sendline("ipconfig /registerdns")
child.expect("Registration of the DNS resource records for all adapters of this computer has been initiated. Any errors will be reported in the Event Viewer")
@@ -227,7 +245,7 @@ def test_winjoin(t, vm):
t.setwinvars(vm)
t.info("Checking the windows join is OK")
t.chdir('${PREFIX}')
- t.port_wait("${WIN_HOSTNAME}", 139)
+ t.port_wait("${WIN_IP}", 139)
t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
@@ -246,7 +264,6 @@ def run_dcpromo(t, vm):
t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
t.vm_poweroff("${WIN_VM}", checkfail=False)
t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
- t.ping_wait("${WIN_HOSTNAME}")
child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
child.sendline("copy /Y con answers.txt")
child.sendline('''
@@ -275,8 +292,8 @@ SafeModeAdminPassword=${PASSWORD1}
i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
if i == 1 or i == 2:
raise Exception("dcpromo failed")
- t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
- t.port_wait("${WIN_HOSTNAME}", 139)
+ t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
+ t.port_wait("${WIN_IP}", 139)
def test_dcpromo(t, vm):
@@ -284,7 +301,7 @@ def test_dcpromo(t, vm):
t.setwinvars(vm)
t.info("Checking the dcpromo join is OK")
t.chdir('${PREFIX}')
- t.port_wait("${WIN_HOSTNAME}", 139)
+ t.port_wait("${WIN_IP}", 139)
t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
@@ -383,7 +400,6 @@ def run_dcpromo_rodc(t, vm):
t.info("Joining a w2k8 box to the domain as a RODC")
t.vm_poweroff("${WIN_VM}", checkfail=False)
t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
- t.ping_wait("${WIN_HOSTNAME}")
child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
child.sendline("copy /Y con answers.txt")
child.sendline('''
@@ -417,8 +433,8 @@ RebootOnCompletion=No
if i != 0:
raise Exception("dcpromo failed")
child.sendline("shutdown -r -t 0")
- t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
- t.port_wait("${WIN_HOSTNAME}", 139)
+ t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
+ t.port_wait("${WIN_IP}", 139)
@@ -427,7 +443,7 @@ def test_dcpromo_rodc(t, vm):
t.setwinvars(vm)
t.info("Checking the w2k8 RODC join is OK")
t.chdir('${PREFIX}')
- t.port_wait("${WIN_HOSTNAME}", 139)
+ t.port_wait("${WIN_IP}", 139)
t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
@@ -464,11 +480,12 @@ def join_as_dc(t, vm):
t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
t.vm_poweroff("${WIN_VM}", checkfail=False)
t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
- t.run_cmd('${RNDC} -c ${PREFIX}/etc/rndc.conf flush')
+ rndc_cmd(t, 'flush')
t.run_cmd("rm -rf etc private")
- t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True, set_ip=True)
+ child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
+ t.get_ipconfig(child)
t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
- t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}')
+ t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
@@ -533,11 +550,12 @@ def join_as_rodc(t, vm):
t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
t.vm_poweroff("${WIN_VM}", checkfail=False)
t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
- t.run_cmd('${RNDC} -c ${PREFIX}/etc/rndc.conf flush')
+ rndc_cmd(t, 'flush')
t.run_cmd("rm -rf etc private")
- t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True, set_ip=True)
+ child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
+ t.get_ipconfig(child)
t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
- t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}')
+ t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
@@ -608,13 +626,13 @@ def test_howto(t):
build_s4(t)
if not t.skip("provision"):
- provision_s4(t, interface='${INTERFACE_IP}')
+ provision_s4(t)
if not t.skip("create-shares"):
create_shares(t)
if not t.skip("starts4"):
- start_s4(t, interface='${INTERFACE_IP}')
+ start_s4(t)
if not t.skip("smbclient"):
test_smbclient(t)
if not t.skip("startbind"):
@@ -652,9 +670,9 @@ def test_howto(t):
if t.have_var('W2K3B_VM') and not t.skip("dcpromo_w2k3"):
t.info("Testing w2k3 dcpromo")
t.info("Changing to 2003 functional level")
- provision_s4(t, func_level='2003', interfaces='${INTERFACES}')
+ provision_s4(t, func_level='2003')
create_shares(t)
- start_s4(t, interfaces='${INTERFACES}')
+ start_s4(t)
test_smbclient(t)
restart_bind(t)
test_dns(t)
@@ -666,21 +684,21 @@ def test_howto(t):
if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
join_as_dc(t, "W2K8R2A")
create_shares(t)
- start_s4(t, interfaces='${INTERFACES}')
+ start_s4(t)
test_dyndns(t)
test_join_as_dc(t, "W2K8R2A")
if t.have_var('W2K8R2A_VM') and not t.skip("join_rodc"):
join_as_rodc(t, "W2K8R2A")
create_shares(t)
- start_s4(t, interfaces='${INTERFACES}')
+ start_s4(t)
test_dyndns(t)
test_join_as_rodc(t, "W2K8R2A")
if t.have_var('W2K3A_VM') and not t.skip("join_w2k3"):
join_as_dc(t, "W2K3A")
create_shares(t)
- start_s4(t, interfaces='${INTERFACES}')
+ start_s4(t)
test_dyndns(t)
test_join_as_dc(t, "W2K3A")
diff --git a/wintest/wintest.py b/wintest/wintest.py
index d7ca5fe067..659b15ec43 100644
--- a/wintest/wintest.py
+++ b/wintest/wintest.py
@@ -19,11 +19,13 @@ class wintest():
def getvar(self, varname):
'''return a substitution variable'''
+ if not varname in self.vars:
+ return None
return self.vars[varname]
def setwinvars(self, vm, prefix='WIN'):
'''setup WIN_XX vars based on a vm name'''
- for v in ['VM', 'HOSTNAME', 'USER', 'PASS', 'SNAPSHOT', 'BASEDN', 'REALM', 'DOMAIN']:
+ for v in ['VM', 'HOSTNAME', 'USER', 'PASS', 'SNAPSHOT', 'BASEDN', 'REALM', 'DOMAIN', 'IP']:
vname = '%s_%s' % (vm, v)
if vname in self.vars:
self.setvar("%s_%s" % (prefix,v), self.substitute("${%s}" % vname))
@@ -343,13 +345,32 @@ class wintest():
child.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=5)
return True
-
- def open_telnet(self, hostname, username, password, retries=60, delay=5, set_time=False, set_ip=False, disable_firewall=True, run_tlntadmn=True):
+
+
+ def resolve_ip(self, hostname, retries=60, delay=5):
+ '''resolve an IP given a hostname, assuming NBT'''
+ while retries > 0:
+ child = self.pexpect_spawn("bin/nmblookup %s" % hostname)
+ i = child.expect(['\d+.\d+.\d+.\d+', "Lookup failed"])
+ if i == 0:
+ return child.after
+ retries -= 1
+ time.sleep(delay)
+ raise RuntimeError("Failed to resolve IP of %s" % hostname)
+
+
+ def open_telnet(self, hostname, username, password, retries=60, delay=5, set_time=False, set_ip=False,
+ disable_firewall=True, run_tlntadmn=True):
'''open a telnet connection to a windows server, return the pexpect child'''
set_route = False
set_dns = False
+ if self.getvar('WIN_IP'):
+ ip = self.getvar('WIN_IP')
+ else:
+ ip = self.resolve_ip(hostname)
+ self.setvar('WIN_IP', ip)
while retries > 0:
- child = self.pexpect_spawn("telnet " + hostname + " -l '" + username + "'")
+ child = self.pexpect_spawn("telnet " + ip + " -l '" + username + "'")
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",
@@ -415,3 +436,14 @@ class wintest():
child.expect("Password for")
child.sendline(password)
child.expect("Authenticated to Kerberos")
+
+
+ def get_domains(self):
+ '''return a dictionary of DNS domains and IPs for named.conf'''
+ ret = {}
+ for v in self.vars:
+ if v[-6:] == "_REALM":
+ base = v[:-6]
+ if base + '_IP' in self.vars:
+ ret[self.vars[base + '_REALM']] = self.vars[base + '_IP']
+ return ret