Merge "libvirt: Create qcow2 disks with the correct size without extending"
This commit is contained in:
commit
125a8530cc
|
@ -13616,7 +13616,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||||
|
|
||||||
mock_utime.assert_called()
|
mock_utime.assert_called()
|
||||||
mock_create_cow_image.assert_called_once_with(
|
mock_create_cow_image.assert_called_once_with(
|
||||||
backfile_path, '/fake/instance/dir/disk_path')
|
backfile_path, '/fake/instance/dir/disk_path', virt_disk_size)
|
||||||
|
|
||||||
@mock.patch('nova.virt.libvirt.utils.create_image',
|
@mock.patch('nova.virt.libvirt.utils.create_image',
|
||||||
new=mock.NonCallableMock())
|
new=mock.NonCallableMock())
|
||||||
|
@ -13700,9 +13700,17 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||||
|
|
||||||
# TODO(efried): Should these be disk_info[path]??
|
# TODO(efried): Should these be disk_info[path]??
|
||||||
mock_create_cow_image.assert_has_calls([
|
mock_create_cow_image.assert_has_calls([
|
||||||
mock.call(root_backing, CONF.instances_path + '/disk'),
|
mock.call(
|
||||||
mock.call(ephemeral_backing,
|
root_backing,
|
||||||
CONF.instances_path + '/disk.local')])
|
CONF.instances_path + '/disk',
|
||||||
|
disk_info_byname['disk']['virt_disk_size']
|
||||||
|
),
|
||||||
|
mock.call(
|
||||||
|
ephemeral_backing,
|
||||||
|
CONF.instances_path + '/disk.local',
|
||||||
|
disk_info_byname['disk.local']['virt_disk_size']
|
||||||
|
),
|
||||||
|
])
|
||||||
|
|
||||||
def test_create_images_and_backing_disk_info_none(self):
|
def test_create_images_and_backing_disk_info_none(self):
|
||||||
instance = objects.Instance(**self.test_instance)
|
instance = objects.Instance(**self.test_instance)
|
||||||
|
|
|
@ -524,30 +524,12 @@ class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
|
||||||
|
|
||||||
@mock.patch.object(imagebackend.utils, 'synchronized')
|
@mock.patch.object(imagebackend.utils, 'synchronized')
|
||||||
@mock.patch('nova.virt.libvirt.utils.create_cow_image')
|
@mock.patch('nova.virt.libvirt.utils.create_cow_image')
|
||||||
@mock.patch.object(imagebackend.disk, 'extend')
|
|
||||||
@mock.patch('nova.privsep.path.utime')
|
|
||||||
def test_create_image(self, mock_utime, mock_extend, mock_create,
|
|
||||||
mock_sync):
|
|
||||||
mock_sync.side_effect = lambda *a, **kw: self._fake_deco
|
|
||||||
fn = mock.MagicMock()
|
|
||||||
image = self.image_class(self.INSTANCE, self.NAME)
|
|
||||||
|
|
||||||
image.create_image(fn, self.TEMPLATE_PATH, None)
|
|
||||||
|
|
||||||
mock_create.assert_called_once_with(self.TEMPLATE_PATH, self.PATH)
|
|
||||||
fn.assert_called_once_with(target=self.TEMPLATE_PATH)
|
|
||||||
self.assertTrue(mock_sync.called)
|
|
||||||
self.assertFalse(mock_extend.called)
|
|
||||||
mock_utime.assert_called()
|
|
||||||
|
|
||||||
@mock.patch.object(imagebackend.utils, 'synchronized')
|
|
||||||
@mock.patch('nova.virt.libvirt.utils.create_cow_image')
|
|
||||||
@mock.patch.object(imagebackend.disk, 'extend')
|
|
||||||
@mock.patch.object(os.path, 'exists', side_effect=[])
|
@mock.patch.object(os.path, 'exists', side_effect=[])
|
||||||
@mock.patch.object(imagebackend.Image, 'verify_base_size')
|
@mock.patch.object(imagebackend.Image, 'verify_base_size')
|
||||||
@mock.patch('nova.privsep.path.utime')
|
@mock.patch('nova.privsep.path.utime')
|
||||||
def test_create_image_with_size(self, mock_utime, mock_verify, mock_exist,
|
def test_create_image(
|
||||||
mock_extend, mock_create, mock_sync):
|
self, mock_utime, mock_verify, mock_exist, mock_create, mock_sync
|
||||||
|
):
|
||||||
mock_sync.side_effect = lambda *a, **kw: self._fake_deco
|
mock_sync.side_effect = lambda *a, **kw: self._fake_deco
|
||||||
fn = mock.MagicMock()
|
fn = mock.MagicMock()
|
||||||
mock_exist.side_effect = [False, True, False, False, False]
|
mock_exist.side_effect = [False, True, False, False, False]
|
||||||
|
@ -561,10 +543,8 @@ class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
|
||||||
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
|
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
|
||||||
|
|
||||||
mock_verify.assert_called_once_with(self.TEMPLATE_PATH, self.SIZE)
|
mock_verify.assert_called_once_with(self.TEMPLATE_PATH, self.SIZE)
|
||||||
mock_create.assert_called_once_with(self.TEMPLATE_PATH, self.PATH)
|
mock_create.assert_called_once_with(
|
||||||
mock_extend.assert_called_once_with(
|
self.TEMPLATE_PATH, self.PATH, self.SIZE)
|
||||||
imgmodel.LocalFileImage(self.PATH, imgmodel.FORMAT_QCOW2),
|
|
||||||
self.SIZE)
|
|
||||||
fn.assert_called_once_with(target=self.TEMPLATE_PATH)
|
fn.assert_called_once_with(target=self.TEMPLATE_PATH)
|
||||||
mock_exist.assert_has_calls(exist_calls)
|
mock_exist.assert_has_calls(exist_calls)
|
||||||
self.assertTrue(mock_sync.called)
|
self.assertTrue(mock_sync.called)
|
||||||
|
|
|
@ -624,14 +624,8 @@ class Qcow2(Image):
|
||||||
filename = self._get_lock_name(base)
|
filename = self._get_lock_name(base)
|
||||||
|
|
||||||
@utils.synchronized(filename, external=True, lock_path=self.lock_path)
|
@utils.synchronized(filename, external=True, lock_path=self.lock_path)
|
||||||
def copy_qcow2_image(base, target, size):
|
def create_qcow2_image(base, target, size):
|
||||||
# TODO(pbrady): Consider copying the cow image here
|
libvirt_utils.create_cow_image(base, target, size)
|
||||||
# with preallocation=metadata set for performance reasons.
|
|
||||||
# This would be keyed on a 'preallocate_images' setting.
|
|
||||||
libvirt_utils.create_cow_image(base, target)
|
|
||||||
if size:
|
|
||||||
image = imgmodel.LocalFileImage(target, imgmodel.FORMAT_QCOW2)
|
|
||||||
disk.extend(image, size)
|
|
||||||
|
|
||||||
# Download the unmodified base image unless we already have a copy.
|
# Download the unmodified base image unless we already have a copy.
|
||||||
if not os.path.exists(base):
|
if not os.path.exists(base):
|
||||||
|
@ -670,7 +664,7 @@ class Qcow2(Image):
|
||||||
|
|
||||||
if not os.path.exists(self.path):
|
if not os.path.exists(self.path):
|
||||||
with fileutils.remove_path_on_error(self.path):
|
with fileutils.remove_path_on_error(self.path):
|
||||||
copy_qcow2_image(base, self.path, size)
|
create_qcow2_image(base, self.path, size)
|
||||||
|
|
||||||
def resize_image(self, size):
|
def resize_image(self, size):
|
||||||
image = imgmodel.LocalFileImage(self.path, imgmodel.FORMAT_QCOW2)
|
image = imgmodel.LocalFileImage(self.path, imgmodel.FORMAT_QCOW2)
|
||||||
|
|
Loading…
Reference in New Issue