Merge lp:~marceloshima/testdrive/grub into lp:testdrive

Proposed by Marcelo Boveto Shima
Status: Needs review
Proposed branch: lp:~marceloshima/testdrive/grub
Merge into: lp:testdrive
Diff against target: 203 lines (+116/-23)
3 files modified
50_testdrive (+71/-0)
testdrive (+34/-20)
testdrive.py (+11/-3)
To merge this branch: bzr merge lp:~marceloshima/testdrive/grub
Reviewer Review Type Date Requested Status
Andres Rodriguez Needs Resubmitting
Review via email: mp+26459@code.launchpad.net

Description of the change

This branch adds the option --grub.
This option uses /var/cache/testdrive as cache dir
and ignores the virtual machine stuff.

Once the iso had been downloaded it invokes update-grub.

The script 50_testdrive should be placed at /etc/grub.d/
When update-grub is invoke it looks for iso files at
/var/cache/testdrive/iso and creates a boot menu for
booting directly into the iso.

To post a comment you must log in.
Dustin Kirkland  (kirkland) wrote :

This is a neat idea :-) We need to make sure, though, that it's well documented that this invocation of TestDrive would affect your real system and not a virtual machine.

Andres will need to review this merge proposal, since he has drastically changed TestDrive for the GTK bits.

Andres Rodriguez (andreserl) wrote :

HI Marcelo,

This is indeed a nice idea. Sorry for not reviewing it earlier but I've been busy with the GTK.

Anyways, would you please update your branch with the trunk to see if the latest changes of testdrive have affected yours. Once that done, please resubmit for review.

Thank you.

review: Needs Resubmitting
Jackson Doak (noskcaj) wrote :

i hope we can get this working now, it's a good idea

Unmerged revisions

243. By Marcelo Boveto Shima <mshima@note1> on 2010-06-01

Add grub support to testdrive

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '50_testdrive'
2--- 50_testdrive 1970-01-01 00:00:00 +0000
3+++ 50_testdrive 2010-06-01 04:14:22 +0000
4@@ -0,0 +1,71 @@
5+#!/bin/bash -e
6+# Created by Robert Wall, 2010-03-07
7+# Modified by Marcelo Boveto Shima, 2010-03-07
8+
9+#DEBUG=0
10+# Path to USB stick's current mountpoint
11+#boot_disk_mountpoint="`pwd`"
12+# path to location of ISOs
13+isolocation="/var/cache/testdrive/iso"
14+
15+# Others options at /usr/share/initramfs-tools/scripts/casper-bottom/ at casper/filesystem.squashfs
16+
17+OPTIONS="noeject noprompt quiet splash"
18+if [ ! -d "${boot_disk_mountpoint}${isolocation}" ]
19+then
20+ exit 0
21+fi
22+
23+if [ -n "$boot_disk_mountpoint" ]
24+then
25+ exec > "${boot_disk_mountpoint}/boot/grub/grub.cfg"
26+fi
27+
28+for isofile in ${boot_disk_mountpoint}${isolocation}/*.iso
29+do
30+ [ x$DEBUG == "x1" ] && echo "Trying $isofile" >&2
31+ relative_isofile=${isolocation}/`basename $isofile`
32+ TITLE=`isoinfo -R -x "/.disk/info" -i $isofile | sed "s/\"/'/g"`
33+ if [ -z "$TITLE" ]
34+ then
35+ TITLE=`isoinfo -R -d -i $isofile | grep -e "Volume id" | cut -d":" -f2 | sed "s/^ //"`
36+ fi
37+ if [ -z "$TITLE" ]
38+ then
39+ TITLE=`isoinfo -R -x "/README.diskdefines" -i $isofile | grep DISKNAME | cut -d' ' -f4- | sed "s/\"/'/g"`
40+ fi
41+ if [ -z "$TITLE" ]
42+ then
43+ TITLE=`basename $isofile .iso`
44+ fi
45+ TITLE="Testdrive: $TITLE"
46+ [ x$DEBUG == "x1" ] && echo "Title $TITLE" >&2
47+
48+ INSTALLER_LANG=`cat /etc/default/locale | grep "LANG=" | cut -d"\"" -f2 | cut -d"." -f1`
49+ if [ -n "$INSTALLER_LANG" ]
50+ then
51+ INSTALLER_LANG="debian-installer/language=$INSTALLER_LANG"
52+ fi
53+ [ x$DEBUG == "x1" ] && echo "Lang $INSTALLER_LANG" >&2
54+
55+ INITRD=`isoinfo -R -f -i $isofile | grep initrd | grep -e "\.gz$" -e "\.lz$" -e "\.img" | tail -n1`
56+ [ x$DEBUG == "x1" ] && echo "Initrd $INITRD" >&2
57+ VMLINUZ=`isoinfo -R -f -i $isofile | grep "vmlinuz" | tail -n1`
58+ [ x$DEBUG == "x1" ] && echo "Vmlinuz $VMLINUZ" >&2
59+
60+ if [ -z "$INITRD" -o -z "$VMLINUZ" ]
61+ then
62+ echo "File not found skipping" >&2
63+ exit 0
64+ fi
65+
66+ echo "Found $TITLE on $isofile" >&2
67+ cat <<EOF
68+menuentry "$TITLE" {
69+ loopback loop $relative_isofile
70+ linux (loop)$VMLINUZ boot=casper iso-scan/filename=$relative_isofile $OPTIONS $INSTALLER_LANG --
71+ initrd (loop)$INITRD
72+}
73+EOF
74+done
75+
76
77=== modified file 'testdrive'
78--- testdrive 2010-05-20 22:48:26 +0000
79+++ testdrive 2010-06-01 04:14:22 +0000
80@@ -136,6 +136,8 @@
81 help='try to launch usb-creator for further testing')
82 parser.add_option('-r', '--release', action='store', type='string', dest='release',
83 help='hardcode Ubuntu RELEASE codename')
84+ parser.add_option('-g', '--grub', action='store_true', dest='grub', default=False,
85+ help='put the iso into a system directory for grub')
86
87 (opt, args) = parser.parse_args()
88 info("version passed: %s" % opt.version)
89@@ -191,26 +193,35 @@
90 hasOptions = True
91 td.r = opt.release
92
93- # Choose the virtualization engine
94- if not td.VIRT:
95- td.VIRT = td.get_virt()
96- #NOTICE: Removed from get_virt() and placed here
97- if td.VIRT == 1:
98- error("Your CPU supports KVM acceleration; please install KVM:\n\
99- sudo apt-get install qemu-kvm")
100- if td.VIRT == 0:
101- error("Your CPU does not support acceleration; run kvm-ok for more information; then please install VirtualBox:\n\
102- kvm-ok\n\
103- sudo apt-get install virtualbox-ose")
104- if td.VIRT == "kvm":
105- info("Using KVM for virtual machine hosting...");
106- virt = kvm.KVM(td)
107- if td.VIRT == "virtualbox":
108- info("Using VirtualBox for virtual machine hosting...")
109- virt = virtualbox.VBox(td)
110- if td.VIRT == "paralels":
111- info("Using Parallels Desktop for virtual machine hosting...")
112- virt = parallels.Parallels(td)
113+ if opt.grub:
114+ grub_script = "/etc/grub.d/50_testdrive"
115+ info("Looking for %s" % grub_script)
116+ if not os.path.exists(grub_script):
117+ error("Grub script not installed.")
118+ td.CACHE = "/var/cache/testdrive"
119+ td.CACHE_ISO = "/var/cache/testdrive/iso"
120+ td.GRUB = True
121+ else:
122+ # Choose the virtualization engine
123+ if not td.VIRT:
124+ td.VIRT = td.get_virt()
125+ #NOTICE: Removed from get_virt() and placed here
126+ if td.VIRT == 1:
127+ error("Your CPU supports KVM acceleration; please install KVM:\n\
128+ sudo apt-get install qemu-kvm")
129+ if td.VIRT == 0:
130+ error("Your CPU does not support acceleration; run kvm-ok for more information; then please install VirtualBox:\n\
131+ kvm-ok\n\
132+ sudo apt-get install virtualbox-ose")
133+ if td.VIRT == "kvm":
134+ info("Using KVM for virtual machine hosting...");
135+ virt = kvm.KVM(td)
136+ if td.VIRT == "virtualbox":
137+ info("Using VirtualBox for virtual machine hosting...")
138+ virt = virtualbox.VBox(td)
139+ if td.VIRT == "paralels":
140+ info("Using Parallels Desktop for virtual machine hosting...")
141+ virt = parallels.Parallels(td)
142
143 # set defaults were undefined
144 td.set_defaults()
145@@ -269,6 +280,9 @@
146 if cmd != 0:
147 run_or_die(cmd)
148
149+ if opt.grub:
150+ run_or_die("update-grub")
151+ sys.exit(0)
152 # Launch the VM
153 info("Validating Virtualization Method....")
154 try:
155
156=== modified file 'testdrive.py'
157--- testdrive.py 2010-05-28 19:38:15 +0000
158+++ testdrive.py 2010-06-01 04:14:22 +0000
159@@ -42,6 +42,7 @@
160 self.r = None
161 self.PROTO = None
162 self.m = None
163+ self.GRUB = False
164
165 def set_values(self, var, value):
166 if var == 'kvm_args':
167@@ -70,6 +71,8 @@
168 self.u = value
169 if var == 'm':
170 self.m = [value]
171+ if var == 'grub':
172+ self.GRUB = [value]
173
174 def load_config_file(self, config_file):
175 cfg = ConfigParser.ConfigParser()
176@@ -128,11 +131,11 @@
177
178 if self.CACHE_IMG is None:
179 self.CACHE_IMG = '%s/img' % self.CACHE
180- if not os.path.exists(self.CACHE_IMG):
181+ if not self.GRUB and not os.path.exists(self.CACHE_IMG):
182 os.makedirs(self.CACHE_IMG, 0700)
183 # if running the image from /dev/shm, remove the image when done
184 # (unless CLEAN_IMG is set)
185- if self.CLEAN_IMG is None:
186+ if not self.GRUB and self.CLEAN_IMG is None:
187 if self.CACHE_IMG == '/dev/shm':
188 self.CLEAN_IMG = True
189 else:
190@@ -141,7 +144,12 @@
191 if self.CACHE_ISO is None:
192 self.CACHE_ISO = '%s/iso' % self.CACHE
193 if not os.path.exists(self.CACHE_ISO):
194- os.makedirs(self.CACHE_ISO, 0700)
195+ if not self.GRUB:
196+ os.makedirs(self.CACHE_ISO, 0700)
197+ else:
198+ os.makedirs(self.CACHE_ISO, 0755)
199+ if self.GRUB:
200+ return
201
202 if len(self.SMP) == 0:
203 self.SMP = commands.getoutput("grep -c ^processor /proc/cpuinfo")

Subscribers

People subscribed via source and target branches