From b22a7df476cbb05852b9a6f582ebcffd4e85b1cb Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 29 May 2014 16:54:49 -0700 Subject: [PATCH] livemedia-creator: Handle virt-install failure cleanup Unmount the iso and remove the disk, if it exists. --- src/sbin/livemedia-creator | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator index b4fb2b72..0fac7e05 100755 --- a/src/sbin/livemedia-creator +++ b/src/sbin/livemedia-creator @@ -359,7 +359,7 @@ class VirtualInstall(object): rc = execWithRedirect("virt-install", args) if rc: - raise Exception("Problem starting virtual install") + raise InstallError("Problem starting virtual install") conn = libvirt.openReadOnly(None) dom = conn.lookupByName(self.virt_name) @@ -726,16 +726,22 @@ def virt_install(opts, install_log, disk_img, disk_size): else: diskimg_path = disk_img - virt = VirtualInstall(iso_mount, opts.ks, diskimg_path, disk_size, - kernel_args, opts.ram, opts.vnc, opts.arch, - log_check = log_monitor.server.log_check, - virtio_host = log_monitor.host, - virtio_port = log_monitor.port, - qcow2=opts.qcow2) + try: + virt = VirtualInstall(iso_mount, opts.ks, diskimg_path, disk_size, + kernel_args, opts.ram, opts.vnc, opts.arch, + log_check = log_monitor.server.log_check, + virtio_host = log_monitor.host, + virtio_port = log_monitor.port, + qcow2=opts.qcow2) - virt.destroy() - log_monitor.shutdown() - iso_mount.umount() + virt.destroy() + log_monitor.shutdown() + except InstallError as e: + log.error("VirtualInstall failed: %s", e) + raise + finally: + log.info("unmounting the iso") + iso_mount.umount() if log_monitor.server.log_check(): raise InstallError("virt_install failed") @@ -812,7 +818,7 @@ def make_image(opts, ks): virt_install(opts, install_log, disk_img, disk_size) except InstallError as e: log.error("Install failed: {0}".format(e)) - if not opts.keep_image: + if not opts.keep_image and os.path.exists(disk_img): log.info("Removing bad disk image") os.unlink(disk_img) raise