106 lines
3.3 KiB
Python
106 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Smoke: API counts + start neko1 + probe HTTP."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import ssl
|
|
import sys
|
|
import time
|
|
import urllib.error
|
|
import urllib.request
|
|
import http.cookiejar
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
BASE = "https://dy.nomadro.live"
|
|
ctx = ssl.create_default_context()
|
|
cj = http.cookiejar.CookieJar()
|
|
opener = urllib.request.build_opener(
|
|
urllib.request.HTTPCookieProcessor(cj),
|
|
urllib.request.HTTPSHandler(context=ctx),
|
|
)
|
|
|
|
|
|
def api(path: str, method: str = "GET", data: dict | None = None):
|
|
body = None if data is None else json.dumps(data).encode()
|
|
headers = {"Content-Type": "application/json"} if data is not None else {}
|
|
req = urllib.request.Request(BASE + path, data=body, headers=headers, method=method)
|
|
with opener.open(req, timeout=120) as r:
|
|
return r.status, json.loads(r.read().decode())
|
|
|
|
|
|
st, login = api("/api/auth/login", "POST", {"username": "hackrobot", "password": "Xiao4669805@"})
|
|
print("login", st, login)
|
|
|
|
st, rooms = api("/api/rooms")
|
|
print("rooms", st, "n=", len(rooms.get("rooms") or []), "total=", rooms.get("total"))
|
|
|
|
st, shorts = api("/api/shorts/channels")
|
|
chs = shorts.get("channels") or []
|
|
with_rt = sum(1 for c in chs if c.get("refresh_token"))
|
|
print("shorts", st, "n=", len(chs), "with_rt=", with_rt)
|
|
|
|
st, assign = api("/api/youtube/assign/groups")
|
|
groups = assign.get("groups") or assign.get("items") or []
|
|
if isinstance(assign, list):
|
|
groups = assign
|
|
print("assign", st, "n=", len(groups), "sample=", [g.get("name") for g in groups[:5]])
|
|
|
|
# start neko 1
|
|
print("--- start neko1 ---")
|
|
try:
|
|
st, out = api("/api/youtube/neko/1/start", "POST", {})
|
|
print("start_api", st, out)
|
|
except Exception as e:
|
|
print("start_api_err", e)
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"108.174.50.68",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
_, o, e2 = c.exec_command(
|
|
"docker start douyinweb-neko-1; sleep 4; docker ps --filter name=douyinweb-neko-1 --format '{{.Names}} {{.Status}}'",
|
|
timeout=90,
|
|
)
|
|
print(o.read().decode())
|
|
print(e2.read().decode()[:400])
|
|
c.close()
|
|
|
|
time.sleep(6)
|
|
st, status = api("/api/youtube/neko/status")
|
|
inst = next(i for i in status["instances"] if i["id"] == 1)
|
|
print("neko1", {k: inst.get(k) for k in ("running", "ready", "status", "http_port", "studio_url")})
|
|
print("running_count", status.get("running"), "/", status.get("desired"))
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"108.174.50.68",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
_, o, _ = c.exec_command(
|
|
"echo local:$(curl -sI -o /dev/null -w '%{http_code}' http://127.0.0.1:9200/); "
|
|
"echo pub:$(curl -skI -o /dev/null -w '%{http_code}' https://dy.nomadro.live/neko/1/); "
|
|
"ss -ulnp 2>/dev/null | grep -E '5200[0-9]|52300' | head -5 || true; "
|
|
"docker ps --filter name=douyinweb-neko-1 --format '{{.Names}} {{.Status}}'",
|
|
timeout=40,
|
|
)
|
|
print(o.read().decode("utf-8", "replace"))
|
|
c.close()
|
|
print("DONE")
|