Skip to content

Commit eb64323

Browse files
David Subirosviraptor
authored andcommitted
Enforce snapshot cleanup.
Makes sure that the snapshot and the temporary directory is cleaned up, even if qemu-img fails. Fixes bug 861582. Change-Id: I3c7798215c8d0d5dc979379a13e038098b0f31d4
1 parent 00bb8f9 commit eb64323

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

Authors

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Dan Prince <dan.prince@rackspace.com>
2929
Dan Wendlandt <dan@nicira.com>
3030
Dave Walker <DaveWalker@ubuntu.com>
3131
David Pravec <David.Pravec@danix.org>
32+
David Subiros <david.perez5@hp.com>
3233
Dean Troyer <dtroyer@gmail.com>
3334
Devendra Modium <dmodium@isi.edu>
3435
Devin Carlen <devin.carlen@gmail.com>

nova/virt/libvirt/connection.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -445,29 +445,31 @@ def snapshot(self, context, instance, image_href):
445445

446446
# Export the snapshot to a raw image
447447
temp_dir = tempfile.mkdtemp()
448-
out_path = os.path.join(temp_dir, snapshot_name)
449-
qemu_img_cmd = ('qemu-img',
450-
'convert',
451-
'-f',
452-
source_format,
453-
'-O',
454-
image_format,
455-
'-s',
456-
snapshot_name,
457-
disk_path,
458-
out_path)
459-
utils.execute(*qemu_img_cmd)
460-
461-
# Upload that image to the image service
462-
with open(out_path) as image_file:
463-
image_service.update(context,
464-
image_href,
465-
metadata,
466-
image_file)
467-
468-
# Clean up
469-
shutil.rmtree(temp_dir)
470-
snapshot_ptr.delete(0)
448+
try:
449+
out_path = os.path.join(temp_dir, snapshot_name)
450+
qemu_img_cmd = ('qemu-img',
451+
'convert',
452+
'-f',
453+
source_format,
454+
'-O',
455+
image_format,
456+
'-s',
457+
snapshot_name,
458+
disk_path,
459+
out_path)
460+
utils.execute(*qemu_img_cmd)
461+
462+
# Upload that image to the image service
463+
with open(out_path) as image_file:
464+
image_service.update(context,
465+
image_href,
466+
metadata,
467+
image_file)
468+
469+
finally:
470+
# Clean up
471+
shutil.rmtree(temp_dir)
472+
snapshot_ptr.delete(0)
471473

472474
@exception.wrap_exception()
473475
def reboot(self, instance, network_info, reboot_type=None, xml=None):

0 commit comments

Comments
 (0)