virt-install: If virt-viewer will fail, default to --wait -1

This can happen if user requests explicit --graphics, but they are on
a headless display. We had a few reports of this recently.
This commit is contained in:
Cole Robinson 2014-09-20 18:20:41 -04:00
parent 85161e4c57
commit 1f3f3fa4fc
3 changed files with 52 additions and 27 deletions

View File

@ -96,7 +96,6 @@ def main(conn=None):
options.dry = True
options.quiet = True
conscb = options.autoconsole and cli.show_console_for_guest or None
print_cb = print_stdout
if options.quiet:
print_cb = None
@ -109,6 +108,10 @@ def main(conn=None):
guest = converter.get_guest()
conscb = None
if options.autoconsole:
conscb = cli.get_console_cb(guest) or None
if options.xmlonly:
print_stdout(guest.start_install(return_xml=True)[1],
do_force=True)

View File

@ -675,9 +675,10 @@ def start_install(guest, continue_inst, options):
# waiting. Otherwise, we can exit before the domain has finished
# installing. Passing --wait will give the above semantics.
#
if options.wait is None:
wait_on_install = continue_inst
wait_time = -1
if options.wait is not None:
else:
wait_on_install = True
wait_time = options.wait * 60
@ -686,10 +687,25 @@ def start_install(guest, continue_inst, options):
# expires
wait_on_console = not wait_on_install
if wait_time == 0:
# --wait 0 implies --noautoconsole
options.autoconsole = (wait_time != 0) and options.autoconsole or False
autoconsole = False
else:
autoconsole = options.autoconsole
conscb = None
if autoconsole:
conscb = cli.get_console_cb(guest)
if not conscb:
# If there isn't any console to actually connect up,
# default to --wait -1 to get similarish behavior
autoconsole = False
if options.wait is None:
logging.warning(_("No console to launch for the guest, "
"defaulting to --wait -1"))
wait_on_install = True
wait_time = -1
conscb = options.autoconsole and cli.show_console_for_guest or None
meter = (options.quiet and
progress.BaseMeter() or
progress.TextMeter(fo=sys.stdout))

View File

@ -383,12 +383,8 @@ def _gfx_console(guest):
"--connect", guest.conn.uri,
"--wait", guest.name]
if not os.path.exists(args[0]):
logging.warn(_("Unable to connect to graphical console: "
"virt-viewer not installed. Please install "
"the 'virt-viewer' package."))
return None
logging.debug("Launching virt-viewer for graphics type '%s'",
guest.get_devices("graphics")[0].type)
return _run_console(args)
@ -397,6 +393,7 @@ def _txt_console(guest):
"--connect", guest.conn.uri,
"console", guest.name]
logging.debug("Connecting to text console")
return _run_console(args)
@ -419,22 +416,31 @@ def connect_console(guest, consolecb, wait):
logging.debug("waitpid: %s: %s", e.errno, e.message)
def show_console_for_guest(guest):
gdev = guest.get_devices("graphics")
if not gdev:
logging.debug("Connecting to text console")
return _txt_console(guest)
def get_console_cb(guest):
gdevs = guest.get_devices("graphics")
if not gdevs:
return _txt_console
gtype = gdev[0].type
if gtype in ["default",
gtype = gdevs[0].type
if gtype not in ["default",
VirtualGraphics.TYPE_VNC,
VirtualGraphics.TYPE_SPICE]:
logging.debug("Launching virt-viewer for graphics type '%s'", gtype)
return _gfx_console(guest)
else:
logging.debug("No viewer to launch for graphics type '%s'", gtype)
return
if not os.path.exists("/usr/bin/virt-viewer"):
logging.warn(_("Unable to connect to graphical console: "
"virt-viewer not installed. Please install "
"the 'virt-viewer' package."))
return None
if not os.environ.get("DISPLAY", ""):
logging.warn(_("Graphics requested but DISPLAY is not set. "
"Not running virt-viewer."))
return None
return _gfx_console
###########################
# Common CLI option/group #