@@ -11767,23 +11767,38 @@ def test_create_images_and_backing_images_not_exist_fallback(
11767
11767
instance = objects.Instance(**self.test_instance)
11768
11768
11769
11769
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
11770
11773
disk_info = [
11771
11774
{u'backing_file': backing_file,
11772
- u'disk_size': 10747904 ,
11775
+ u'disk_size': disk_size ,
11773
11776
u'path': u'disk_path',
11774
11777
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
11777
11788
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',
11780
11792
side_effect=exception.ImageNotFound(
11781
11793
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):
11783
11799
conn._create_images_and_backing(self.context, instance,
11784
11800
"/fake/instance/dir", disk_info,
11785
11801
fallback_from_host="fake_host")
11786
- backfile_path = os.path.join(base_dir, backing_file)
11787
11802
kernel_path = os.path.join(CONF.instances_path,
11788
11803
self.test_instance['uuid'],
11789
11804
'kernel')
@@ -11808,6 +11823,7 @@ def test_create_images_and_backing_images_not_exist_fallback(
11808
11823
mock.call(self.context, ramdisk_path, instance.ramdisk_id,
11809
11824
trusted_certs)
11810
11825
])
11826
+ resize_image_mock.assert_called_once_with(virt_disk_size)
11811
11827
11812
11828
mock_utime.assert_called()
11813
11829
mock_create_cow_image.assert_called_once_with(
0 commit comments