Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c82be9f

Browse files
committed
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
1 parent 8749df7 commit c82be9f

2 files changed

Lines changed: 4 additions & 27 deletions

File tree

nova/tests/test_imagebackend.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,26 +196,9 @@ def test_create_image_with_size(self):
196196
fn = self.prepare_mocks()
197197
fn(target=self.TEMPLATE_PATH)
198198
self.mox.StubOutWithMock(os.path, 'exists')
199-
os.path.exists(self.QCOW2_BASE).AndReturn(False)
200-
imagebackend.libvirt_utils.copy_image(self.TEMPLATE_PATH,
201-
self.QCOW2_BASE)
202-
imagebackend.disk.extend(self.QCOW2_BASE, self.SIZE)
203-
imagebackend.libvirt_utils.create_cow_image(self.QCOW2_BASE,
204-
self.PATH)
205-
self.mox.ReplayAll()
206-
207-
image = self.image_class(self.INSTANCE, self.NAME)
208-
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
209-
210-
self.mox.VerifyAll()
211-
212-
def test_create_image_with_size_template_exists(self):
213-
fn = self.prepare_mocks()
214-
fn(target=self.TEMPLATE_PATH)
215-
self.mox.StubOutWithMock(os.path, 'exists')
216-
os.path.exists(self.QCOW2_BASE).AndReturn(True)
217-
imagebackend.libvirt_utils.create_cow_image(self.QCOW2_BASE,
199+
imagebackend.libvirt_utils.create_cow_image(self.TEMPLATE_PATH,
218200
self.PATH)
201+
imagebackend.disk.extend(self.PATH, self.SIZE)
219202
self.mox.ReplayAll()
220203

221204
image = self.image_class(self.INSTANCE, self.NAME)

nova/virt/libvirt/imagebackend.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,9 @@ def create_image(self, prepare_template, base, size, *args, **kwargs):
177177
@lockutils.synchronized(base, 'nova-', external=True,
178178
lock_path=self.lock_path)
179179
def copy_qcow2_image(base, target, size):
180-
qcow2_base = base
180+
libvirt_utils.create_cow_image(base, target)
181181
if size:
182-
size_gb = size / (1024 * 1024 * 1024)
183-
qcow2_base += '_%d' % size_gb
184-
if not os.path.exists(qcow2_base):
185-
with utils.remove_path_on_error(qcow2_base):
186-
libvirt_utils.copy_image(base, qcow2_base)
187-
disk.extend(qcow2_base, size)
188-
libvirt_utils.create_cow_image(qcow2_base, target)
182+
disk.extend(target, size)
189183

190184
prepare_template(target=base, *args, **kwargs)
191185
with utils.remove_path_on_error(self.path):

0 commit comments

Comments
 (0)