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
This commit is contained in:
parent
7a9eb10d0d
commit
407e659eb9
@ -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):
|
||||
|
@ -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,
|
||||
# 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=instance.flavor.ephemeral_gb)
|
||||
ephemeral_size=info['virt_disk_size'] / units.Gi)
|
||||
elif cache_name.startswith('swap'):
|
||||
inst_type = instance.get_flavor()
|
||||
swap_mb = inst_type.swap
|
||||
|
Loading…
Reference in New Issue
Block a user