fix libguestfs mount order when inspecting

variable `mounts` sorted value is
[
    ('/boot', '/dev/vda1'),
    ('/', '/dev/vda2'),
    ('/var', '/dev/vda5'),
    ('/home', '/dev/vda6'),
    ('/home/q', '/dev/vda7')
]
but `/boot` directory is in `/` partition.

Fixes: Bug #1210371
Change-Id: I3d9cd59237bc4fc277415104c9170d2e372a1c25
This commit is contained in:
jaypei
2013-08-08 16:26:06 +08:00
parent c4e7df7a98
commit a8613dd593
3 changed files with 29 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ class GuestFS(object):
self.files = {}
self.auginit = False
self.attach_method = 'libvirt'
self.root_mounted = False
def launch(self):
self.running = True
@@ -50,10 +51,17 @@ class GuestFS(object):
return ["/dev/guestvgf/lv_root"]
def inspect_get_mountpoints(self, dev):
return [["/", "/dev/mapper/guestvgf-lv_root"],
return [["/home", "/dev/mapper/guestvgf-lv_home"],
["/", "/dev/mapper/guestvgf-lv_root"],
["/boot", "/dev/vda1"]]
def mount_options(self, options, device, mntpoint):
if mntpoint == "/":
self.root_mounted = True
else:
if not self.root_mounted:
raise RuntimeError(
"mount: %s: No such file or directory" % mntpoint)
self.mounts.append((options, device, mntpoint))
def mkdir_p(self, path):

View File

@@ -37,12 +37,15 @@ class VirtDiskVFSGuestFSTest(test.TestCase):
vfs.setup()
self.assertEqual(vfs.handle.running, True)
self.assertEqual(len(vfs.handle.mounts), 2)
self.assertEqual(len(vfs.handle.mounts), 3)
self.assertEqual(vfs.handle.mounts[0][1],
"/dev/mapper/guestvgf-lv_root")
self.assertEqual(vfs.handle.mounts[1][1], "/dev/vda1")
self.assertEqual(vfs.handle.mounts[2][1],
"/dev/mapper/guestvgf-lv_home")
self.assertEqual(vfs.handle.mounts[0][2], "/")
self.assertEqual(vfs.handle.mounts[1][2], "/boot")
self.assertEqual(vfs.handle.mounts[2][2], "/home")
handle = vfs.handle
vfs.teardown()

View File

@@ -86,11 +86,25 @@ class VFSGuestFS(vfs.VFS):
_("No mount points found in %(root)s of %(imgfile)s") %
{'root': root, 'imgfile': self.imgfile})
mounts.sort(key=lambda mount: mount[1])
# the root directory must be mounted first
mounts.sort(key=lambda mount: mount[0])
root_mounted = False
for mount in mounts:
LOG.debug(_("Mounting %(dev)s at %(dir)s") %
{'dev': mount[1], 'dir': mount[0]})
self.handle.mount_options("", mount[1], mount[0])
try:
self.handle.mount_options("", mount[1], mount[0])
root_mounted = True
except RuntimeError as e:
msg = _("Error mounting %(device)s to %(dir)s in image"
" %(imgfile)s with libguestfs (%(e)s)") % \
{'imgfile': self.imgfile, 'device': mount[1],
'dir': mount[0], 'e': e}
if root_mounted:
LOG.debug(msg)
else:
raise exception.NovaException(msg)
def setup(self):
LOG.debug(_("Setting up appliance for %(imgfile)s %(imgfmt)s") %