s3-param: Add "server role" as global parameter
[samba.git] / wintest / wintest.py
index af4588f5c8ee988fbc5a9466c15a5972082e69e3..d5728a883b5a7a9d2548b21175cacfdeeea510a4 100644 (file)
@@ -13,7 +13,7 @@ class wintest():
         self.vars = {}
         self.list_mode = False
         self.vms = None
-        os.putenv('PYTHONUNBUFFERED', '1')
+        os.environ['PYTHONUNBUFFERED'] = '1'
         self.parser = optparse.OptionParser("wintest")
 
     def check_prerequesites(self):
@@ -57,6 +57,8 @@ class wintest():
             self.setvar("WIN_LCREALM", self.getvar("WIN_REALM").lower())
             dnsdomain = self.getvar("WIN_REALM")
             self.setvar("WIN_BASEDN", "DC=" + dnsdomain.replace(".", ",DC="))
+        if self.getvar("WIN_USER") is None:
+            self.setvar("WIN_USER", "administrator")
 
     def info(self, msg):
         '''print some information'''
@@ -88,7 +90,10 @@ class wintest():
     def set_vms(self, vms):
         '''set a list of VMs to test'''
         if vms is not None:
-            self.vms = vms.split(',')
+            self.vms = []
+            for vm in vms.split(','):
+                vm = vm.upper()
+                self.vms.append(vm)
 
     def skip(self, step):
         '''return True if we should skip a step'''
@@ -137,7 +142,7 @@ class wintest():
 
     def putenv(self, key, value):
         '''putenv with substitution'''
-        os.putenv(key, self.substitute(value))
+        os.environ[key] = self.substitute(value)
 
     def chdir(self, dir):
         '''chdir with substitution'''
@@ -343,7 +348,6 @@ nameserver %s
                          '''tkey-gssapi-credential "DNS/${LCREALM}";
                             tkey-domain "${LCREALM}";
                  ''')
-            self.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
             self.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
             self.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
 
@@ -444,7 +448,7 @@ options {
         self.rndc_cmd("flush")
 
     def restart_bind(self, kerberos_support=False, include=None):
-        self.configure_bind(keberos_support=kerberos_support, include=include)
+        self.configure_bind(kerberos_support=kerberos_support, include=include)
         self.stop_bind()
         self.start_bind()
 
@@ -559,7 +563,7 @@ options {
             return True
 
     def set_noexpire(self, child, username):
-        '''Ensure this user's password does not expire'''
+        """Ensure this user's password does not expire"""
         child.sendline('wmic useraccount where name="%s" set PasswordExpires=FALSE' % username)
         child.expect("update successful")
         child.expect("C:")
@@ -567,13 +571,13 @@ options {
     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(["The settings were successfully updated", "Access is denied"])
         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"])
+        i = child.expect(["Ok", "The following command was not found: advfirewall set allprofiles state off", "The requested operation requires elevation"])
         child.expect("C:")
         if i == 1:
             child.sendline('netsh firewall set opmode mode = DISABLE profile = ALL')
@@ -581,7 +585,7 @@ options {
             if i != 0:
                 self.info("Firewall disable failed - ignoring")
             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)
@@ -621,8 +625,12 @@ options {
         '''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:
+            i = 0
+            while i == 0:
+                i = child.expect(["querying", '\d+.\d+.\d+.\d+', hostname, "Lookup failed"])
+                if i == 0:
+                    child.expect("\r")
+            if i == 1:
                 return child.after
             retries -= 1
             time.sleep(delay)
@@ -802,6 +810,47 @@ RebootOnCompletion=No
         child.sendline("shutdown -r -t 0")
         self.port_wait("${WIN_IP}", 139, wait_for_fail=True)
         self.port_wait("${WIN_IP}", 139)
+        self.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
+
+
+    def start_winvm(self, vm):
+        '''start a Windows VM'''
+        self.setwinvars(vm)
+        
+        self.info("Joining a windows box to the domain")
+        self.vm_poweroff("${WIN_VM}", checkfail=False)
+        self.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
+
+    def run_winjoin(self, vm, domain, username="administrator", password="${PASSWORD1}"):
+        '''join a windows box to a domain'''
+        child = self.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True, set_noexpire=True)
+        child.sendline("ipconfig /flushdns")
+        child.expect("C:")
+        child.sendline("netdom join ${WIN_HOSTNAME} /Domain:%s /UserD:%s /PasswordD:%s" % (domain, username, password))
+        child.expect("The command completed successfully")
+        child.expect("C:")
+        child.sendline("shutdown /r -t 0")
+        self.wait_reboot()
+        child = self.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_remote_smbclient(self, vm, username="${WIN_USER}", password="${WIN_PASS}", args=""):
+        '''test smbclient against remote server'''
+        self.setwinvars(vm)
+        self.info('Testing smbclient')
+        self.chdir('${PREFIX}')
+        self.cmd_contains("bin/smbclient --version", ["${SAMBA_VERSION}"])
+        self.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME} -U%s%%%s %s' % (username, password, args), ["IPC"])
+
+    def test_net_use(self, vm, domain, username, password):
+        self.setwinvars(vm)
+        self.info('Testing net use against Samba3 member')
+        child = self.open_telnet("${WIN_HOSTNAME}", "%s\\%s" % (domain, username), password)
+        child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
+        child.expect("The command completed successfully")
 
 
     def setup(self, testname, subdir):