libvirt: fix _disk_resize to make sure converted image will be restored

During the process of resizing disk if an image is in qcow2 with
partition less the process converts the image to raw.
After the extend we should to restore the original format in all cases
not only if 'use_cow_images' is configured to True.

Change-Id: I792e0fb986a6c5cf9ac477cef0949c8a40099faa
Closes-Bug: #1298976
This commit is contained in:
Sahid Orentino Ferdjaoui 2014-08-12 09:55:43 +02:00
parent 05dbf0d97d
commit 7b15ed36cd
2 changed files with 4 additions and 47 deletions
nova
tests/virt/libvirt
virt/libvirt

@ -9578,26 +9578,9 @@ class LibvirtDriverTestCase(test.TestCase):
def test_disk_resize_raw(self, mock_extend):
info = {'type': 'raw', 'path': '/test/disk'}
self.flags(use_cow_images=False)
self.libvirtconnection._disk_resize(info, 50)
mock_extend.assert_called_once_with(info['path'], 50, use_cow=False)
@mock.patch('nova.virt.disk.api.extend')
def test_disk_resize_raw_use_cow_images(self, mock_extend):
info = {'type': 'raw', 'path': '/test/disk'}
self.flags(use_cow_images=True)
with mock.patch.object(
self.libvirtconnection, '_disk_raw_to_qcow2') as mock_convert:
self.libvirtconnection._disk_resize(info, 50)
mock_convert.assert_called_once_with(info['path'])
mock_extend.assert_called_once_with(
info['path'], 50, use_cow=False)
@mock.patch('nova.virt.disk.api.can_resize_image')
@mock.patch('nova.virt.disk.api.is_image_partitionless')
@mock.patch('nova.virt.disk.api.extend')
@ -9605,34 +9588,6 @@ class LibvirtDriverTestCase(test.TestCase):
self, mock_extend, mock_can_resize, mock_is_partitionless):
info = {'type': 'qcow2', 'path': '/test/disk'}
self.flags(use_cow_images=False)
with contextlib.nested(
mock.patch.object(
self.libvirtconnection, '_disk_qcow2_to_raw'),
mock.patch.object(
self.libvirtconnection, '_disk_raw_to_qcow2'))\
as (mock_disk_qcow2_to_raw, mock_disk_raw_to_qcow2):
mock_can_resize.return_value = True
mock_is_partitionless.return_value = True
self.libvirtconnection._disk_resize(info, 50)
mock_disk_qcow2_to_raw.assert_called_once_with(info['path'])
mock_extend.assert_called_once_with(
info['path'], 50, use_cow=False)
self.assertFalse(mock_disk_raw_to_qcow2.called)
@mock.patch('nova.virt.disk.api.can_resize_image')
@mock.patch('nova.virt.disk.api.is_image_partitionless')
@mock.patch('nova.virt.disk.api.extend')
def test_disk_resize_qcow2_use_cow_images(
self, mock_extend, mock_can_resize, mock_is_partitionless):
info = {'type': 'qcow2', 'path': '/test/disk'}
self.flags(use_cow_images=True)
with contextlib.nested(
mock.patch.object(
self.libvirtconnection, '_disk_qcow2_to_raw'),

@ -5252,7 +5252,7 @@ class LibvirtDriver(driver.ComputeDriver):
"""
# If we have a non partitioned image that we can extend
# then ensure we're in 'raw' format so we can extend file system.
fmt = info['type']
fmt, org = [info['type']] * 2
pth = info['path']
if (size and fmt == 'qcow2' and
disk.can_resize_image(pth, size) and
@ -5264,7 +5264,7 @@ class LibvirtDriver(driver.ComputeDriver):
use_cow = fmt == 'qcow2'
disk.extend(pth, size, use_cow=use_cow)
if fmt == 'raw' and CONF.use_cow_images:
if fmt != org:
# back to qcow2 (no backing_file though) so that snapshot
# will be available
self._disk_raw_to_qcow2(pth)
@ -5279,6 +5279,8 @@ class LibvirtDriver(driver.ComputeDriver):
for info in disk_info:
size = self._disk_size_from_instance(instance, info)
self._disk_resize(info, size)
if info['type'] == 'raw' and CONF.use_cow_images:
self._disk_raw_to_qcow2(info['path'])
disk_info = blockinfo.get_disk_info(CONF.libvirt.virt_type,
instance,