From 51441e369bb05e9cb9149ac9a7290fe541e3ed1a Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 17 Sep 2012 16:42:33 -0700 Subject: Inherit the base images qcow2 properties When creating an image based off a base image we likely want to ensure that we are inheriting some of that bases properties. This includes items like cluster_size and encryption for now. Likely it is not intended for those to differ in a child image. Blueprint backing-file-options Change-Id: I0d684ca9825a3d9c4310e4a6d4279f10331d210e --- nova/tests/test_libvirt.py | 3 +++ nova/virt/libvirt/utils.py | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'nova') diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 060a8445a..9a348459b 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -3402,6 +3402,9 @@ class LibvirtUtilsTestCase(test.TestCase): def test_create_cow_image(self): self.mox.StubOutWithMock(utils, 'execute') + rval = ('', '') + utils.execute('env', 'LC_ALL=C', 'LANG=C', + 'qemu-img', 'info', '/some/path').AndReturn(rval) utils.execute('qemu-img', 'create', '-f', 'qcow2', '-o', 'backing_file=/some/path', '/the/new/cow') diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 2dc0bfda1..740d4ea7b 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -86,8 +86,28 @@ def create_cow_image(backing_file, path): :param backing_file: Existing image on which to base the COW image :param path: Desired location of the COW image """ - execute('qemu-img', 'create', '-f', 'qcow2', '-o', - 'backing_file=%s' % backing_file, path) + base_cmd = ['qemu-img', 'create', '-f', 'qcow2'] + cow_opts = [] + if backing_file: + cow_opts += ['backing_file=%s' % backing_file] + base_details = images.qemu_img_info(backing_file) + else: + base_details = {} + # This doesn't seem to get inherited so force it to... + # http://paste.ubuntu.com/1213295/ + # TODO(harlowja) probably file a bug against qemu-img/qemu + if 'cluster_size' in base_details: + cow_opts += ['cluster_size=%s' % base_details['cluster_size']] + # For now don't inherit this due the following discussion... + # See: http://www.gossamer-threads.com/lists/openstack/dev/10592 + # if 'preallocation' in base_details: + # cow_opts += ['preallocation=%s' % base_details['preallocation']] + if 'encryption' in base_details: + cow_opts += ['encryption=%s' % base_details['encryption']] + if cow_opts: + cow_opts.insert(0, '-o') + cmd = base_cmd + cow_opts + [path] + execute(*cmd) def create_lvm_image(vg, lv, size, sparse=False): -- cgit