chiark / gitweb /
02b07d409d36d41d53fe78e6a8828924776d3fbf
[autopkgtest.git] / virt-subproc / adt-virt-xenlvm
1 #!/usr/bin/python2.4
2 #
3 # adt-virt-xenlvm is part of autopkgtest
4 # autopkgtest is a tool for testing Debian binary packages
5 #
6 # autopkgtest is Copyright (C) 2006 Canonical Ltd.
7 #
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.
12 #
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.
17 #
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.
21 #
22 # See the file CREDITS for a full list of credits information (often
23 # installed as /usr/share/doc/autopkgtest/CREDITS).
24
25 import sys
26 import os
27 import re as regexp
28 import string
29 import subprocess
30 from optparse import OptionParser
31
32 try: our_base = os.environ['AUTOPKGTEST_BASE']
33 except KeyError: our_base = '/usr/share/autopkgtest';
34 sys.path.insert(1, our_base+'/python')
35
36 import VirtSubproc as vsp
37
38 withholder = None
39 downtmp = '/root/adt-downtmp'
40
41 def parse_args():
42         global debuglevel, xlargs, gain_root
43
44         usage = "%prog <options> [-- <adt-xenlvm options>]"
45         parser = OptionParser(usage=usage)
46         pa = parser.add_option
47         pe = parser.error
48
49         pa('-r', '--gain-root', type='string', dest='gain_root');
50         pa('-d', '--debug', action='store_true', dest='debug');
51
52         (opts,xlargs) = parser.parse_args()
53         vsp.debuglevel = opts.debug
54
55         if opts.gain_root is None: gain_root = []
56         else: gain_root = opts.gain_root.split()
57         vsp.down = gain_root + ['adt-xenlvm-on-testbed'] + xlargs + ['--']
58
59 def do_open():
60         global withholder
61         assert(withholder is None)
62         withholder = subprocess.Popen(
63                 gain_root + ['adt-xenlvm-with-testbed'] + xlargs +
64                  ['--','sh','-ec','echo y; exec cat'],
65                 stdin=subprocess.PIPE, stdout=subprocess.PIPE )
66         l = withholder.stdout.readline(2)
67         rc = withholder.poll()
68         if rc is not None:
69                 withholder.stdin.close()
70                 withholder.stdout.close()
71                 withholder = None
72                 bomb("with-testbed failed, code %d" % rc)
73         if l != "y\n":
74                 bomb("with-testbed sh gave wrong output `%s', not `l'"
75                         % l.rstrip("\n"))
76         vsp.execute('mkdir %s' % downtmp, downp=True)   
77
78 def do_close():
79         global withholder
80         withholder.stdin.close()
81         withholder.stdout.close()
82         rc = withholder.wait()
83         withholder = None
84         if rc: bomb("with-testbed failed when closing/resetting, code %d" % rc)
85
86 def hook_open():
87         hook_cleanup()
88         do_open()
89         return downtmp
90
91 def hook_reset():
92         do_close()
93         do_open()
94
95 def hook_cleanup():
96         global withholder
97         if withholder is not None:
98                 do_close()
99
100 def hook_capabilities():
101         return ['revert','root-on-testbed','suggest-normal-user=adtxenu']
102
103 parse_args()
104 vsp.main()