Skip to content

Commit f7af85d

Browse files
Pierre LIBEAUplibeau
authored andcommitted
Nova resize don't extend disk in one specific case
Nova resize not apply extend virtual size of the instance if the image is not accessible by the customer (public image use to build the instance is now private image because this image is deprecated) and the source compute of the resize don't have anymore the base image. Related-Bug: #1558880 Change-Id: I4d6dfca1efe10caebb017b6ec96820979018203f
1 parent 52b974a commit f7af85d

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13618,6 +13618,67 @@ def fake_copy_image(src, dest, **kwargs):
1361813618
mock_create_cow_image.assert_called_once_with(
1361913619
backfile_path, '/fake/instance/dir/disk_path')
1362013620

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+
1362113682
@mock.patch('nova.virt.libvirt.utils.create_image',
1362213683
new=mock.NonCallableMock())
1362313684
@mock.patch.object(libvirt_driver.libvirt_utils, 'fetch_image')

nova/virt/libvirt/imagebackend.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,21 @@ def create_image(self, prepare_template, base, size, *args, **kwargs):
568568
def copy_raw_image(base, target, size):
569569
libvirt_utils.copy_image(base, target)
570570
if size:
571-
image = imgmodel.LocalFileImage(target,
572-
self.driver_format)
573-
disk.extend(image, size)
571+
self.resize_image(size)
574572

575573
generating = 'image_id' not in kwargs
576574
if generating:
577575
if not self.exists():
578576
# Generating image in place
579577
prepare_template(target=self.path, *args, **kwargs)
578+
579+
# NOTE(plibeau): extend the disk in the case of image is not
580+
# accessible anymore by the customer and the base image is
581+
# available on source compute during the resize of the
582+
# instance.
583+
else:
584+
if size:
585+
self.resize_image(size)
580586
else:
581587
if not os.path.exists(base):
582588
prepare_template(target=base, *args, **kwargs)

0 commit comments

Comments
 (0)