livemedia-creator: Handle virt-install failure cleanup

Unmount the iso and remove the disk, if it exists.
This commit is contained in:
Brian C. Lane 2014-05-29 16:54:49 -07:00
parent d79222e8ea
commit b22a7df476

View File

@ -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