# 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
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']
except KeyError: our_base = '/usr/share/autopkgtest';
sys.path.insert(1, our_base+'/python')
-import string
-from optparse import OptionParser
import VirtSubproc as vsp
-def parse_args():
- global down, debuglevel
-
- usage = "%prog [<adt-xenlvm options>]"
-
+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, console, pauses
+ usage = "%prog <options> [-- <adt-xenlvm options>]"
+ parser = OptionParser(usage=usage)
+ pa = parser.add_option
+ pe = parser.error
- (opts,args) = parser.parse_args()
- if len(args) != 1: pe("need exactly one arg, xenlvm specification")
+ pa('-r', '--gain-root', type='string', dest='gain_root');
+ pa('-d', '--debug', action='store_true', dest='debug');
+ pa('','--pause', type='string', dest='pause', default='');
+ (opts,xlargs) = parser.parse_args()
vsp.debuglevel = opts.debug
- xenlvm_arg = args[0]
- if not xenlvm_arg: pe("xenlvm specification may not be empty")
- if xenlvm_arg == '=': down = ['dxenlvm','-q']
- elif xenlvm_arg == '=': down = ['dxenlvm','-q']
- elif xenlvm_arg[0] == '=': down = ['dxenlvm','-q','-c',xenlvm_arg[1:]]
- elif xenlvm_arg[0] == '/': down = ['xenlvm',xenlvm_arg,'--']
- else: pe("xenlvm spec must be =[DXENLVM] or /PATH/TO/XENLVM")
-
- if opts.gain_root != None: down = opts.gain_root.split() + down
-
- vsp.debug("down = %s" % string.join(down))
- vsp.down = down
+ if opts.gain_root is None: gain_root = []
+ else: gain_root = opts.gain_root.split()
+ vsp.down = gain_root + ['adt-xenlvm-on-testbed'] + xlargs + ['--']
+
+ 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'],
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE )
+ l = withholder.stdout.readline(2)
+ rc = withholder.poll()
+ if rc is not None:
+ withholder.stdin.close()
+ withholder.stdout.close()
+ withholder = None
+ vsp.bomb("with-testbed failed, code %d" % rc)
+ if l != "y\n":
+ vsp.bomb("with-testbed sh gave wrong output `%s', not `l'"
+ % l.rstrip("\n"))
+ vsp.execute('mkdir %s' % downtmp, downp=True)
+
+def do_close():
+ global withholder
+ check_pause('close')
+ withholder.stdin.close()
+ withholder.stdout.close()
+ rc = withholder.wait()
+ withholder = None
+ if rc: vsp.bomb("with-testbed failed when closing/reverting,"
+ " code %d" % rc)
+
+def hook_forked_inchild():
+ if withholder is not None:
+ withholder.stdin.close()
+ withholder.stdout.close()
def hook_open():
- global downtmp
- vsp.execute('true', downp=True)
- downtmp = vsp.execute('mktemp -t -d', downp=True, outp=True)
+ hook_cleanup()
+ do_open()
return downtmp
-def hook_stop():
- vsp.execute('rm -rf --', c[1:2])
- os.mkdir(c[1])
+def hook_revert():
+ check_pause('revert')
+ do_close()
+ do_open()
def hook_cleanup():
- vsp.execute('rm -rf --', [downtmp], downp=True)
+ check_pause('cleanup')
+ global withholder
+ if withholder is not None:
+ do_close()
+
+def hook_capabilities():
+ return ['revert','root-on-testbed','suggested-normal-user=adtxenu']
parse_args()
vsp.main()