'''automated testing library for testing Samba against windows'''
import pexpect, subprocess
+import optparse
import sys, os, time, re
class wintest():
self.list_mode = False
self.vms = None
os.putenv('PYTHONUNBUFFERED', '1')
+ self.parser = optparse.OptionParser("wintest")
def setvar(self, varname, value):
'''set a substitution variable'''
return self.run_cmd(cmd, output=True)
def cmd_contains(self, cmd, contains, nomatch=False, ordered=False, regex=False,
- casefold=False):
+ casefold=True):
'''check that command output contains the listed strings'''
if isinstance(contains, str):
self.info(out)
for c in self.substitute(contains):
if regex:
+ if casefold:
+ c = c.upper()
+ out = out.upper()
m = re.search(c, out)
if m is None:
start = -1
out = out[end:]
def retry_cmd(self, cmd, contains, retries=30, delay=2, wait_for_fail=False,
- ordered=False, regex=False, casefold=False):
+ ordered=False, regex=False, casefold=True):
'''retry a command a number of times'''
while retries > 0:
try:
child.expect("C:")
def get_is_dc(self, child):
+ '''check if a windows machine is a domain controller'''
child.sendline("dcdiag")
- i = child.expect(["is not a Directory Server", "Home Server = "])
+ i = child.expect(["is not a Directory Server",
+ "is not recognized as an internal or external command",
+ "Home Server = ",
+ "passed test Replications"])
if i == 0:
return False
+ if i == 1 or i == 3:
+ child.expect("C:")
+ child.sendline("net config Workstation")
+ child.expect("Workstation domain")
+ child.expect('[\S]+')
+ domain = child.after
+ i = child.expect(["Workstation Domain DNS Name", "Logon domain"])
+ '''If we get the Logon domain first, we are not in an AD domain'''
+ if i == 1:
+ return False
+ if domain.upper() == self.getvar("WIN_DOMAIN").upper():
+ return True
+
child.expect('[\S]+')
hostname = child.after
- if hostname.upper() == self.getvar("WIN_HOSTNAME").upper:
+ if hostname.upper() == self.getvar("WIN_HOSTNAME").upper():
return True
def run_tlntadmn(self, child):
if v[-3:] == "_VM":
ret.append(self.vars[v])
return ret
+
+ def setup(self, testname, subdir):
+ '''setup for main tests, parsing command line'''
+ self.parser.add_option("--conf", type='string', default='', help='config file')
+ self.parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
+ self.parser.add_option("--vms", type='string', default=None, help='list of VMs to use (comma separated)')
+ self.parser.add_option("--list", action='store_true', default=False, help='list the available steps')
+ self.parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
+ self.parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
+ self.parser.add_option("--prefix", type='string', default=None, help='override install prefix')
+ self.parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
+ self.parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
+
+ self.opts, self.args = self.parser.parse_args()
+
+ if not self.opts.conf:
+ print("Please specify a config file with --conf")
+ sys.exit(1)
+
+ # we don't need fsync safety in these tests
+ self.putenv('TDB_NO_FSYNC', '1')
+
+ self.load_config(self.opts.conf)
+
+ self.set_skip(self.opts.skip)
+ self.set_vms(self.opts.vms)
+
+ if self.opts.list:
+ self.list_steps_mode()
+
+ if self.opts.prefix:
+ self.setvar('PREFIX', self.opts.prefix)
+
+ if self.opts.sourcetree:
+ self.setvar('SOURCETREE', self.opts.sourcetree)
+
+ if self.opts.rebase:
+ self.info('rebasing')
+ self.chdir('${SOURCETREE}')
+ self.run_cmd('git pull --rebase')
+
+ if self.opts.clean:
+ self.info('cleaning')
+ self.chdir('${SOURCETREE}/' + subdir)
+ self.run_cmd('make clean')