Merge lp:~cjwatson/vmbuilder/chroot-grub into lp:vmbuilder/trunk

Proposed by Colin Watson
Status: Merged
Approved by: Soren Hansen
Approved revision: 351
Merged at revision: not available
Proposed branch: lp:~cjwatson/vmbuilder/chroot-grub
Merge into: lp:vmbuilder/trunk
Diff against target: 46 lines
1 file modified
VMBuilder/plugins/ubuntu/distro.py (+20/-4)
To merge this branch: bzr merge lp:~cjwatson/vmbuilder/chroot-grub
Reviewer Review Type Date Requested Status
Soren Hansen Approve
Review via email: mp+12865@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Soren Hansen (soren) wrote :

On Mon, Oct 05, 2009 at 11:10:25AM -0000, Colin Watson wrote:
> + def install_bootloader_cleanup(self):
> + self.vm.cancel_cleanup(self.install_bootloader_cleanup)

Clever! I can think of a bunch of places this would be useful.

The rest looks great as well. Thank you!

 merge approved

--
Soren Hansen |
Lead virtualisation engineer | Ubuntu Server Team
Canonical Ltd. | http://www.ubuntu.com/

review: Approve
Revision history for this message
Colin Watson (cjwatson) wrote :

On Thu, Oct 08, 2009 at 10:48:12AM -0000, Soren Hansen wrote:
> On Mon, Oct 05, 2009 at 11:10:25AM -0000, Colin Watson wrote:
> > + def install_bootloader_cleanup(self):
> > + self.vm.cancel_cleanup(self.install_bootloader_cleanup)
>
> Clever! I can think of a bunch of places this would be useful.

Not my idea, actually; I borrowed it from
VMBuilder.disk.Filesystem.umount. :-)

--
Colin Watson [<email address hidden>]

Revision history for this message
Soren Hansen (soren) wrote :

On Thu, Oct 08, 2009 at 10:54:11AM -0000, Colin Watson wrote:
>On Thu, Oct 08, 2009 at 10:48:12AM -0000, Soren Hansen wrote:
>> On Mon, Oct 05, 2009 at 11:10:25AM -0000, Colin Watson wrote:
>>> + def install_bootloader_cleanup(self):
>>> + self.vm.cancel_cleanup(self.install_bootloader_cleanup)
>>
>> Clever! I can think of a bunch of places this would be useful.
> Not my idea, actually; I borrowed it from
> VMBuilder.disk.Filesystem.umount. :-)

Wow, and "bzr blame" says I wrote that bit. Talk about a brief moment of
clarity :)

--
Soren Hansen |
Lead virtualisation engineer | Ubuntu Server Team
Canonical Ltd. | http://www.ubuntu.com/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'VMBuilder/plugins/ubuntu/distro.py'
--- VMBuilder/plugins/ubuntu/distro.py 2009-09-15 10:33:37 +0000
+++ VMBuilder/plugins/ubuntu/distro.py 2009-10-05 11:10:24 +0000
@@ -20,6 +20,7 @@
20import os20import os
21import socket21import socket
22import types22import types
23import shutil
23import VMBuilder24import VMBuilder
24from VMBuilder import register_distro, Distro25from VMBuilder import register_distro, Distro
25from VMBuilder.util import run_cmd26from VMBuilder.util import run_cmd
@@ -155,15 +156,30 @@
155 def use_virtio_net(self):156 def use_virtio_net(self):
156 return self.suite.virtio_net157 return self.suite.virtio_net
157158
159 def install_bootloader_cleanup(self):
160 self.vm.cancel_cleanup(self.install_bootloader_cleanup)
161 tmpdir = '%s/tmp/vmbuilder-grub' % self.destdir
162 for disk in os.listdir(tmpdir):
163 if disk != 'device.map':
164 run_cmd('umount', os.path.join(tmpdir, disk))
165 shutil.rmtree(tmpdir)
166
158 def install_bootloader(self):167 def install_bootloader(self):
159 devmapfile = '%s/device.map' % self.vm.workdir168 tmpdir = '/tmp/vmbuilder-grub'
160 devmap = open(devmapfile, 'w')169 os.makedirs('%s%s' % (self.destdir, tmpdir))
170 self.vm.add_clean_cb(self.install_bootloader_cleanup)
171 devmapfile = os.path.join(tmpdir, 'device.map')
172 devmap = open('%s%s' % (self.destdir, devmapfile), 'w')
161 for (disk, id) in zip(self.vm.disks, range(len(self.vm.disks))):173 for (disk, id) in zip(self.vm.disks, range(len(self.vm.disks))):
162 devmap.write("(hd%d) %s\n" % (id, disk.filename))174 new_filename = os.path.join(tmpdir, os.path.basename(disk.filename))
175 open('%s%s' % (self.destdir, new_filename), 'w').close()
176 run_cmd('mount', '--bind', disk.filename, '%s%s' % (self.destdir, new_filename))
177 devmap.write("(hd%d) %s\n" % (id, new_filename))
163 devmap.close()178 devmap.close()
164 run_cmd('grub', '--device-map=%s' % devmapfile, '--batch', stdin='''root (hd0,0)179 self.run_in_target('grub', '--device-map=%s' % devmapfile, '--batch', stdin='''root (hd0,0)
165setup (hd0)180setup (hd0)
166EOT''')181EOT''')
182 self.install_bootloader_cleanup()
167183
168 def xen_kernel_version(self):184 def xen_kernel_version(self):
169 if self.suite.xen_kernel_flavour:185 if self.suite.xen_kernel_flavour: