diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/check-qemu-install | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/scripts/check-qemu-install b/scripts/check-qemu-install index cabda683..b8ab3f61 100755 --- a/scripts/check-qemu-install +++ b/scripts/check-qemu-install @@ -644,21 +644,57 @@ def BOOTLOADERchooseSerialConsole(child, live: bool) -> None: # XXX: UEFI systems directly load GRUB, BIOS systems fallback to ISOLINUX if live and args.uefi: - # Let UEFI start before GRUB - child.expect(UEFI_STRING, timeout=BOOTLOADER_TMO) - # Wait for GRUB - child.expect(GRUB_STRING, timeout=BOOTLOADER_TMO) - time.sleep(BOOTLOADER_LOAD_TMO) + def expectSelected(title, timeout=15) -> bool: + try: + child.expect_exact(b'*' + title, timeout=timeout) + except (pexpect.TIMEOUT, pexpect.EOF): + recent = child.before[-1500:] + log.warning( + f'GRUB did not confirm selection of {title!r}; ' + f'recent output: {recent!r}' + ) + return False + return True + + # The countdown is printed after all menu entries have been drawn. + child.expect( + rb'The highlighted entry will be executed automatically in (\d+)s\.', + timeout=120, + ) + # Until a key is confirmed, an unacknowledged Home is resent without + # using up an attempt, as long as the countdown may still be running. + autoboot = time.monotonic() + int(child.match.group(1)) - 2 + + # A missing acknowledgement does not tell us whether the key was received. + # Restart from Home instead of repeating Down from an unknown selection. + attempts = 3 + while attempts: + if child.eof(): + raise RuntimeError('QEMU exited during GRUB menu selection') + + # Ctrl-A is Home without the EFI console's escape-sequence parsing. + child.sendcontrol('a') + if not expectSelected(b'Live system (vyos) - KVM console', timeout=1): + if time.monotonic() >= autoboot: + attempts -= 1 + continue + # A received key stops the countdown + autoboot = 0 + + for title in ( + b'Live system (vyos fail-safe mode)', + b'Live system (vyos) - Serial console', + ): + # Ctrl-N is Down without the escape-sequence parsing of arrow keys. + child.sendcontrol('n') + if not expectSelected(title): + break + else: + child.send(b'\r') + return + attempts -= 1 - # Select GRUB serial console - # Key DOWN -> fail-safe mode - child.send(KEY_DOWN) - time.sleep(BOOTLOADER_SLEEP) - # Key DOWN -> Serial Console boot - child.send(KEY_DOWN) - time.sleep(BOOTLOADER_SLEEP) - # Boot - child.send(KEY_RETURN) + raise RuntimeError('Failed to confirm GRUB serial console boot selection after 3 attempts') elif live and not args.uefi: # Wait for ISOLINUX child.expect(ISOLINUX_STRING, timeout=BOOTLOADER_TMO) |
