Fix ISO tool checks and fail promptly on installer refusal

This commit is contained in:
Codex
2026-10-13 05:33:27 +03:00
parent c490991054
commit 32e9334feb
2 changed files with 92 additions and 9 deletions
+30 -7
View File
@@ -423,6 +423,15 @@ def parse_frame(data, token):
return int(end.group(1)), output
def installer_command(token):
# A literal control-byte return frame cannot be forged by terminal echo.
# Keep the installer on this controlling TTY for getpass, then mark every
# shell return, including an unexpected status zero without completion.
return ('sudo -n hydra-install --disk /dev/vda --user hydratest --execute '
'--confirm-erase /dev/vda; rc=$?; '
f"printf '\\036{token}:INSTALL_EXIT:%s\\037' \"$rc\"")
class Console:
def __init__(self, connection, logfile, passwords):
self.sock = connection
@@ -472,10 +481,17 @@ class Console:
raise SmokeError('Console exceeded bounded capture size')
return data
def expect(self, pattern, timeout):
def expect(self, pattern, timeout, failure_pattern=None):
deadline = time.monotonic() + timeout
while True:
match = re.search(pattern, self.buffer)
failure = re.search(failure_pattern, self.buffer) if failure_pattern else None
if failure and (not match or failure.start() < match.start()):
evidence = failure.group()
for password in self.passwords:
evidence = evidence.replace(password, b'[REDACTED]')
raise SmokeError('Installer exited before expected console state: ' +
evidence.decode(errors='replace'))
if match:
self.buffer = self.buffer[match.end():]
return match
@@ -484,6 +500,11 @@ class Console:
raise SmokeError('Timed out waiting for guest console state')
self.read(min(remaining, 1))
def expect_installer(self, pattern, timeout, token):
failure = (rb'hydra-install: [^\r\n]*[\r\n]|\x1e' +
re.escape(token.encode()) + rb':INSTALL_EXIT:[0-9]+\x1f')
return self.expect(pattern, timeout, failure_pattern=failure)
def command(self, command, timeout=60):
token = secrets.token_hex(12)
self.buffer = b''
@@ -579,7 +600,7 @@ test -f /etc/hydra/live-mode/active
findmnt -n -o FSTYPE / | grep -qx overlay
test -f /run/initramfs/live/LiveOS/squashfs.img
sudo -n true
for tool in hydra hydra-install qemu-system-x86_64 qemu-img virt-viewer foot labwc; do command -v "$tool"; done
for tool in hydra hydra-install qemu-system-x86_64 qemu-img remote-viewer foot labwc; do command -v "$tool"; done
for service in NetworkManager hydra-network hydra-dnsmasq; do systemctl is-active "$service"; done
'''
@@ -627,7 +648,7 @@ ip -4 route show default | grep '^default '
nft list table ip hydra_nat
nmcli -t -f STATE general | grep -E '^connected'
getent ahostsv4 gentoo.org
for tool in hydra hydra-install qemu-system-x86_64 qemu-img virt-viewer foot labwc; do command -v "$tool"; done
for tool in hydra hydra-install qemu-system-x86_64 qemu-img remote-viewer foot labwc; do command -v "$tool"; done
hydra --help
qemu-system-x86_64 --version
qemu-img --version
@@ -789,12 +810,14 @@ def main(argv=None):
console.expect(rb'hydra-live[^\r\n]*[#$] ', args.boot_timeout)
checkpoint('live_boot', console.command(LIVE_CHECK, 90))
console.buffer = b''
console.send('sudo -n hydra-install --disk /dev/vda --user hydratest --execute --confirm-erase /dev/vda\n')
console.expect(rb'Installed account password: ', 120)
installer_token = secrets.token_hex(12)
console.send(installer_command(installer_token) + '\n')
console.expect_installer(rb'Installed account password: ', 120, installer_token)
console.send(password + '\n')
console.expect(rb'Repeat password: ', 30)
console.expect_installer(rb'Repeat password: ', 30, installer_token)
console.send(password + '\n')
console.expect(rb'Installation completed\. Diagnostic log: [^\r\n]+', args.install_timeout)
console.expect_installer(rb'Installation completed\. Diagnostic log: [^\r\n]+',
args.install_timeout, installer_token)
checkpoint('real_installer', b'Installer completed via guest controlling TTY')
console.command("sudo -n mkdir -p /mnt/hydra-validation && sudo -n mount /dev/vda2 /mnt/hydra-validation && printf %s " +
shlex.quote(sentinel) + " | sudo -n tee /mnt/hydra-validation/var/lib/hydra-acceptance-sentinel >/dev/null && sudo -n umount /mnt/hydra-validation", 60)