Changeset 988 for vendor/current/wintest/wintest.py
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/wintest/wintest.py
r740 r988 26 26 self.run_cmd('ifconfig ${INTERFACE} inet6 del ${INTERFACE_IPV6}/64', checkfail=False) 27 27 self.run_cmd('ifconfig ${INTERFACE} inet6 add ${INTERFACE_IPV6}/64 up') 28 29 self.run_cmd('ifconfig ${NAMED_INTERFACE} ${NAMED_INTERFACE_NET} up') 30 if self.getvar('NAMED_INTERFACE_IPV6'): 31 self.run_cmd('ifconfig ${NAMED_INTERFACE} inet6 del ${NAMED_INTERFACE_IPV6}/64', checkfail=False) 32 self.run_cmd('ifconfig ${NAMED_INTERFACE} inet6 add ${NAMED_INTERFACE_IPV6}/64 up') 28 33 29 34 def stop_vms(self): … … 326 331 self.chdir('${PREFIX}') 327 332 328 nameserver = self.get_nameserver() 329 if nameserver == self.getvar('INTERFACE_IP'): 330 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration" % nameserver) 331 self.setvar('DNSSERVER', nameserver) 332 333 if self.getvar('INTERFACE_IPV6'): 334 ipv6_listen = 'listen-on-v6 port 53 { ${INTERFACE_IPV6}; };' 333 if self.getvar('NAMED_INTERFACE_IPV6'): 334 ipv6_listen = 'listen-on-v6 port 53 { ${NAMED_INTERFACE_IPV6}; };' 335 335 else: 336 336 ipv6_listen = '' … … 339 339 if not kerberos_support: 340 340 self.setvar("NAMED_TKEY_OPTION", "") 341 el se:341 elif self.getvar('NAMESERVER_BACKEND') != 'SAMBA_INTERNAL': 342 342 if self.named_supports_gssapi_keytab(): 343 343 self.setvar("NAMED_TKEY_OPTION", … … 351 351 self.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab') 352 352 self.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab') 353 354 if include: 353 else: 354 self.setvar("NAMED_TKEY_OPTION", "") 355 356 if include and self.getvar('NAMESERVER_BACKEND') != 'SAMBA_INTERNAL': 355 357 self.setvar("NAMED_INCLUDE", 'include "%s";' % include) 356 358 else: … … 361 363 self.write_file("etc/named.conf", ''' 362 364 options { 363 listen-on port 53 { ${ INTERFACE_IP}; };365 listen-on port 53 { ${NAMED_INTERFACE_IP}; }; 364 366 ${BIND_LISTEN_IPV6} 365 367 directory "${PREFIX}/var/named"; … … 387 389 388 390 controls { 389 inet ${ INTERFACE_IP} port 953391 inet ${NAMED_INTERFACE_IP} port 953 390 392 allow { any; } keys { "rndc-key"; }; 391 393 }; … … 393 395 ${NAMED_INCLUDE} 394 396 ''') 397 398 if self.getvar('NAMESERVER_BACKEND') == 'SAMBA_INTERNAL': 399 self.write_file('etc/named.conf', 400 ''' 401 zone "%s" IN { 402 type forward; 403 forward only; 404 forwarders { 405 %s; 406 }; 407 }; 408 ''' % (self.getvar('LCREALM'), self.getvar('INTERFACE_IP')), 409 mode='a') 410 395 411 396 412 # add forwarding for the windows domains 397 413 domains = self.get_domains() 414 398 415 for d in domains: 399 416 self.write_file('etc/named.conf', … … 419 436 options { 420 437 default-key "rndc-key"; 421 default-server ${ INTERFACE_IP};438 default-server ${NAMED_INTERFACE_IP}; 422 439 default-port 953; 423 440 }; … … 428 445 '''Stop our private BIND from listening and operating''' 429 446 self.rndc_cmd("stop", checkfail=False) 430 self.port_wait("${ INTERFACE_IP}", 53, wait_for_fail=True)447 self.port_wait("${NAMED_INTERFACE_IP}", 53, wait_for_fail=True) 431 448 432 449 self.run_cmd("rm -rf var/named") … … 438 455 self.chdir('${PREFIX}') 439 456 440 self.set_nameserver(self.getvar(' INTERFACE_IP'))457 self.set_nameserver(self.getvar('NAMED_INTERFACE_IP')) 441 458 442 459 self.run_cmd("mkdir -p var/named/data") … … 445 462 self.bind_child = self.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g") 446 463 447 self.port_wait("${ INTERFACE_IP}", 53)464 self.port_wait("${NAMED_INTERFACE_IP}", 53) 448 465 self.rndc_cmd("flush") 449 466 … … 492 509 def port_wait(self, hostname, port, retries=200, delay=3, wait_for_fail=False): 493 510 '''wait for a host to come up on the network''' 494 self.retry_cmd("nc -v -z -w 1 %s %u" % (hostname, port), ['succeeded'], 495 retries=retries, delay=delay, wait_for_fail=wait_for_fail) 511 512 while retries > 0: 513 child = self.pexpect_spawn("nc -v -z -w 1 %s %u" % (hostname, port), crlf=False, timeout=1) 514 child.expect([pexpect.EOF, pexpect.TIMEOUT]) 515 child.close() 516 i = child.exitstatus 517 if wait_for_fail: 518 #wait for timeout or fail 519 if i == None or i > 0: 520 return 521 else: 522 if i == 0: 523 return 524 525 time.sleep(delay) 526 retries -= 1 527 self.info("retrying (retries=%u delay=%u)" % (retries, delay)) 528 529 raise RuntimeError("gave up waiting for %s:%d" % (hostname, port)) 496 530 497 531 def run_net_time(self, child): … … 532 566 self.setvar('WIN_SUBNET_MASK', child.after) 533 567 child.expect('Default Gateway') 534 child.expect('\d+.\d+.\d+.\d+') 535 self.setvar('WIN_DEFAULT_GATEWAY', child.after) 536 child.expect("C:") 568 i = child.expect(['\d+.\d+.\d+.\d+', "C:"]) 569 if i == 0: 570 self.setvar('WIN_DEFAULT_GATEWAY', child.after) 571 child.expect("C:") 537 572 538 573 def get_is_dc(self, child): 539 574 '''check if a windows machine is a domain controller''' 540 575 child.sendline("dcdiag") 541 i = child.expect(["is not a Directory Server",576 i = child.expect(["is not a [Directory Server|DC]", 542 577 "is not recognized as an internal or external command", 543 578 "Home Server = ", … … 564 599 565 600 def set_noexpire(self, child, username): 566 '''Ensure this user's password does not expire'''601 """Ensure this user's password does not expire""" 567 602 child.sendline('wmic useraccount where name="%s" set PasswordExpires=FALSE' % username) 568 603 child.expect("update successful") … … 572 607 '''remove the annoying telnet restrictions''' 573 608 child.sendline('tlntadmn config maxconn=1024') 574 child.expect( "The settings were successfully updated")609 child.expect(["The settings were successfully updated", "Access is denied"]) 575 610 child.expect("C:") 576 611 … … 578 613 '''remove the annoying firewall''' 579 614 child.sendline('netsh advfirewall set allprofiles state off') 580 i = child.expect(["Ok", "The following command was not found: advfirewall set allprofiles state off" ])615 i = child.expect(["Ok", "The following command was not found: advfirewall set allprofiles state off", "The requested operation requires elevation", "Access is denied"]) 581 616 child.expect("C:") 582 617 if i == 1: 583 618 child.sendline('netsh firewall set opmode mode = DISABLE profile = ALL') 584 i = child.expect(["Ok", "The following command was not found" ])619 i = child.expect(["Ok", "The following command was not found", "Access is denied"]) 585 620 if i != 0: 586 621 self.info("Firewall disable failed - ignoring") … … 588 623 589 624 def set_dns(self, child): 590 child.sendline('netsh interface ip set dns "${WIN_NIC}" static ${ INTERFACE_IP} primary')625 child.sendline('netsh interface ip set dns "${WIN_NIC}" static ${NAMED_INTERFACE_IP} primary') 591 626 i = child.expect(['C:', pexpect.EOF, pexpect.TIMEOUT], timeout=5) 592 627 if i > 0: … … 644 679 set_route = False 645 680 set_dns = False 681 set_telnetclients = True 682 start_telnet = True 646 683 if self.getvar('WIN_IP'): 647 684 ip = self.getvar('WIN_IP') … … 667 704 child.sendline(password) 668 705 i = child.expect(["C:", 706 "TelnetClients", 669 707 "Denying new connections due to the limit on number of connections", 670 708 "No more connections are allowed to telnet server", … … 673 711 "Connection refused", 674 712 pexpect.EOF]) 713 if i == 1: 714 if set_telnetclients: 715 self.run_cmd('bin/net rpc group add TelnetClients -S $WIN_IP -U$WIN_USER%$WIN_PASS') 716 self.run_cmd('bin/net rpc group addmem TelnetClients "authenticated users" -S $WIN_IP -U$WIN_USER%$WIN_PASS') 717 child.close() 718 retries -= 1 719 set_telnetclients = False 720 self.info("retrying (retries=%u delay=%u)" % (retries, delay)) 721 continue 722 else: 723 raise RuntimeError("Failed to connect with telnet due to missing TelnetClients membership") 724 725 if i == 6: 726 # This only works if it is installed and enabled, but not started. Not entirely likely, but possible 727 self.run_cmd('bin/net rpc service start TlntSvr -S $WIN_IP -U$WIN_USER%$WIN_PASS') 728 child.close() 729 start_telnet = False 730 retries -= 1 731 self.info("retrying (retries=%u delay=%u)" % (retries, delay)) 732 continue 733 675 734 if i != 0: 676 735 child.close() … … 805 864 child.expect("C:") 806 865 child.sendline("dcpromo /answer:answers.txt") 807 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:" ], timeout=240)866 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:", pexpect.TIMEOUT], timeout=240) 808 867 if i == 1 or i == 2: 809 868 raise Exception("dcpromo failed") 869 if i == 4: # timeout 870 child = self.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}") 871 810 872 child.sendline("shutdown -r -t 0") 811 873 self.port_wait("${WIN_IP}", 139, wait_for_fail=True) 812 874 self.port_wait("${WIN_IP}", 139) 813 self.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] ) 875 876 child = self.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}") 877 # Check if we became a DC by now 878 if not self.get_is_dc(child): 879 raise Exception("dcpromo failed (and wasn't a DC even after rebooting)") 880 # Give DNS registration a kick 881 child.sendline("ipconfig /registerdns") 882 883 self.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'], retries=60, delay=5 ) 814 884 815 885 … … 825 895 '''join a windows box to a domain''' 826 896 child = self.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True, set_noexpire=True) 827 child.sendline("ipconfig /flushdns") 828 child.expect("C:") 829 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:%s /UserD:%s /PasswordD:%s" % (domain, username, password)) 830 child.expect("The command completed successfully") 897 retries = 5 898 while retries > 0: 899 child.sendline("ipconfig /flushdns") 900 child.expect("C:") 901 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:%s /UserD:%s /PasswordD:%s" % (domain, username, password)) 902 i = child.expect(["The command completed successfully", 903 "The specified domain either does not exist or could not be contacted."], timeout=120) 904 if i == 0: 905 break 906 time.sleep(10) 907 retries -= 1 908 831 909 child.expect("C:") 832 910 child.sendline("shutdown /r -t 0") … … 843 921 self.info('Testing smbclient') 844 922 self.chdir('${PREFIX}') 845 self.cmd_contains("bin/smbclient --version", ["${SAMBA_VERSION}"]) 846 self.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME} -U%s%%%s %s' % (username, password, args), ["IPC"]) 923 smbclient = self.getvar("smbclient") 924 self.cmd_contains("%s --version" % (smbclient), ["${SAMBA_VERSION}"]) 925 self.retry_cmd('%s -L ${WIN_HOSTNAME} -U%s%%%s %s' % (smbclient, username, password, args), ["IPC"], retries=60, delay=5) 926 927 def test_net_use(self, vm, realm, domain, username, password): 928 self.setwinvars(vm) 929 self.info('Testing net use against Samba3 member') 930 child = self.open_telnet("${WIN_HOSTNAME}", "%s\\%s" % (domain, username), password) 931 child.sendline("net use t: \\\\${HOSTNAME}.%s\\test" % realm) 932 child.expect("The command completed successfully") 847 933 848 934 … … 858 944 self.parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location') 859 945 self.parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code') 946 self.parser.add_option("--use-ntvfs", action='store_true', default=False, help='use NTVFS for the fileserver') 947 self.parser.add_option("--dns-backend", type="choice", 948 choices=["SAMBA_INTERNAL", "BIND9_FLATFILE", "BIND9_DLZ", "NONE"], 949 help="The DNS server backend. SAMBA_INTERNAL is the builtin name server (default), " \ 950 "BIND9_FLATFILE uses bind9 text database to store zone information, " \ 951 "BIND9_DLZ uses samba4 AD to store zone information, " \ 952 "NONE skips the DNS setup entirely (not recommended)", 953 default="SAMBA_INTERNAL") 860 954 861 955 self.opts, self.args = self.parser.parse_args() … … 869 963 870 964 self.load_config(self.opts.conf) 965 966 nameserver = self.get_nameserver() 967 if nameserver == self.getvar('NAMED_INTERFACE_IP'): 968 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration" % nameserver) 969 self.setvar('DNSSERVER', nameserver) 871 970 872 971 self.set_skip(self.opts.skip) … … 891 990 self.chdir('${SOURCETREE}/' + subdir) 892 991 self.run_cmd('make clean') 992 993 if self.opts.use_ntvfs: 994 self.setvar('USE_NTVFS', "--use-ntvfs") 995 else: 996 self.setvar('USE_NTVFS', "") 997 998 self.setvar('NAMESERVER_BACKEND', self.opts.dns_backend) 999 1000 self.setvar('DNS_FORWARDER', "--option=dns forwarder=%s" % nameserver)
Note:
See TracChangeset
for help on using the changeset viewer.