chiark / gitweb /
adt-run: actually make new auxverbscript and pbuilder-based dependency installation...
[autopkgtest.git] / runner / adt-run
index 25529884af9a0676379b21d71749214b7ca95c3a..9f1f76381bad531730acd289f0791c53a3790b6c 100755 (executable)
@@ -45,7 +45,7 @@ signal.signal(signal.SIGINT, signal.SIG_DFL) # undo stupid Python SIGINT thing
 tmpdir = None          # pathstring on host
 testbed = None         # Testbed
 errorcode = 0          # exit status that we are going to use
-timeouts = { 'short':10, 'install':900, 'test':600, 'build':3000 }
+timeouts = { 'short':100, 'install':3000, 'test':10000, 'build':100000 }
 binaries = None                # Binaries (.debs we have registered)
 build_essential = ["build-essential"]
 
@@ -188,7 +188,9 @@ def mkdir_okexist(pathname, mode=02755):
 
 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+':'
@@ -406,7 +408,7 @@ class Action:
        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)
@@ -419,7 +421,8 @@ def parse_args():
                '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
@@ -507,7 +510,6 @@ def parse_args():
                     ' 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):
@@ -541,6 +543,11 @@ def parse_args():
        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')
@@ -551,6 +558,13 @@ def parse_args():
                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',
@@ -587,6 +601,11 @@ def parse_args():
        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
@@ -647,7 +666,7 @@ def setup_trace():
        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
@@ -716,6 +735,8 @@ class Testbed:
                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()
@@ -735,6 +756,37 @@ class Testbed:
        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
@@ -763,6 +815,7 @@ class Testbed:
                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)
@@ -777,18 +830,7 @@ class Testbed:
        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,
-                               kind='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
@@ -837,7 +879,7 @@ class Testbed:
                        " 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:]
@@ -845,8 +887,8 @@ class Testbed:
        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=()):
@@ -891,6 +933,8 @@ class Testbed:
        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)
@@ -904,6 +948,26 @@ class Testbed:
 
        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:
@@ -1294,35 +1358,18 @@ END
  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]
@@ -1365,6 +1412,8 @@ END
  def publish(b):
        b._debug('publish')
 
+       b._configure_apt(testbed)
+
        script = '''
   exec >&2
   cd "$1"
@@ -1391,7 +1440,7 @@ END
   if [ "x`ls /var/lib/dpkg/updates`" != x ]; then
     echo >&2 "/var/lib/dpkg/updates contains some files, aargh"; exit 1
   fi
-  '''+ b.apt_get() +''' update >&2
+  '''+ b._apt_get() +''' update >&2
   cat /var/lib/dpkg/status >&3
                '''
        testbed.mungeing_apt()
@@ -1416,7 +1465,7 @@ END
        if pkgs_reinstall:
                for pkg in pkgs_reinstall: testbed.blame(pkg)
                what = 'apt-get-reinstall'
-               cmdl = (b.apt_get() + ' --reinstall 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')
@@ -1427,7 +1476,7 @@ END
        for pkg in b.install:
                what = 'apt-get-install-%s' % pkg
                testbed.blame(pkg)
-               cmdl = b.apt_get() + ' install ' + pkg + ' >&2'
+               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"
@@ -1508,15 +1557,8 @@ def build_source(act, control_override):
 
        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, kind='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
@@ -1561,7 +1603,7 @@ def build_source(act, control_override):
                        [ create_command ])
 
        script += [
-                       'cd */.',
+                       'cd [a-z0-9]*-*/.',
                        'pwd >&3',
                        'set +e; test -f debian/tests/control; echo $? >&3'
                ]
@@ -1611,24 +1653,9 @@ def build_source(act, control_override):
                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, kind='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"',
@@ -1660,7 +1687,7 @@ def build_source(act, control_override):
        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',
@@ -1668,7 +1695,7 @@ def build_source(act, control_override):
                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$')