Skip to content

Commit c1782ba

Browse files
author
Alexandre Arents
committed
Fix live-migration when glance image deleted
When block live-migration is run on instance with a deleted glance image, image.cache() is called without specyfing instance disk size parameter, preventing the resize of disk on the target host. Change-Id: Id0f05bb1275cc816d98b662820e02eae25dc57a3 Closes-Bug: #1829000
1 parent 66a77f2 commit c1782ba

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11767,23 +11767,38 @@ def test_create_images_and_backing_images_not_exist_fallback(
1176711767
instance = objects.Instance(**self.test_instance)
1176811768

1176911769
backing_file = imagecache.get_cache_fname(instance.image_ref)
11770+
backfile_path = os.path.join(base_dir, backing_file)
11771+
disk_size = 10747904
11772+
virt_disk_size = 25165824
1177011773
disk_info = [
1177111774
{u'backing_file': backing_file,
11772-
u'disk_size': 10747904,
11775+
u'disk_size': disk_size,
1177311776
u'path': u'disk_path',
1177411777
u'type': u'qcow2',
11775-
u'virt_disk_size': 25165824}]
11776-
11778+
u'virt_disk_size': virt_disk_size}]
11779+
11780+
def fake_copy_image(src, dest, **kwargs):
11781+
# backing file should be present and have a smaller size
11782+
# than instance root disk in order to assert resize_image()
11783+
if dest == backfile_path:
11784+
# dest is created under TempDir() fixture,
11785+
# it will go away after test cleanup
11786+
with open(dest, 'a'):
11787+
pass
1177711788
with test.nested(
11778-
mock.patch('nova.virt.libvirt.utils.copy_image'),
11779-
mock.patch('nova.virt.libvirt.utils.fetch_image',
11789+
mock.patch.object(libvirt_driver.libvirt_utils, 'copy_image',
11790+
side_effect=fake_copy_image),
11791+
mock.patch.object(libvirt_driver.libvirt_utils, 'fetch_image',
1178011792
side_effect=exception.ImageNotFound(
1178111793
image_id=uuids.fake_id)),
11782-
) as (copy_image_mock, fetch_image_mock):
11794+
mock.patch.object(imagebackend.Qcow2, 'resize_image'),
11795+
mock.patch.object(imagebackend.Image, 'get_disk_size',
11796+
return_value=disk_size),
11797+
) as (copy_image_mock, fetch_image_mock, resize_image_mock,
11798+
get_disk_size_mock):
1178311799
conn._create_images_and_backing(self.context, instance,
1178411800
"/fake/instance/dir", disk_info,
1178511801
fallback_from_host="fake_host")
11786-
backfile_path = os.path.join(base_dir, backing_file)
1178711802
kernel_path = os.path.join(CONF.instances_path,
1178811803
self.test_instance['uuid'],
1178911804
'kernel')
@@ -11808,6 +11823,7 @@ def test_create_images_and_backing_images_not_exist_fallback(
1180811823
mock.call(self.context, ramdisk_path, instance.ramdisk_id,
1180911824
trusted_certs)
1181011825
])
11826+
resize_image_mock.assert_called_once_with(virt_disk_size)
1181111827

1181211828
mock_utime.assert_called()
1181311829
mock_create_cow_image.assert_called_once_with(

nova/virt/libvirt/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8432,7 +8432,7 @@ def copy_from_host(target):
84328432
dest=target,
84338433
host=fallback_from_host,
84348434
receive=True)
8435-
image.cache(fetch_func=copy_from_host,
8435+
image.cache(fetch_func=copy_from_host, size=size,
84368436
filename=filename)
84378437

84388438
def _create_images_and_backing(self, context, instance, instance_dir,

0 commit comments

Comments
 (0)