Permalink
Browse files

libvirt: Skip intermediate base files with qcow2.

Instead of having two files in _base (the original and a resized
copy), let's just keep the originals and resize with the qcow2
image in the instance's directory. This will reduce the size of
_base and simplify cleanup. This also simplifies resizing of
instance disk images later.

Resolves bug 1087031.

Change-Id: Id91426e3cb9f75f31339b5156785e3782a4cb98f
  • Loading branch information...
1 parent 8749df7 commit c82be9f4b997d252cfc84350a067a64d6d4b380b @mikalstill mikalstill committed Dec 17, 2012
Showing with 4 additions and 27 deletions.
  1. +2 −19 nova/tests/test_imagebackend.py
  2. +2 −8 nova/virt/libvirt/imagebackend.py
@@ -196,26 +196,9 @@ def test_create_image_with_size(self):
fn = self.prepare_mocks()
fn(target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(os.path, 'exists')
- os.path.exists(self.QCOW2_BASE).AndReturn(False)
- imagebackend.libvirt_utils.copy_image(self.TEMPLATE_PATH,
- self.QCOW2_BASE)
- imagebackend.disk.extend(self.QCOW2_BASE, self.SIZE)
- imagebackend.libvirt_utils.create_cow_image(self.QCOW2_BASE,
- self.PATH)
- self.mox.ReplayAll()
-
- image = self.image_class(self.INSTANCE, self.NAME)
- image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
-
- self.mox.VerifyAll()
-
- def test_create_image_with_size_template_exists(self):
- fn = self.prepare_mocks()
- fn(target=self.TEMPLATE_PATH)
- self.mox.StubOutWithMock(os.path, 'exists')
- os.path.exists(self.QCOW2_BASE).AndReturn(True)
- imagebackend.libvirt_utils.create_cow_image(self.QCOW2_BASE,
+ imagebackend.libvirt_utils.create_cow_image(self.TEMPLATE_PATH,
self.PATH)
+ imagebackend.disk.extend(self.PATH, self.SIZE)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
@@ -177,15 +177,9 @@ def create_image(self, prepare_template, base, size, *args, **kwargs):
@lockutils.synchronized(base, 'nova-', external=True,
lock_path=self.lock_path)
def copy_qcow2_image(base, target, size):
- qcow2_base = base
+ libvirt_utils.create_cow_image(base, target)
if size:
- size_gb = size / (1024 * 1024 * 1024)
- qcow2_base += '_%d' % size_gb
- if not os.path.exists(qcow2_base):
- with utils.remove_path_on_error(qcow2_base):
- libvirt_utils.copy_image(base, qcow2_base)
- disk.extend(qcow2_base, size)
- libvirt_utils.create_cow_image(qcow2_base, target)
+ disk.extend(target, size)
prepare_template(target=base, *args, **kwargs)
with utils.remove_path_on_error(self.path):

0 comments on commit c82be9f

Please sign in to comment.