From c5da0d7b07da27b2102986b7b310f3be0dcb3968 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 25 Nov 2019 13:00:36 -0500 Subject: [PATCH] virt-install: Don't pause for cloudinit pass if stdin is closed Like if run in a script without any stdin open. Have the test suite actually hit this path Signed-off-by: Cole Robinson --- tests/clitest.py | 1 + virt-install | 36 ++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/tests/clitest.py b/tests/clitest.py index 1f4399fca..7406b9180 100644 --- a/tests/clitest.py +++ b/tests/clitest.py @@ -879,6 +879,7 @@ c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init root-pass c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init root-password-file=%(ADMIN-PASSWORD-FILE)s,disable=no", "cloud-init-options") # --cloud-init root-password-file c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init ssh-key=%(XMLDIR)s/cloudinit/ssh-key.txt", "cloud-init-options") # --cloud-init ssh-key c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init user-data=%(XMLDIR)s/cloudinit/user-data.txt,meta-data=%(XMLDIR)s/cloudinit/meta-data.txt", "cloud-init-options") # --cloud-init user-data=,meta-data= +c.add_valid("--connect %(URI-KVM)s --disk %(EXISTIMG1)s --install fedora28 --cloud-init", grep="Password for first root login") # make sure we print the root login password c.add_valid("--panic help --disk=? --check=help", grep="path_in_use") # Make sure introspection doesn't blow up c.add_valid("--connect test:///default --test-stub-command", use_default_args=False) # --test-stub-command c.add_valid("--nodisks --pxe", grep="VM performance may suffer") # os variant warning diff --git a/virt-install b/virt-install index fc0ab0ac7..0bec5f3e2 100755 --- a/virt-install +++ b/virt-install @@ -630,6 +630,30 @@ class WaitHandler: return (time_elapsed >= self._wait_secs) or cli.in_testsuite() +def _print_cloudinit_passwd(installer): + passwd = installer.get_generated_password() + if not passwd: + return + + print_stdout(_("Password for first root login is: %s") % passwd, + do_force=True, do_log=False) + + stdins = [sys.stdin] + timeout = 10 + if sys.stdin.closed or not sys.stdin.isatty(): + if not cli.in_testsuite(): # pragma: no cover + return + stdins = [] + timeout = .0001 + + sys.stdout.write( + _("Installation will continue in 10 seconds " + "(press Enter to skip)...")) + sys.stdout.flush() + + select.select(stdins, [], [], timeout) + + def start_install(guest, installer, options): autoconsole = cli.parse_autoconsole(options, guest) show_console_warnings(installer, autoconsole) @@ -645,8 +669,7 @@ def start_install(guest, installer, options): waithandler = WaitHandler(options.wait) meter = cli.get_meter() - log.debug("Guest.has_install_phase: %s", - installer.has_install_phase()) + log.debug("Guest.has_install_phase: %s", installer.has_install_phase()) # we've got everything -- try to start the install print_stdout(_("\nStarting install...")) @@ -662,14 +685,7 @@ def start_install(guest, installer, options): if options.destroy_on_exit: atexit.register(_destroy_on_exit, domain) - passwd = installer.get_generated_password() - if options.cloud_init and passwd: # pragma: no cover - print_stdout(_("Password for first login is: %s") % passwd, do_log=False) - print_stdout( - _("Installation will continue in 10 seconds " - "(press Enter to skip)")) - timeout = 10 - select.select([sys.stdin], [], [], timeout) + _print_cloudinit_passwd(installer) cli.connect_console(guest, domain, conscb, waithandler.wait_for_console_to_exit,