@@ -13726,6 +13726,67 @@ def fake_copy_image(src, dest, **kwargs):
13726
13726
mock_create_cow_image.assert_called_once_with(
13727
13727
backfile_path, '/fake/instance/dir/disk_path', virt_disk_size)
13728
13728
13729
+ @mock.patch('nova.virt.libvirt.imagebackend.Image.exists',
13730
+ new=mock.Mock(return_value=True))
13731
+ def test_create_images_backing_images_and_fallback_not_exist(self):
13732
+ self.flags(images_type='raw', group='libvirt')
13733
+ conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
13734
+
13735
+ base_dir = os.path.join(CONF.instances_path,
13736
+ CONF.image_cache.subdirectory_name)
13737
+ self.test_instance.update({
13738
+ 'user_id': 'fake-user',
13739
+ 'os_type': None,
13740
+ 'kernel_id': uuids.kernel_id,
13741
+ 'ramdisk_id': uuids.ramdisk_id,
13742
+ 'project_id': 'fake-project'
13743
+ })
13744
+ instance = objects.Instance(**self.test_instance)
13745
+
13746
+ backing_file = imagecache.get_cache_fname(instance.image_ref)
13747
+ backfile_path = os.path.join(base_dir, backing_file)
13748
+ disk_size = 10747904
13749
+ virt_disk_size = 25165824
13750
+ disk_info = [{
13751
+ 'backing_file': backing_file,
13752
+ 'disk_size': disk_size,
13753
+ 'path': 'disk_path',
13754
+ 'type': 'raw',
13755
+ 'virt_disk_size': virt_disk_size
13756
+ }]
13757
+
13758
+ with test.nested(
13759
+ mock.patch.object(libvirt_driver.libvirt_utils, 'copy_image'),
13760
+ mock.patch.object(libvirt_driver.libvirt_utils, 'fetch_image',
13761
+ side_effect=exception.ImageNotFound(
13762
+ image_id=uuids.fake_id)),
13763
+ mock.patch.object(imagebackend.Flat, 'resize_image'),
13764
+ ) as (copy_image_mock, fetch_image_mock, resize_image_mock):
13765
+ conn._create_images_and_backing(
13766
+ self.context, instance, "/fake/instance/dir", disk_info,
13767
+ fallback_from_host="fake_host")
13768
+ kernel_path = os.path.join(CONF.instances_path,
13769
+ self.test_instance['uuid'], 'kernel')
13770
+ ramdisk_path = os.path.join(CONF.instances_path,
13771
+ self.test_instance['uuid'], 'ramdisk')
13772
+ copy_image_mock.assert_has_calls([
13773
+ mock.call(dest=kernel_path, src=kernel_path,
13774
+ host='fake_host', receive=True),
13775
+ mock.call(dest=ramdisk_path, src=ramdisk_path,
13776
+ host='fake_host', receive=True)
13777
+ ])
13778
+ fetch_image_mock.assert_has_calls([
13779
+ mock.call(context=self.context,
13780
+ target=backfile_path,
13781
+ image_id=self.test_instance['image_ref'],
13782
+ trusted_certs=None),
13783
+ mock.call(self.context, kernel_path, instance.kernel_id,
13784
+ None),
13785
+ mock.call(self.context, ramdisk_path, instance.ramdisk_id,
13786
+ None)
13787
+ ])
13788
+ resize_image_mock.assert_called_once_with(virt_disk_size)
13789
+
13729
13790
@mock.patch('nova.virt.libvirt.utils.create_image',
13730
13791
new=mock.NonCallableMock())
13731
13792
@mock.patch.object(libvirt_driver.libvirt_utils, 'fetch_image')
0 commit comments