@@ -13618,6 +13618,67 @@ def fake_copy_image(src, dest, **kwargs):
13618
13618
mock_create_cow_image.assert_called_once_with(
13619
13619
backfile_path, '/fake/instance/dir/disk_path')
13620
13620
13621
+ @mock.patch('nova.virt.libvirt.imagebackend.Image.exists',
13622
+ new=mock.Mock(return_value=True))
13623
+ def test_create_images_backing_images_and_fallback_not_exist(self):
13624
+ self.flags(images_type='raw', group='libvirt')
13625
+ conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
13626
+
13627
+ base_dir = os.path.join(CONF.instances_path,
13628
+ CONF.image_cache.subdirectory_name)
13629
+ self.test_instance.update({
13630
+ 'user_id': 'fake-user',
13631
+ 'os_type': None,
13632
+ 'kernel_id': uuids.kernel_id,
13633
+ 'ramdisk_id': uuids.ramdisk_id,
13634
+ 'project_id': 'fake-project'
13635
+ })
13636
+ instance = objects.Instance(**self.test_instance)
13637
+
13638
+ backing_file = imagecache.get_cache_fname(instance.image_ref)
13639
+ backfile_path = os.path.join(base_dir, backing_file)
13640
+ disk_size = 10747904
13641
+ virt_disk_size = 25165824
13642
+ disk_info = [{
13643
+ 'backing_file': backing_file,
13644
+ 'disk_size': disk_size,
13645
+ 'path': 'disk_path',
13646
+ 'type': 'raw',
13647
+ 'virt_disk_size': virt_disk_size
13648
+ }]
13649
+
13650
+ with test.nested(
13651
+ mock.patch.object(libvirt_driver.libvirt_utils, 'copy_image'),
13652
+ mock.patch.object(libvirt_driver.libvirt_utils, 'fetch_image',
13653
+ side_effect=exception.ImageNotFound(
13654
+ image_id=uuids.fake_id)),
13655
+ mock.patch.object(imagebackend.Flat, 'resize_image'),
13656
+ ) as (copy_image_mock, fetch_image_mock, resize_image_mock):
13657
+ conn._create_images_and_backing(
13658
+ self.context, instance, "/fake/instance/dir", disk_info,
13659
+ fallback_from_host="fake_host")
13660
+ kernel_path = os.path.join(CONF.instances_path,
13661
+ self.test_instance['uuid'], 'kernel')
13662
+ ramdisk_path = os.path.join(CONF.instances_path,
13663
+ self.test_instance['uuid'], 'ramdisk')
13664
+ copy_image_mock.assert_has_calls([
13665
+ mock.call(dest=kernel_path, src=kernel_path,
13666
+ host='fake_host', receive=True),
13667
+ mock.call(dest=ramdisk_path, src=ramdisk_path,
13668
+ host='fake_host', receive=True)
13669
+ ])
13670
+ fetch_image_mock.assert_has_calls([
13671
+ mock.call(context=self.context,
13672
+ target=backfile_path,
13673
+ image_id=self.test_instance['image_ref'],
13674
+ trusted_certs=None),
13675
+ mock.call(self.context, kernel_path, instance.kernel_id,
13676
+ None),
13677
+ mock.call(self.context, ramdisk_path, instance.ramdisk_id,
13678
+ None)
13679
+ ])
13680
+ resize_image_mock.assert_called_once_with(virt_disk_size)
13681
+
13621
13682
@mock.patch('nova.virt.libvirt.utils.create_image',
13622
13683
new=mock.NonCallableMock())
13623
13684
@mock.patch.object(libvirt_driver.libvirt_utils, 'fetch_image')
0 commit comments