diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-01-04 10:05:34 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-01-04 10:05:34 +0000 |
| commit | e4b5abcdb34bed91a8033b24cf47dad60c670604 (patch) | |
| tree | 4cd4b45a6e702fcc121484ca910120bf07626dae | |
| parent | b6843ad968ca03797d968625e8bec814caa42aa0 (diff) | |
| parent | 54ee787d7ae1d7635bd5dac8efd985e3a93ad1c2 (diff) | |
| download | nova-e4b5abcdb34bed91a8033b24cf47dad60c670604.tar.gz nova-e4b5abcdb34bed91a8033b24cf47dad60c670604.tar.xz nova-e4b5abcdb34bed91a8033b24cf47dad60c670604.zip | |
Merge "fix resize of unpartitioned images with libguestfs"
| -rw-r--r-- | nova/virt/disk/api.py | 12 | ||||
| -rw-r--r-- | nova/virt/disk/vfs/guestfs.py | 21 |
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 |
