X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=virt-subproc%2Fadt-virt-xenlvm;h=08608daba9ad6d6f321bb33b5b1f63dab365ecc3;hb=93430ac8f5eec12bdd8b679a055af33b3c2d08b8;hp=870afb1631c9bb246eb287c5fb21de2d68cbe34b;hpb=a6abcf0d59f203ae7062bfed10a1cd52cc7d95a7;p=autopkgtest.git diff --git a/virt-subproc/adt-virt-xenlvm b/virt-subproc/adt-virt-xenlvm index 870afb1..08608da 100755 --- a/virt-subproc/adt-virt-xenlvm +++ b/virt-subproc/adt-virt-xenlvm @@ -3,7 +3,7 @@ # adt-virt-xenlvm is part of autopkgtest # autopkgtest is a tool for testing Debian binary packages # -# autopkgtest is Copyright (C) 2006 Canonical Ltd. +# autopkgtest is Copyright (C) 2006-2007 Canonical Ltd. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,6 +26,9 @@ import sys import os import re as regexp import string +import subprocess +import fnmatch +import signal from optparse import OptionParser try: our_base = os.environ['AUTOPKGTEST_BASE'] @@ -34,31 +37,81 @@ sys.path.insert(1, our_base+'/python') import VirtSubproc as vsp -witholder = None +withholder = None +downtmp = '/root/adt-downtmp' +pauses = None +event_counters = { } + +def check_pause(kind): + if not event_counters.has_key(kind): event_counters[kind] = 0 + event = '%s#%d' % (kind, event_counters[kind]) + event_counters[kind] += 1 + for pattern in pauses: + if not '#' in pattern: matched = kind == pattern + else: matched = fnmatch.fnmatchcase(event,pattern) + if matched: break + if not matched: + return + print >>sys.stderr, ("----- adt-virt-xenlvm pause (event=%s)," + " stopping -----" % event) + os.kill(0, signal.SIGSTOP) def parse_args(): - global debuglevel, xlargs, gain_root + global debuglevel, with_testbed, console, pauses usage = "%prog [-- ]" parser = OptionParser(usage=usage) pa = parser.add_option pe = parser.error - pa('-r', '--gain-root', type='string', dest='gain_root'); - pa('-d', '--debug', action='store_true', dest='debug'); + pa('-r', '--gain-root', type='string', dest='gain_root') + pa('-d', '--debug', action='store_true', dest='debug') + pa('', '--userv', action='store_true', dest='userv') + pa('', '--distro', type='string', dest='distro') + pa('', '--nominum', type='string', dest='nominum') + pa('','--pause', type='string', dest='pause', default='') (opts,xlargs) = parser.parse_args() vsp.debuglevel = opts.debug + xargs_userv = [] + xargs_direct = [] - if opts.gain_root = None: gain_root = [] - else: gain_root = opts.gain_root.split() - vsp.down = gain_root + ['adt-xenlvm-on-testbed'] + xlargs + ['--'] + for k in ['distro','nominum']: + v = getattr(opts,k) + if v is None: continue + xargs_direct.append('--%s=%s' % (k, v)) + xargs_userv.append('-D%s=%s' % (k, v)) -def hook_open(): - hook_cleanup() + if not opts.userv: + if opts.gain_root is None: gain_root = [] + else: gain_root = opts.gain_root.split() + with_testbed = (gain_root + ['adt-xenlvm-with-testbed'] + + xargs_direct + xlargs + + ['--','sh','-ec','echo y; exec cat']) + vsp.down = (gain_root + ['adt-xenlvm-on-testbed'] + + xargs_direct + xlargs + ['--']) + else: + if opts.gain_root: + pe('--userv and --gain-root are not compatible') + basis = (['userv'] + xargs_userv + xlargs + + ['root','adt-xenlvm-testbed']) + with_testbed = basis + ['with'] + get_down = subprocess.Popen(basis + ['pon0'], + stdin=file('/dev/null'), stdout=subprocess.PIPE, + stderr=None) + (pon0, _) = get_down.communicate() + if get_down.returncode: + vsp.bomb('failed to check userv service provision' + ' and subcommand details (code=%d)' % + get_down.returncode) + vsp.down = pon0.split('\0') + pauses = opts.pause.split(',') + +def do_open(): + global withholder + assert(withholder is None) withholder = subprocess.Popen( - gain_root + ['adt-xenlvm-with-testbed'] + xlargs + - ['--','sh','-ec','echo y; exec cat'], + with_testbed, stdin=subprocess.PIPE, stdout=subprocess.PIPE ) l = withholder.stdout.readline(2) rc = withholder.poll() @@ -66,32 +119,45 @@ def hook_open(): withholder.stdin.close() withholder.stdout.close() withholder = None - bomb("with-testbed failed, code %d" % rc) + vsp.bomb("with-testbed failed, code %d" % rc) if l != "y\n": - bomb("with-testbed sh gave wrong output `%s', not `l'" + vsp.bomb("with-testbed sh gave wrong output `%s', not `l'" % l.rstrip("\n")) - downtmp = '/root/adt-downtmp' - vsp.execute('mkdir %s' % downtmp, downp=True) - return downtmp + vsp.execute('mkdir %s' % downtmp, downp=True) -def hook_stop(): +def do_close(): + global withholder + check_pause('close') withholder.stdin.close() withholder.stdout.close() rc = withholder.wait() withholder = None - if rc: bomb("with-testbed failed at shutdown, code %d" % rc) + if rc: vsp.bomb("with-testbed failed when closing/reverting," + " code %d" % rc) -def hook_cleanup(): +def hook_forked_inchild(): if withholder is not None: withholder.stdin.close() withholder.stdout.close() - rc = withholder.wait() - withholder = None - if rc: print >>sys.stderr, ( - "with-testbed failed during cleanup, code %d" % rc) + +def hook_open(): + hook_cleanup() + do_open() + return downtmp + +def hook_revert(): + check_pause('revert') + do_close() + do_open() + +def hook_cleanup(): + check_pause('cleanup') + global withholder + if withholder is not None: + do_close() def hook_capabilities(): - return ('revert','root-on-testbed','suggest-normal-user=adtxenu') + return ['revert','root-on-testbed','suggested-normal-user=adtxenu'] parse_args() vsp.main()