From d62e43f3e39eaa37e8321a4bfaee577aeb0d7cbd Mon Sep 17 00:00:00 2001 From: Dennis Dmitriev Date: Tue, 19 Jul 2016 17:05:03 +0300 Subject: [PATCH] Fix for qcow2 volume resize If qcow2 volume has bigger size than specified for the volume with the attribute 'capacity', qemu-img fails to shrink such image. - do not fail if the image cannot be shrinked to specified size Change-Id: I8560e04657eb6570c43ebe07ddd5aa4975de9aec Closes-Bug:#1546635 --- devops/driver/libvirt/libvirt_driver.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/devops/driver/libvirt/libvirt_driver.py b/devops/driver/libvirt/libvirt_driver.py index aa12c74b..cb8dfba3 100644 --- a/devops/driver/libvirt/libvirt_driver.py +++ b/devops/driver/libvirt/libvirt_driver.py @@ -780,8 +780,18 @@ class LibvirtVolume(Volume): if capacity > size: # Resize the uploaded image to specified capacity - self._libvirt_volume.resize(capacity) - self.save() + try: + self._libvirt_volume.resize(capacity) + self.save() + except libvirt.libvirtError: + err = libvirt.virGetLastError() + if (err[0] == libvirt.VIR_ERR_INVALID_ARG and + err[1] == libvirt.VIR_FROM_STORAGE): + logger.error( + "Cannot resize volume {0}: {1}" + .format(self._libvirt_volume.path(), err[2])) + else: + raise def get_allocation(self): """Get allocated volume size