3 # adt-virt-xenlvm is part of autopkgtest
4 # autopkgtest is a tool for testing Debian binary packages
6 # autopkgtest is Copyright (C) 2006-2007 Canonical Ltd.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 # See the file CREDITS for a full list of credits information (often
23 # installed as /usr/share/doc/autopkgtest/CREDITS).
32 from optparse import OptionParser
34 try: our_base = os.environ['AUTOPKGTEST_BASE']
35 except KeyError: our_base = '/usr/share/autopkgtest';
36 sys.path.insert(1, our_base+'/python')
38 import VirtSubproc as vsp
41 downtmp = '/root/adt-downtmp'
45 def check_pause(kind):
46 if not event_counters.has_key(kind): event_counters[kind] = 0
47 event = '%s#%d' % (kind, event_counters[kind])
48 event_counters[kind] += 1
49 for pattern in pauses:
50 if not '#' in pattern: matched = kind == pattern
51 else: matched = fnmatch.fnmatchcase(event,pattern)
55 print >>sys.stderr, ("----- adt-virt-xenlvm pause (event=%s),"
56 " stopping -----" % event)
57 os.kill(0, signal.SIGSTOP)
60 global debuglevel, xlargs, gain_root, console, pauses
62 usage = "%prog <options> [-- <adt-xenlvm options>]"
63 parser = OptionParser(usage=usage)
64 pa = parser.add_option
67 pa('-r', '--gain-root', type='string', dest='gain_root');
68 pa('-d', '--debug', action='store_true', dest='debug');
69 pa('','--pause', type='string', dest='pause', default='');
71 (opts,xlargs) = parser.parse_args()
72 vsp.debuglevel = opts.debug
74 if opts.gain_root is None: gain_root = []
75 else: gain_root = opts.gain_root.split()
76 vsp.down = gain_root + ['adt-xenlvm-on-testbed'] + xlargs + ['--']
78 pauses = opts.pause.split(',')
82 assert(withholder is None)
83 withholder = subprocess.Popen(
84 gain_root + ['adt-xenlvm-with-testbed'] + xlargs +
85 ['--','sh','-ec','echo y; exec cat'],
86 stdin=subprocess.PIPE, stdout=subprocess.PIPE )
87 l = withholder.stdout.readline(2)
88 rc = withholder.poll()
90 withholder.stdin.close()
91 withholder.stdout.close()
93 vsp.bomb("with-testbed failed, code %d" % rc)
95 vsp.bomb("with-testbed sh gave wrong output `%s', not `l'"
97 vsp.execute('mkdir %s' % downtmp, downp=True)
102 withholder.stdin.close()
103 withholder.stdout.close()
104 rc = withholder.wait()
106 if rc: vsp.bomb("with-testbed failed when closing/reverting,"
109 def hook_forked_inchild():
110 if withholder is not None:
111 withholder.stdin.close()
112 withholder.stdout.close()
120 check_pause('revert')
125 check_pause('cleanup')
127 if withholder is not None:
130 def hook_capabilities():
131 return ['revert','root-on-testbed','suggested-normal-user=adtxenu']