61 lines
1.8 KiB
Python
Executable File
61 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Exercise a reversible live administration-TUI edit through a PTY."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
|
|
if os.environ.get("BONGO_ALLOW_LIVE_CONFIG_EDIT") != "1":
|
|
raise SystemExit("set BONGO_ALLOW_LIVE_CONFIG_EDIT=1 for the disposable host")
|
|
|
|
try:
|
|
import pexpect
|
|
except ImportError as error:
|
|
raise SystemExit("config-tui-edit.py requires pexpect") from error
|
|
|
|
replacement = os.environ.get("BONGO_TEST_WORKER_INTERVAL", "31")
|
|
if not replacement.isdigit():
|
|
raise SystemExit("BONGO_TEST_WORKER_INTERVAL must be an integer")
|
|
command = os.environ.get("BONGO_ADMIN", "/usr/bin/bongo-admin")
|
|
child = pexpect.spawn(
|
|
command, ["config"], encoding="utf-8", timeout=60,
|
|
dimensions=(40, 120), env={**os.environ, "TERM": "xterm-256color"})
|
|
child.logfile = sys.stdout
|
|
|
|
while True:
|
|
match = child.expect([
|
|
"SpamAssassin signing-key warning",
|
|
"Select a configuration document",
|
|
])
|
|
if match == 0:
|
|
child.send("\r")
|
|
continue
|
|
break
|
|
|
|
# The release-test menu puts Scheduled background jobs at position twelve.
|
|
for _index in range(11):
|
|
child.send("j")
|
|
time.sleep(0.1)
|
|
child.send("\r")
|
|
child.expect("poll_interval_seconds")
|
|
child.send("\r")
|
|
child.expect("New value")
|
|
child.send("\x7f" * 32 + replacement + "\r")
|
|
child.expect("poll_interval_seconds")
|
|
child.send("s")
|
|
match = child.expect(["Configuration warnings", "Press Enter to continue"])
|
|
if match == 0:
|
|
child.send("k\r")
|
|
child.expect("Press Enter to continue")
|
|
child.send("\r")
|
|
child.expect("Select a configuration document")
|
|
child.send("\x1b")
|
|
child.expect(pexpect.EOF)
|
|
child.close()
|
|
if child.signalstatus is not None:
|
|
raise SystemExit(128 + child.signalstatus)
|
|
raise SystemExit(child.exitstatus if child.exitstatus is not None else 1)
|