summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorPádraig Brady <pbrady@redhat.com>2013-01-03 03:09:00 +0000
committerPádraig Brady <pbrady@redhat.com>2013-01-03 18:12:19 +0000
commit54ee787d7ae1d7635bd5dac8efd985e3a93ad1c2 (patch)
tree8e610449e9fc4a6dd59c67a3b7b8629706ad5535 /nova/virt
parent1b1b955e86086054496f96e0d9a2631ee5dd678f (diff)
downloadnova-54ee787d7ae1d7635bd5dac8efd985e3a93ad1c2.tar.gz
nova-54ee787d7ae1d7635bd5dac8efd985e3a93ad1c2.tar.xz
nova-54ee787d7ae1d7635bd5dac8efd985e3a93ad1c2.zip
fix resize of unpartitioned images with libguestfs
Following on from I9c974e138ff90e8b7a5a40f5b31dcdb25a59622d Ensure that the libguestfs path also throws a NovaException, handled by can_resize_fs(). * nova/virt/disk/vfs/guestfs.py (setup): Move the debug message and guestfs handle outside the exception handler as we don't want to map failure of those to a NovaException that indicates an issue with the image as opposed to the nova code or libguestfs installation. Change to a more explicit exception thrown by guestfs, so as to avoid masking other issues. (teardown): Remove redundant calls to str(). * nova/virt/disk/api.py (can_resize_fs): Cleanup the debug messages, and use the newer vfs API directly, rather than the slightly hacky call to inject_data() with no data to inject. Fixes bug: 1094373 Change-Id: I3e1305cf6bb64278a8caf37e4c5005cb9683f632
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/disk/api.py12
-rw-r--r--nova/virt/disk/vfs/guestfs.py21
2 files changed, 20 insertions, 13 deletions
diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py
index f663515cd..a93cf261e 100644
--- a/nova/virt/disk/api.py
+++ b/nova/virt/disk/api.py
@@ -124,6 +124,9 @@ def extend(image, size):
def can_resize_fs(image, size, use_cow=False):
"""Check whether we can resize contained file system."""
+ LOG.debug(_('Checking if we can resize image %(image)s. '
+ 'size=%(size)s, CoW=%(use_cow)s'), locals())
+
# Check that we're increasing the size
virt_size = get_disk_size(image)
if virt_size >= size:
@@ -133,19 +136,18 @@ def can_resize_fs(image, size, use_cow=False):
# Check the image is unpartitioned
if use_cow:
- # Try to mount an unpartitioned qcow2 image
- LOG.debug(_('Checking if we can resize the COW image %s.'), image)
try:
- inject_data(image, use_cow=True)
+ fs = vfs.VFS.instance_for_image(image, 'qcow2', None)
+ fs.setup()
+ fs.teardown()
except exception.NovaException, e:
- LOG.debug(_('File injection failed for image %(image)s with '
+ LOG.debug(_('Unable to mount image %(image)s with '
'error %(error)s. Cannot resize.'),
{'image': image,
'error': e})
return False
else:
# For raw, we can directly inspect the file system
- LOG.debug(_('Checking if we can resize the non-COW image %s.'), image)
try:
utils.execute('e2label', image)
except exception.ProcessExecutionError, e:
diff --git a/nova/virt/disk/vfs/guestfs.py b/nova/virt/disk/vfs/guestfs.py
index 5fe599b89..66c6849d4 100644
--- a/nova/virt/disk/vfs/guestfs.py
+++ b/nova/virt/disk/vfs/guestfs.py
@@ -89,18 +89,23 @@ class VFSGuestFS(vfs.VFS):
self.handle.mount_options("", mount[1], mount[0])
def setup(self):
- try:
- LOG.debug(_("Setting up appliance for %(imgfile)s %(imgfmt)s") %
- {'imgfile': self.imgfile, 'imgfmt': self.imgfmt})
- self.handle = guestfs.GuestFS()
+ LOG.debug(_("Setting up appliance for %(imgfile)s %(imgfmt)s") %
+ {'imgfile': self.imgfile, 'imgfmt': self.imgfmt})
+ self.handle = guestfs.GuestFS()
+ try:
self.handle.add_drive_opts(self.imgfile, format=self.imgfmt)
self.handle.launch()
self.setup_os()
self.handle.aug_init("/", 0)
- except Exception, e:
+ except RuntimeError, e:
+ self.handle = None
+ raise exception.NovaException(
+ _("Error mounting %(imgfile)s with libguestfs (%(e)s)") %
+ {'imgfile': self.imgfile, 'e': e})
+ except Exception:
self.handle = None
raise
@@ -109,15 +114,15 @@ class VFSGuestFS(vfs.VFS):
try:
self.handle.aug_close()
except Exception, e:
- LOG.debug(_("Failed to close augeas %s"), str(e))
+ LOG.debug(_("Failed to close augeas %s"), e)
try:
self.handle.shutdown()
except Exception, e:
- LOG.debug(_("Failed to shutdown appliance %s"), str(e))
+ LOG.debug(_("Failed to shutdown appliance %s"), e)
try:
self.handle.close()
except Exception, e:
- LOG.debug(_("Failed to close guest handle %s"), str(e))
+ LOG.debug(_("Failed to close guest handle %s"), e)
self.handle = None
@staticmethod