From 407e659eb9c228eb1ec06ec49864279aeab0a1a1 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 --- 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 c440d6466004..cd01fe81fd88 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -9307,10 +9307,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'), @@ -9338,8 +9339,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 dacccf1bf1b5..05bfc1a22825 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -6608,12 +6608,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