Skip to content

Commit

Permalink
libvirt: Skip intermediate base files with qcow2.
Browse files Browse the repository at this point in the history
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
mikalstill committed Dec 18, 2012
1 parent 8749df7 commit c82be9f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
21 changes: 2 additions & 19 deletions nova/tests/test_imagebackend.py
Expand Up @@ -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)
Expand Down
10 changes: 2 additions & 8 deletions nova/virt/libvirt/imagebackend.py
Expand Up @@ -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):
Expand Down

0 comments on commit c82be9f

Please sign in to comment.