[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Tue Nov 23 00:31:01 MST 2010


The branch, master has been updated
       via  95edbc3 wintest Evolve wintest to handle it's own BIND nameserver
       via  be0f412 wintest Improve wintest's handling of IP addresses and add more auto-setup
       via  39c2fd1 wintest Explian that this is my KVM/libvirt configuration
       via  41f1e32 wintest example configuration file for a KVM based wintest
       via  e77ea04 wintest Allow substitute to cope with objects like pexpect.EOF
       via  5767ee9 wintest Set the virtual machine IP to match it's dynamic IP, but don't use DHCP
       via  c251c45 wintest Force krb5.conf for BIND so we use the one generated for this test
      from  568a237 s3: Add a word of warning about "winbind use default domain"

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 95edbc382d8167b59a79a570aff664ba806de809
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Nov 23 17:38:31 2010 +1100

    wintest Evolve wintest to handle it's own BIND nameserver
    
    The changes here start our own copy of BIND, listening on a new
    interface that we create at the start of the script.  The user must
    specify the IP address etc that this interface will have, and BIND and
    Samba will bind to that interface only.
    
    This means that we won't conflict with an existing BIND on the system,
    so long as it isn't configured to listen on all interfaces.
    
    We also auto-create the /etc/resolv.conf and restore it at the end of
    the script, using the existing server value from the script as a
    forwarder.
    
    Andrew Bartlett
    
    Autobuild-User: Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date: Tue Nov 23 08:30:34 CET 2010 on sn-devel-104

commit be0f4129a165c0fbfa363f87b52ce733dba4e4bc
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Nov 23 15:04:31 2010 +1100

    wintest Improve wintest's handling of IP addresses and add more auto-setup
    
     - Don't change the IP address if DHCP is not in use
    
       The main reason to 'fix' the IP is to get around Dynamic DNS issues caused
       by the DHCP server, if the VM is already on a fixed IP, it does not matter.
    
     - Set the maximum telnet connection limit to 1024
    
       This ensures that we can always make a new connection, regardless
       of the existing configuration.  We also catch more conditions when
       the server has restricted the number of connections, and try again.
    
     - Set the route after the connection drops out
    
       My WinXP box always wants to drop the default route
    
     - Set the DNS as a distinct step
    
       My WinXP box drops the connection when we set DNS servers
    
    Andrew Bartlett

commit 39c2fd1c6462aaa91132ef10fbb51254a133864c
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Nov 23 15:02:30 2010 +1100

    wintest Explian that this is my KVM/libvirt configuration

commit 41f1e3242cf73ff93dafe30e2c80ad6438cb0469
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Nov 22 21:26:13 2010 +1100

    wintest example configuration file for a KVM based wintest
    
    Andrew Bartlett

commit e77ea04872dbd4dfab2c798a0b434e8211cd818b
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Nov 22 21:24:56 2010 +1100

    wintest Allow substitute to cope with objects like pexpect.EOF
    
    These are not strings, but may get passed into this function on the
    way to pexpect.
    
    Andrew Bartlett

commit 5767ee96636470b32c7c819bbef75d06fe1004e6
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Nov 22 21:23:38 2010 +1100

    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

commit c251c45e7f97128e1066d788ad7fe254f2b64474
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Nov 22 21:21:57 2010 +1100

    wintest Force krb5.conf for BIND so we use the one generated for this test
    
    This avoids needing to set the krb5.conf for the whole host to match
    the test environment.
    
    Andrew Bartlett

-----------------------------------------------------------------------

Summary of changes:
 wintest/conf/abartlet.conf |   60 ++++++++++++++++++
 wintest/test-s4-howto.py   |  144 +++++++++++++++++++++++++++++++++++---------
 wintest/wintest.py         |  145 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 316 insertions(+), 33 deletions(-)
 create mode 100644 wintest/conf/abartlet.conf


Changeset truncated at 500 lines:

diff --git a/wintest/conf/abartlet.conf b/wintest/conf/abartlet.conf
new file mode 100644
index 0000000..ea8a5cf
--- /dev/null
+++ b/wintest/conf/abartlet.conf
@@ -0,0 +1,60 @@
+# config file for test-howto.py for abartlet's KVM based setup (using libvirt)
+
+# where the git checkout is
+SOURCETREE            : /data/samba/howto/git
+
+# where to install Samba to
+PREFIX                : /data/samba/howto/prefix
+
+# debug level which will be put in smb.conf
+DEBUGLEVEL	      : 1
+
+# commands to control VMs
+VM_POWEROFF           : virsh destroy ${VMNAME}
+VM_RESTORE            : virsh snapshot-revert ${VMNAME} ${SNAPSHOT}
+
+# interfaces to create
+INTERFACE            : virbr0:0
+INTERFACE_IP          : 192.168.122.2
+INTERFACE_NET          : 192.168.122.0/24
+
+# how to run bind9
+BIND9	              : /usr/sbin/named
+RNDC	              : /usr/sbin/rndc
+BIND_USER             : named
+
+# provision information
+REALM                 : S4.HOWTO.ABARTLET.NET
+LCREALM               : s4.howto.abartlet.net
+DOMAIN                : s4-howto
+BASEDN                : DC=S4,DC=howto,DC=abartlet,DC=net
+PASSWORD1             : p at ssw0rd
+PASSWORD2             : p at ssw0rd2
+PASSWORD3             : p at ssw0rd3
+
+# a Windows7 VM
+WINDOWS7_HOSTNAME     : Windows7-1
+WINDOWS7_VM           : Windows7-1
+WINDOWS7_SNAPSHOT     : 1290389594
+WINDOWS7_USER         : administrator
+WINDOWS7_PASS         : penguin
+
+# a winxp VM - needs Windows XP Service Pack 2 Support Tools
+WINXP_HOSTNAME        : WinXP-1
+WINXP_VM              : WinXP-1
+WINXP_SNAPSHOT        : 1290386227
+WINXP_USER            : administrator
+WINXP_PASS            : penguin
+
+# Samba will join this w2k8r2 VM as a DC and then as a RODC
+W2K8R2B_HOSTNAME      : Win2008R2-1
+W2K8R2B_VM            : Win2008R2-1
+W2K8R2B_PASS          : penguin12#
+W2K8R2B_SNAPSHOT      : 1290382773
+
+# Samba will join this w2k3 VM as a DC
+W2K3B_HOSTNAME        : Win2003R2-1
+W2K3B_VM              : Win2003R2-1
+W2K3B_PASS            : penguin
+W2K3B_SNAPSHOT        : 1290386298
+
diff --git a/wintest/test-s4-howto.py b/wintest/test-s4-howto.py
index b925973..b28370a 100755
--- a/wintest/test-s4-howto.py
+++ b/wintest/test-s4-howto.py
@@ -11,8 +11,8 @@ def check_prerequesites(t):
     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"])
-
+    t.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
+    t.run_cmd('ifconfig ${INTERFACE} ${INTERFACE_IP} up')
 
 def build_s4(t):
     '''build samba4'''
@@ -24,26 +24,27 @@ 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", interface=None):
     '''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 interfaces:
-        options += ' --option=interfaces=%s' % interfaces
+    if interface:
+        options += ' --option=interfaces=%s' % interface
+        options += ' --host-ip=%s' % interface
     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, interfaces=None):
+def start_s4(t, interface=None):
     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])
+             '--option', 'interfaces=%s' % interface])
     t.port_wait("localhost", 139)
 
 def test_smbclient(t):
@@ -82,13 +83,88 @@ 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")
+    t.chdir('${PREFIX}')
+    t.run_cmd("mkdir -p var/named/data")
+    t.run_cmd("chown -R ${BIND_USER} var/named")
+
+    nameserver = t.get_nameserver()
+    if nameserver == t.vars['INTERFACE_IP']:
+        raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration")
+    t.setvar('DNSSERVER', nameserver)
+
+    t.write_file("etc/named.conf", '''
+options {
+	listen-on port 53 { ${INTERFACE_IP}; };
+	directory 	"${PREFIX}/var/named";
+	dump-file 	"${PREFIX}/var/named/data/cache_dump.db";
+	pid-file 	"${PREFIX}/var/named/named.pid";
+        statistics-file "${PREFIX}/var/named/data/named_stats.txt";
+        memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
+	allow-query     { ${INTERFACE_NET}; 127.0.0.0/8; };
+	recursion yes;
+	tkey-gssapi-credential "DNS/${LCREALM}";
+	tkey-domain "${REALM}";
+
+	forward only;
+	forwarders {
+		  ${DNSSERVER};
+	};
+
+};
+
+key "rndc-key" {
+ 	algorithm hmac-md5;
+ 	secret "lA/cTrno03mt5Ju17ybEYw==";
+};
+ 
+controls {
+ 	inet ${INTERFACE_IP}
+	allow { 127.0.0.0/8; ${INTERFACE_NET}; } keys { "rndc-key"; };
+};
+
+include "${PREFIX}/private/named.conf";
+''')
+
+    t.write_file("etc/rndc.conf", '''
+# Start of rndc.conf
+key "rndc-key" {
+	algorithm hmac-md5;
+	secret "lA/cTrno03mt5Ju17ybEYw==";
+};
+
+options {
+	default-key "rndc-key";
+	default-server  ${INTERFACE_IP};
+	default-port 953;
+};
+''')
+   
+    t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf stop", checkfail=False)
+    t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
+    t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -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):
+    if getattr(t, 'resolv_conf_backup', False):
+        t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
 
 def test_dns(t):
     t.info("Testing DNS")
@@ -109,7 +185,7 @@ def test_kerberos(t):
 def test_dyndns(t):
     t.chdir('${PREFIX}')
     t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
-    t.run_cmd("${RNDC} flush")
+    t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf flush")
 
 
 def run_winjoin(t, vm):
@@ -119,20 +195,24 @@ def run_winjoin(t, vm):
     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 = 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)
-
+    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")
+    child.expect("C:")
 
 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.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"])
@@ -151,7 +231,7 @@ def run_dcpromo(t, vm):
     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]
@@ -176,8 +256,8 @@ 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)
@@ -286,7 +366,7 @@ def run_dcpromo_rodc(t, vm):
     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]
@@ -361,9 +441,9 @@ 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} flush')
+    t.run_cmd('${RNDC} -c ${PREFIX}/etc/rndc.conf flush')
     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.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}')
@@ -428,9 +508,9 @@ 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} flush')
+    t.run_cmd('${RNDC} -c ${PREFIX}/etc/rndc.conf flush')
     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.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}')
@@ -502,13 +582,13 @@ def test_howto(t):
         build_s4(t)
 
     if not t.skip("provision"):
-        provision_s4(t)
+        provision_s4(t, interface='${INTERFACE_IP}')
 
     if not t.skip("create-shares"):
         create_shares(t)
 
     if not t.skip("starts4"):
-        start_s4(t, interfaces='${INTERFACES}')
+        start_s4(t, interface='${INTERFACE_IP}')
     if not t.skip("smbclient"):
         test_smbclient(t)
     if not t.skip("startbind"):
@@ -620,4 +700,10 @@ if __name__ == '__main__':
         t.chdir('${SOURCETREE}/source4')
         t.run_cmd('rm -rf bin')
 
-    test_howto(t)
+    try:
+        test_howto(t)
+    except Exception, str:
+        restore_resolv_conf(t)
+        if getattr(t, 'bind_child', False):
+            t.bind_child.kill()
+        raise
diff --git a/wintest/wintest.py b/wintest/wintest.py
index 5706f88..4c93017 100644
--- a/wintest/wintest.py
+++ b/wintest/wintest.py
@@ -70,6 +70,9 @@ class wintest():
                 ret[i] = self.substitute(ret[i])
             return ret
 
+        """We may have objects such as pexpect.EOF that are not strings"""
+        if not isinstance(text, str):
+            return text
         while True:
             var_start = text.find("${")
             if var_start == -1:
@@ -124,6 +127,21 @@ class wintest():
         else:
             return subprocess.call(cmd, shell=shell, cwd=dir)
 
+    def run_child(self, cmd, dir="."):
+        cwd = os.getcwd()
+        cmd = self.substitute(cmd)
+        if isinstance(cmd, list):
+            self.info('$ ' + " ".join(cmd))
+        else:
+            self.info('$ ' + cmd)
+        if isinstance(cmd, list):
+            shell=False
+        else:
+            shell=True
+        os.chdir(dir)
+        ret = subprocess.Popen(cmd, shell=shell)
+        os.chdir(cwd)
+        return ret
 
     def cmd_output(self, cmd):
         '''return output from and command'''
@@ -197,6 +215,13 @@ class wintest():
 
         return ret
 
+    def get_nameserver(self):
+        '''Get the current nameserver from /etc/resolv.conf'''
+        child = self.pexpect_spawn('cat /etc/resolv.conf')
+        child.expect('nameserver')
+        child.expect('\d+.\d+.\d+.\d+')
+        return child.after
+
     def vm_poweroff(self, vmname, checkfail=True):
         '''power off a VM'''
         self.setvar('VMNAME', vmname)
@@ -240,22 +265,102 @@ class wintest():
             time_tuple = time.localtime()
         child.sendline("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.sendline("time")
         child.expect("Enter the new time:")
         child.sendline(time.strftime("%H:%M:%S", time_tuple))
         child.expect("C:")
 
+    def get_ipconfig(self, child):
+        '''get the IP configuration of the child'''
+        child.sendline("ipconfig /all")
+        child.expect('Ethernet adapter ')
+        child.expect("[\w\s]+")
+        self.setvar("WIN_NIC", child.after)
+        child.expect(['DHCP Enabled', 'Dhcp Enabled'])
+        i = child.expect(['Yes', 'No'])
+        if i == 0:
+            self.setvar("WIN_DHCP", True)
+        else:
+            self.setvar("WIN_DHCP", False)
+        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)
+        child.expect("C:")
 
-    def open_telnet(self, hostname, username, password, retries=60, delay=5, set_time=False):
+    def run_tlntadmn(self, child):
+        '''remove the annoying telnet restrictions'''
+        child.sendline('tlntadmn config maxconn=1024')
+        child.expect("The settings were successfully updated")
+        child.expect("C:")
+
+    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_dns(self, child):
+        child.sendline('netsh interface ip set dns "${WIN_NIC}" static ${INTERFACE_IP} primary')
+        i = child.expect(['C:', pexpect.EOF, pexpect.TIMEOUT], timeout=5)
+        if i > 0:
+            return True
+        else:
+            return False
+
+    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)
+        if self.vars['WIN_DHCP'] is False:
+            return False
+        child.sendline('netsh')
+        child.expect('netsh>')
+        child.sendline('offline')
+        child.expect('netsh>')
+        child.sendline('routing ip add persistentroute dest=0.0.0.0 mask=0.0.0.0 name="${WIN_NIC}" nhop=${WIN_DEFAULT_GATEWAY}')
+        child.expect('netsh>')
+        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', 'netsh>', 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.expect('netsh>')
+        child.sendline('commit')
+        child.sendline('online')
+        child.sendline('exit')
+
+        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):
         '''open a telnet connection to a windows server, return the pexpect child'''
+        set_route = False
+        set_dns = False
         while retries > 0:
             child = self.pexpect_spawn("telnet " + hostname + " -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",
                               "Unable to connect to remote host",
-                              "No route to host"])
+                              "No route to host",
+                              "Connection refused",
+                              pexpect.EOF])
             if i != 0:
                 child.close()
                 time.sleep(delay)
@@ -263,9 +368,41 @@ class wintest():
                 continue
             child.expect("password:")
             child.sendline(password)
-            child.expect("C:")
+            i = child.expect(["C:",
+                              "Denying new connections due to the limit on number of connections",
+                              "No more connections are allowed to telnet server",
+                              "Unable to connect to remote host",
+                              "No route to host",
+                              "Connection refused",
+                              pexpect.EOF])
+            if i != 0:
+                child.close()
+                time.sleep(delay)
+                retries -= 1


-- 
Samba Shared Repository


More information about the samba-cvs mailing list