tmpdir = None # pathstring on host
testbed = None # Testbed
errorcode = 0 # exit status that we are going to use
-timeouts = { 'short':10, 'install':300, 'test':300, 'build':3000 }
+timeouts = { 'short':100, 'install':3000, 'test':10000, 'build':100000 }
binaries = None # Binaries (.debs we have registered)
build_essential = ["build-essential"]
def debug(m, minlevel=0):
if opts.debuglevel < minlevel: return
if opts.quiet and trace_stream is None: return
- p = 'adt-run: debug'
+ p = 'adt-run: trace'
if minlevel: p += `minlevel`
p += ': '
for l in m.rstrip('\n').split('\n'):
ep.stream = open('/dev/null','w')
ep._sp = None
elif count == 1:
- if to_stderr: ep.stream = sys.stderr
+ if to_stderr: ep.stream = os.dup(2)
else: ep.stream = trace_stream
ep._sp = None
else:
ep.stream = ep._sp.stdin
def wait(ep):
if ep._sp is None: return
+ if type(ep.stream) == type(2):
+ os.close(ep.stream)
+ ep.stream = ()
ep._sp.stdin.close()
rc = ep._sp.wait()
if rc: bomb('stderr plumbing tee(1) failed, exit code %d' % rc)
def mkdir_okexist(pathname, mode=02755):
try:
os.mkdir(pathname, mode)
- except OSError, oe:
+ except (IOError,OSError), oe:
if oe.errno != errno.EEXIST: raise
def rmtree(what, pathname):
debug('/ %s rmtree %s' % (what, pathname), 2)
- shutil.rmtree(pathname)
+ try: shutil.rmtree(pathname)
+ except (IOError,OSError), oe:
+ if oe.errno != errno.EEXIST: raise
def debug_subprocess(what, cmdl=None, script=None):
o = '$ '+what+':'
return "<Action %s %s %s>" % (a.kind, a.what, `a.af`)
def parse_args():
- global opts
+ global opts, timeouts
global n_non_actions # argh, stupid python scoping rules
usage = "%prog <options> --- <virt-server>..."
parser = OptionParser(usage=usage)
'deb_forbuilds': 'auto',
'deb_fortests': 'auto',
'tb': False,
- 'override_control': None
+ 'override_control': None,
+ 'set_lang': 'C'
}
initial_arghandling = arghandling.copy()
n_non_actions = 0
' according to most recent --binaries-* settings')
pa_setah('--no-built-binaries', ['dsc_filter'], '_',
help='from subsequent sources, do not use any binaries')
-
#---- binary package processing settings:
def pa_setahbins(long,toset,how):
pa_path('output-dir', OutputDir, dir=True,
help='write stderr/out files in PATH')
+ pa('--leave-lang', dest='set_lang', action='store_false',
+ help="leave LANG on testbed set to testbed's default")
+ pa('--set-lang', dest='set_lang', action='store', metavar='LANGVAL',
+ help='set LANG on testbed to LANGVAL', default='C')
+
pa('','--tmp-dir', type='string', dest='tmpdir',
help='write temporary files to TMPDIR, emptying it'
' beforehand and leaving it behind at the end')
help='write a summary report to SUMMARY,'
' emptying it beforehand')
+ for k in timeouts.keys():
+ pa('','--timeout-'+k, type='int', dest='timeout_'+k,
+ metavar='T', help='set %s timeout to T')
+ pa('','--timeout-factor', type='float', dest='timeout_factor',
+ metavar='FACTOR', default=1.0,
+ help='multiply all default timeouts by FACTOR')
+
pa('','--user', type='string', dest='user',
help='run tests as USER (needs root on testbed)')
pa('','--gain-root', type='string', dest='gainroot',
if n_non_actions >= len(parser.largs):
parser.error('nothing to do specified')
+ for k in timeouts.keys():
+ t = getattr(opts,'timeout_'+k)
+ if t is None: t = timeouts[k] * opts.timeout_factor
+ timeouts[k] = int(t)
+
arghandling = initial_arghandling
opts.actions = []
ix = 0
elif kindpath.endswith('/'):
kind = 'tree'
constructor = InputDir
- else: parser.error("do not know how to handle filename \`%s';"
- " specify --source --binary or --build-tree")
+ else: parser.error("do not know how to handle filename `%s';"
+ " specify --source --binary or --build-tree" %
+ kindpath)
what = '%s%s' % (kind,ix); ix += 1
if opts.summary is not None:
summary_stream = open(opts.summary, 'w', 0)
- debug('options: '+`opts`, 1)
+ debug('options: '+`opts`+'; timeouts: '+`timeouts`, 1)
def finalise_options():
global opts, tb, build_essential
stdin=p, stdout=p, stderr=tb._errplumb.stream)
tb.expect('ok')
tb.caps = tb.commandr('capabilities')
+ if not 'print-execute-command' in tb.caps:
+ tb.bomb('testbed does not support print-execute-command')
def stop(tb):
tb._debug('stop')
tb.close()
pl = tb.commandr('open')
tb.scratch = InputDir('tb-scratch', pl[0], True)
tb.deps_processed = []
+ tb._auxverbscript_make()
+
+ def _auxverbscript_make(tb):
+ pec = tb.commandr('print-execute-command')
+ if len(pec) < 2: tb.bomb('too few results from print-execute-command')
+ tb.ec_cmdl = map(urllib.unquote, pec[0].split(','))
+ tb.ec_mode = urllib.unquote(pec[1])
+ tb.ec_infos = map(urllib.unquote,pec[2:])
+
+ shellquote_re = regexp.compile(r'([\\"$`])')
+ def shellquote_arg(s): return '"' + shellquote_re.sub(r'\\\1', s) + '"'
+ def shellquote_cmdl(l): return ' '.join(map(shellquote_arg,l))
+
+ tb._debug('tb.ec_cmdl = %s' % (`tb.ec_cmdl`))
+
+ tb.ec_auxverbscript = TemporaryFile('satdep-auxverb')
+ print >>open(tb.ec_auxverbscript.write(),'w'), (
+'''#!/bin/sh
+set -ex
+echo >&2 ": $*"
+if [ $# = 2 ] && [ "x$1" = xdpkg-architecture ] && [ "x$2" = x-qDEB_HOST_ARCH ]; then
+ set -- dpkg --print-architecture
+fi
+if [ "x$1" = xsh ] && [ "x$2" = x-c ]; then
+ shift; shift
+ # what a horrible hack!
+fi
+exec '''+shellquote_cmdl(tb.ec_cmdl)+' "$*"'+"\n"
+ )
+ os.chmod(tb.ec_auxverbscript.write(), 0755)
+
def mungeing_apt(tb):
if not 'revert' in tb.caps:
tb._need_reset_apt = True
def reset_apt(tb):
if not tb._need_reset_apt: return
what = 'aptget-update-reset'
- cmdl = ['apt-get','-qy','update']
- rc = tb.execute(what, cmdl, timeout=timeouts['install'])
+ cmdl = ['sh','-c','apt-get -qy update 2>&1']
+ rc = tb.execute(what, cmdl, kind='install')
if rc:
pstderr("\n" "warning: failed to restore"
" testbed apt cache, exit code %d" % rc)
tb.command('revert')
tb.blamed = []
for af in tb._ephemeral: af.invalidate(True)
+ tb._auxverbscript_make()
tb.modified = False
def prepare2(tb, deps_new):
tb._debug('prepare2, deps_new=%s' % deps_new, 1)
tb._debug(' installing dependencies '+`deps_new`, 1)
tb.deps_processed = deps_new
if not deps_new: return
- dstr = ', '.join(deps_new)
- script = binaries.apt_pkg_gdebi_script(
- dstr, [[
- 'from GDebi.DebPackage import DebPackage',
- 'd = DebPackage(cache)',
- 'res = d.satisfyDependsStr(arg)',
- ]])
- cmdl = ['python','-c',script]
- what = 'install-deps'
- rc = testbed.execute(what+'-debinstall', cmdl, script=script,
- timeout=timeouts['install'])
- if rc: badpkg('dependency install failed, exit code %d' % rc)
+ tb.satisfy_dependencies_string(', '.join(deps_new), 'install-deps')
def needs_reset(tb):
tb._debug('needs_reset, previously=%s' % tb.modified, 1)
tb.modified = True
" expected %d result parameters" %
(string, l, len(ll), nresults))
return ll
- def commandr(tb, cmd, args=(), nresults=None):
+ def commandr(tb, cmd, args=(), nresults=None, unquote=True):
# pass args=[None,...] or =(None,...) to avoid more url quoting
if type(cmd) is str: cmd = [cmd]
if len(args) and args[0] is None: args = args[1:]
al = cmd + args
tb.send(string.join(al))
ll = tb.expect('ok', nresults)
- rl = map(urllib.unquote, ll)
- return rl
+ if unquote: ll = map(urllib.unquote, ll)
+ return ll
def command(tb, cmd, args=()):
tb.commandr(cmd, args, 0)
def commandr1(tb, cmd, args=()):
return rl[0]
def execute(tb, what, cmdl,
si='/dev/null', so='/dev/null', se=None, cwd=None,
- script=False, tmpdir=None, timeout=timeouts['short']):
+ script=False, tmpdir=None, kind='short'):
# Options for script:
# False - do not call debug_subprocess, no synch. reporting required
# None or string - call debug_subprocess with that value,
# None - usual Errplumb (output is of kind 2c)
# string - path on testbed (output is of kind 2d)
+ timeout = timeouts[kind]
+
if script is not False: debug_subprocess(what, cmdl, script=script)
if cwd is None: cwd = tb.scratch.write(True)
if xdump is not None and 'execute-debug' in tb.caps: cmdl += [xdump]
if tmpdir is not None: cmdl.append('env=TMPDIR=%s' % tmpdir)
+ if kind=='install': cmdl.append('env=DEBIAN_FRONTEND=noninteractive')
+ if opts.set_lang is not False:
+ cmdl.append('env=LANG=%s' % opts.set_lang)
rc = tb.commandr1('execute', cmdl)
try: rc = int(rc)
return rc
+ def satisfy_dependencies_string(tb, deps, what):
+ # Must have called Binaries.configure_apt
+ debug('dependencies: %s: satisfying %s' % (what,deps))
+ dsc = TemporaryFile('deps.dsc')
+ print >>open(dsc.write(),'w'), 'Build-Depends: ', deps, '\n\n'
+ # pbuilder-satisfydepends has a bug where it ignores the
+ # Build-Depends if it's the last line in the dsc
+ tb.satisfy_dependencies_dsc(dsc, what)
+
+ def satisfy_dependencies_dsc(tb, dsc, what):
+ # Must have called Binaries.configure_apt
+ cmdl = [ '/usr/lib/pbuilder/pbuilder-satisfydepends-classic',
+ '--binary-all', # --check-key
+ '--internal-chrootexec',tb.ec_auxverbscript.read(),
+ '-c',dsc.read()
+ ]
+ debug('dependencies: %s: running %s' % (what,`cmdl`))
+ rc = subprocess.call(cmdl, stdout=None, stderr=None)
+ if rc: badpkg('dependency install failed, exit code %d' % rc)
+
#---------- representation of test control files: Field*, Test, etc.
class FieldBase:
use_dir = testbed.scratch
return RelativeOutputFile(idstr, use_dir, idstr)
- t.act.work.write(True)
+ if hasattr(t.act,'work'): t.act.work.write(True)
+ tree.read(True)
af = RelativeInputFile(t.what, tree, t.path)
so = stdouterr('stdout')
tf = af.read(True)
tmpdir = None
- tree.read(True)
rc = testbed.execute('testchmod-'+t.what, ['chmod','+x','--',tf])
if rc: bomb('failed to chmod +x %s' % tf)
tfl = ['su',opts.user,'-c',tf]
tmpdir = '%s%s-tmpdir' % (testbed.scratch.read(True), t.what)
script = 'rm -rf -- "$1"; mkdir -- "$1"'
- if opts.user: script += '; chown %s "$1"' % opts.user
- if 'rw-build-tree' in t.restriction_names:
- script += '; chown -R %s "$2"' % opts.user
+ if opts.user:
+ script += '; chown %s "$1"' % opts.user
+ if 'rw-build-tree' in t.restriction_names:
+ script += '; chown -R %s "$2"' % opts.user
rc = testbed.execute('mktmpdir-'+t.what,
['sh','-xec',script,'x',tmpdir,tree.read(True)])
if rc: bomb("could not create test tmpdir `%s', exit code %d"
rc = testbed.execute('test-'+t.what, tfl,
so=so.write(True), se=se.write(True), cwd=tree.read(True),
- tmpdir=tmpdir, timeout=timeouts['test'])
+ tmpdir=tmpdir, kind='test')
so_read = so.read()
se_read = se.read()
tree, 'debian/tests/control')
try:
control = open(control_af.read(), 'r')
- except OSError, oe:
+ except (IOError,OSError), oe:
if oe[0] != errno.ENOENT: raise
return []
def cleanup():
global trace_stream
try:
- rm_ec = 0
- if opts.tmpdir is None and tmpdir is not None:
- rmtree('tmpdir', tmpdir)
if testbed is not None:
testbed.reset_apt()
testbed.stop()
- if rm_ec: bomb('rm -rf -- %s failed, code %d' % (tmpdir, ec))
+ if opts.tmpdir is None and tmpdir is not None:
+ rmtree('tmpdir', tmpdir)
if trace_stream is not None:
trace_stream.close()
trace_stream = None
for x in ['pubring','secring']:
os.stat(opts.gnupghome + '/' + x + '.gpg')
ok = True
- except OSError, oe:
+ except (IOError,OSError), oe:
if oe.errno != errno.ENOENT: raise
if ok: b._debug('no key generation needed')
gpg --homedir="$1" --batch --gen-key key-gen-params
'''
cmdl = ['sh','-ec',script,'x',opts.gnupghome]
- rc = subprocess_cooked(cmdl, dbg=(genkey,script))[0]
- if rc:
- try:
- f = open(opts.gnupghome+'/key-gen-log')
- tp = file.read()
- except OSError, e: tp = e
- pstderr(tp)
- bomb('key generation failed, code %d' % rc)
+ rc = subprocess_cooked(cmdl, dbg=('genkey',script))[0]
+ if rc: bomb('key generation failed, code %d' % rc)
def apt_configs(b):
return {
"Dir::Etc::sourcelist": b.dir.read(True)+'sources.list',
+ "Debug::pkgProblemResolver": "true",
}
- def apt_pkg_gdebi_script(b, arg, middle):
- script = [
- 'import apt_pkg',
- 'import urllib',
- 'arg = urllib.unquote("%s")' % urllib.quote(arg),
- ]
+ def _configure_apt(b, tb):
+ config = OutputFile('apt-config','/etc/apt/apt.conf.d/90autopkgtest',
+ True)
+ f = open(config.write(),'w')
for (k,v) in b.apt_configs().iteritems():
- v = urllib.quote(v)
- script.append('apt_pkg.Config.Set("%s",urllib.unquote("%s"))'
- % (k, v))
- script += [
- 'from GDebi.Cache import Cache',
- 'cache = Cache()',
- ]
- for m in middle:
- script += m + [
- 'print res',
- 'print d.missingDeps',
- 'print d.requiredChanges',
- 'if not res: raise "gdebi failed (%s, %s, %s): %s" % '+
- ' (`res`, `d.missingDeps`, `d.requiredChanges`, '+
- 'd._failureString)',
- 'cache.commit()',
- ''
- ]
- return '\n'.join(script)
- def apt_get(b):
+ print >>f, '%s { "%s"; };' % (k, v)
+ f.close()
+
+ def _apt_get(b):
ag = ['apt-get','-qy']
for kv in b.apt_configs().iteritems():
ag += ['-o', '%s=%s' % kv]
- return ag
+ return ' '.join(ag)
def reset(b):
b._debug('reset')
dest = RelativeOutputFile('binaries--'+leafname, b.dir, leafname)
try: os.remove(dest.write())
- except OSError, oe:
+ except (IOError,OSError), oe:
if oe.errno != errno.ENOENT: raise e
try: os.link(af.read(), dest.write())
- except OSError, oe:
+ except (IOError,OSError), oe:
if oe.errno != errno.EXDEV: raise e
shutil.copy(af.read(), dest)
def publish(b):
b._debug('publish')
+ b._configure_apt(testbed)
+
script = '''
exec >&2
cd "$1"
if [ "x`ls /var/lib/dpkg/updates`" != x ]; then
echo >&2 "/var/lib/dpkg/updates contains some files, aargh"; exit 1
fi
- '''+ ' '.join(b.apt_get()) +''' update >&2
+ '''+ b._apt_get() +''' update >&2
cat /var/lib/dpkg/status >&3
'''
testbed.mungeing_apt()
rc = testbed.execute('apt-key', ['sh','-ec',script],
so=so.write(True), cwd=b.dir.write(True),
- script=script)
+ script=script, kind='install')
if rc: bomb('apt setup failed with exit code %d' % rc)
testbed.blamed += b.blamed
if pkgs_reinstall:
for pkg in pkgs_reinstall: testbed.blame(pkg)
what = 'apt-get-reinstall'
- cmdl = (b.apt_get() + ['--reinstall','install'] +
- [pkg for pkg in pkgs_reinstall])
- rc = testbed.execute(what, cmdl, script=None,
- timeout=timeouts['install'])
+ cmdl = (b._apt_get() + ' --reinstall install '+
+ ' '.join([pkg for pkg in pkgs_reinstall])+' >&2')
+ cmdl = ['sh','-c',cmdl]
+ rc = testbed.execute(what, cmdl, script=None, kind='install')
if rc: badpkg("installation of basic binarries failed,"
" exit code %d" % rc)
for pkg in b.install:
what = 'apt-get-install-%s' % pkg
testbed.blame(pkg)
- cmdl = b.apt_get() + ['install',pkg]
- rc = testbed.execute(what, cmdl, script=None,
- timeout=timeouts['install'])
+ cmdl = b._apt_get() + ' install ' + pkg + ' >&2'
+ cmdl = ['sh','-c',cmdl]
+ rc = testbed.execute(what, cmdl, script=None, kind='install')
if rc: badpkg("installation of %s failed, exit code %d"
% (pkg, rc))
so = TemporaryFile('%s-%s-results' % (what,which))
rc = testbed.execute('%s-%s' % (what,which),
['sh','-ec',script]+xargs, script=script,
- so=so.write(True), cwd=cwd,
- timeout=timeouts['build'])
+ so=so.write(True), cwd=cwd, kind='build')
results = open(so.read()).read().rstrip('\n')
if len(results): results = results.split("\n")
else: results = []
if act.kind == 'dsc':
testbed.prepare2([])
- script = binaries.apt_pkg_gdebi_script('', [[
- 'from GDebi.DebPackage import DebPackage',
- 'd = DebPackage(cache)',
- 'res = d.satisfyDependsStr("dpkg-dev")',
- ]])
- cmdl = ['python','-c',script]
- whatp = what+'-dpkgsource'
- rc = testbed.execute(what, cmdl, script=script,
- timeout=timeouts['install'])
- if rc: badpkg('dpkg-source install failed, exit code %d' % rc)
+ testbed.satisfy_dependencies_string('dpkg-dev',
+ 'install dpkg-dev')
work = TemporaryDir(what+'-build')
act.work = work
[ create_command ])
script += [
- 'cd */.',
+ 'cd [a-z0-9]*-*/.',
'pwd >&3',
'set +e; test -f debian/tests/control; echo $? >&3'
]
if act.kind != 'dsc':
testbed.prepare2([])
- script = binaries.apt_pkg_gdebi_script(
- dsc.read(True), [[
- 'from GDebi.DscSrcPackage import DscSrcPackage',
- 'd = DscSrcPackage(cache, arg)',
- 'res = d.checkDeb()',
- ],[
- 'from GDebi.DebPackage import DebPackage',
- 'd = DebPackage(cache)',
- 'res = d.satisfyDependsStr("'+
- ','.join(build_essential)+
- '")',
- ]])
-
- cmdl = ['python','-c',script]
- whatp = what+'-builddeps'
- rc = testbed.execute(what, cmdl, script=script,
- timeout=timeouts['install'])
- if rc: badpkg('build-depends install failed,'
- ' exit code %d' % rc)
+ testbed.satisfy_dependencies_string('build-essential',
+ 'install build-essential')
+ testbed.satisfy_dependencies_dsc(dsc, 'build dependencies')
script = tmpdir_script + [
'cd "$2"',
debug_b('filter=%s' % filter)
if filter != '_':
script = tmpdir_script + [
- 'cd '+work.write(True)+'/*/.',
+ 'cd '+work.write(True)+'/[a-z0-9]*-*/.',
opts.user_wrap(opts.gainroot+' debian/rules binary'),
'cd ..',
'echo *.deb >&3',
result_debs = source_rules_command(act,script,what,
'binary',work,work.write(True),
results_lines=1, xargs=['x',tmpdir])
- if result_debs == '*': debs = []
+ if result_debs == '*.deb': debs = []
else: debs = result_debs.split(' ')
debug_b('debs='+`debs`)
re = regexp.compile('^([-+.0-9a-z]+)_[^_/]+(?:_[^_/]+)\.deb$')