Add Paramiko deploy/verify scripts for ARM board; gitignore deploy logs
Made-with: Cursor
This commit is contained in:
57
tools/verify_live_console.py
Normal file
57
tools/verify_live_console.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""重启 live-console 并验收 HTTP(Paramiko)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import paramiko
|
||||
|
||||
HOST = "192.168.21.105"
|
||||
USER = "live"
|
||||
PASS = "12345678"
|
||||
LOG = Path(__file__).resolve().parent.parent / ".deploy_logs" / "verify_live_console.log"
|
||||
|
||||
|
||||
def main() -> int:
|
||||
LOG.parent.mkdir(parents=True, exist_ok=True)
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect(HOST, username=USER, password=PASS, timeout=30)
|
||||
|
||||
def run(cmd: str, timeout: int = 90) -> tuple[int, str, str]:
|
||||
_, stdout, stderr = c.exec_command(
|
||||
"export LC_ALL=C.UTF-8 LANG=C.UTF-8; " + cmd,
|
||||
timeout=timeout,
|
||||
)
|
||||
out = stdout.read().decode("utf-8", errors="replace")
|
||||
err = stderr.read().decode("utf-8", errors="replace")
|
||||
code = stdout.channel.recv_exit_status()
|
||||
block = f"\n$ {cmd}\nexit={code}\n--- out ---\n{out}\n--- err ---\n{err}\n"
|
||||
with LOG.open("a", encoding="utf-8", errors="replace") as fh:
|
||||
fh.write(block)
|
||||
tail = "\n".join(block.splitlines()[-60:])
|
||||
print(tail)
|
||||
return code, out, err
|
||||
|
||||
try:
|
||||
run(
|
||||
f"echo '{PASS}' | sudo -S systemctl restart live-console.service",
|
||||
timeout=120,
|
||||
)
|
||||
time.sleep(5)
|
||||
run("systemctl is-active live-console.service", timeout=20)
|
||||
run("ss -tlnp 2>/dev/null | grep 8001 || true", timeout=20)
|
||||
run(
|
||||
"curl -sS -m 15 http://127.0.0.1:8001/health && echo "
|
||||
"&& curl -sS -m 15 http://127.0.0.1:8001/server_info | head -c 1200",
|
||||
timeout=40,
|
||||
)
|
||||
return 0
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user