Skip to content

Commit 3f274c6

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Nova resize don't extend disk in one specific case"
2 parents 395789e + f7af85d commit 3f274c6

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
@@ -13726,6 +13726,67 @@ def fake_copy_image(src, dest, **kwargs):
1372613726
mock_create_cow_image.assert_called_once_with(
1372713727
backfile_path, '/fake/instance/dir/disk_path', virt_disk_size)
1372813728

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+
1372913790
@mock.patch('nova.virt.libvirt.utils.create_image',
1373013791
new=mock.NonCallableMock())
1373113792
@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)