Skip to content

Commit

Permalink
fix libguestfs mount order when inspecting
Browse files Browse the repository at this point in the history
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
Cherry picked: a8613dd
  • Loading branch information
jaypei authored and Pádraig Brady committed Aug 21, 2013
1 parent 37e3b55 commit 4918fd6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
10 changes: 9 additions & 1 deletion nova/tests/fakeguestfs.py
Expand Up @@ -25,6 +25,7 @@ def __init__(self):
self.files = {}
self.auginit = False
self.attach_method = 'libvirt'
self.root_mounted = False

def launch(self):
self.running = True
Expand All @@ -50,10 +51,17 @@ def inspect_os(self):
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):
Expand Down
5 changes: 4 additions & 1 deletion nova/tests/test_virt_disk_vfs_guestfs.py
Expand Up @@ -37,12 +37,15 @@ def test_appliance_setup_inspect(self):
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()
Expand Down
18 changes: 16 additions & 2 deletions nova/virt/disk/vfs/guestfs.py
Expand Up @@ -85,11 +85,25 @@ def setup_os_root(self, root):
_("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") %
Expand Down

0 comments on commit 4918fd6

Please sign in to comment.