From da6cb543df6692dcc0ea66f9fde1c3ff3f7999a1 Mon Sep 17 00:00:00 2001 From: Sahid Orentino Ferdjaoui Date: Wed, 28 Sep 2016 07:49:45 -0400 Subject: [PATCH] libvirt: fix DiskSmallerThanImage when block migrate ephemerals When block live migrate an instance with ephemerals an exception FlavorDiskSmallerThanImage can be raised because the size used to create the base ephemeral disk is the total size allowed by flavor which can be greater than the size effectively requested by the instance when spwaned. Closes-Bug: #1628449 Change-Id: I264f5beb73d9b8ba441aec8f8a317b553a7e22c0 (cherry picked from commit 407e659eb9c228eb1ec06ec49864279aeab0a1a1) --- nova/tests/unit/virt/libvirt/test_driver.py | 8 ++++---- nova/virt/libvirt/driver.py | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 49aac4585cba..d322484476a5 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -9252,10 +9252,11 @@ class LibvirtConnTestCase(test.NoDBTestCase): CONF.image_cache_subdirectory_name) instance = objects.Instance(**self.test_instance) disk_info_byname = fake_disk_info_byname(instance) - disk_info = disk_info_byname.values() - # Give the ephemeral disk a non-default name disk_info_byname['disk.local']['backing_file'] = 'ephemeral_foo' + disk_info_byname['disk.local']['virt_disk_size'] = 1 * units.Gi + + disk_info = disk_info_byname.values() with test.nested( mock.patch.object(libvirt_driver.libvirt_utils, 'fetch_image'), @@ -9283,8 +9284,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): verify_base_size_mock.assert_has_calls([ mock.call(root_backing, instance.flavor.root_gb * units.Gi), - mock.call(ephemeral_backing, - instance.flavor.ephemeral_gb * units.Gi) + mock.call(ephemeral_backing, 1 * units.Gi) ]) def test_create_images_and_backing_disk_info_none(self): diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 19b15e7847ac..668681f50b8a 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -6587,12 +6587,19 @@ class LibvirtDriver(driver.ComputeDriver): instance_disk, CONF.libvirt.images_type) if cache_name.startswith('ephemeral'): - image.cache(fetch_func=self._create_ephemeral, - fs_label=cache_name, - os_type=instance.os_type, - filename=cache_name, - size=info['virt_disk_size'], - ephemeral_size=instance.flavor.ephemeral_gb) + # The argument 'size' is used by image.cache to + # validate disk size retrieved from cache against + # the instance disk size (should always return OK) + # and ephemeral_size is used by _create_ephemeral + # to build the image if the disk is not already + # cached. + image.cache( + fetch_func=self._create_ephemeral, + fs_label=cache_name, + os_type=instance.os_type, + filename=cache_name, + size=info['virt_disk_size'], + ephemeral_size=info['virt_disk_size'] / units.Gi) elif cache_name.startswith('swap'): inst_type = instance.get_flavor() swap_mb = inst_type.swap