diff options
| author | David Subiros <david.perez5@hp.com> | 2011-09-28 15:19:04 +0100 |
|---|---|---|
| committer | Stanislaw Pitucha <stanislaw.pitucha@hp.com> | 2011-09-29 10:57:27 +0100 |
| commit | eb6432361ee4946d93867e2d3f0870d892a25c66 (patch) | |
| tree | f4c0b3d277a47c726d53c9d14446659e8467ca78 /nova | |
| parent | 00bb8f9d03f18ce6efbf128cef6d07bbfe99677f (diff) | |
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
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/virt/libvirt/connection.py | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 064c2688f..6afd41c1b 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -445,29 +445,31 @@ class LibvirtConnection(driver.ComputeDriver): # Export the snapshot to a raw image temp_dir = tempfile.mkdtemp() - out_path = os.path.join(temp_dir, snapshot_name) - qemu_img_cmd = ('qemu-img', - 'convert', - '-f', - source_format, - '-O', - image_format, - '-s', - snapshot_name, - disk_path, - out_path) - utils.execute(*qemu_img_cmd) - - # Upload that image to the image service - with open(out_path) as image_file: - image_service.update(context, - image_href, - metadata, - image_file) - - # Clean up - shutil.rmtree(temp_dir) - snapshot_ptr.delete(0) + try: + out_path = os.path.join(temp_dir, snapshot_name) + qemu_img_cmd = ('qemu-img', + 'convert', + '-f', + source_format, + '-O', + image_format, + '-s', + snapshot_name, + disk_path, + out_path) + utils.execute(*qemu_img_cmd) + + # Upload that image to the image service + with open(out_path) as image_file: + image_service.update(context, + image_href, + metadata, + image_file) + + finally: + # Clean up + shutil.rmtree(temp_dir) + snapshot_ptr.delete(0) @exception.wrap_exception() def reboot(self, instance, network_info, reboot_type=None, xml=None): |
