R-1338 memory figure + Plex fixtures + Wanderer entry re-measure
This commit is contained in:
1 parent
0baf8f9485
commit
3671802c29
7 files changed
+390
-14
No files matched your search
+24
-8
@@ -23,6 +23,7 @@ The walk, per `09` §6.4 and the update-night brief §4:
|
||||
`inconclusive` is a first-class verdict and is NEVER collapsed into `failed`.
|
||||
"""
|
||||
import argparse, json, os, re, subprocess, sys, time
|
||||
from memfigure import anon_live # R-1338: the soak's memory figure, shared with upgrade-test.py
|
||||
from datetime import datetime, timezone
|
||||
|
||||
SC = os.environ.get('SC', os.path.expanduser('~/.felhom-retest'))
|
||||
@@ -733,13 +734,16 @@ while :; do
|
||||
rc=$(docker inspect -f '{{{{.RestartCount}}}}' $id); run=$(docker inspect -f '{{{{.State.Running}}}}' $id)
|
||||
start=$(docker inspect -f '{{{{.State.StartedAt}}}}' $id); oomk=$(docker inspect -f '{{{{.State.OOMKilled}}}}' $id)
|
||||
cg=""; for c in /sys/fs/cgroup/system.slice/docker-$full.scope /sys/fs/cgroup/docker/$full; do [ -d "$c" ] && cg=$c; done
|
||||
anon=0; mx=max; pk=0; ok=0
|
||||
anon=0; fl=0; af=0; inf=0; aa=0; ia=0; sh=0; mx=max; pk=0; ok=0
|
||||
if [ -n "$cg" ]; then
|
||||
anon=$(awk '$1=="anon"{{print $2}}' $cg/memory.stat); mx=$(cat $cg/memory.max)
|
||||
fl=$(awk '$1=="file"{{print $2}}' $cg/memory.stat); af=$(awk '$1=="active_file"{{print $2}}' $cg/memory.stat)
|
||||
inf=$(awk '$1=="inactive_file"{{print $2}}' $cg/memory.stat); aa=$(awk '$1=="active_anon"{{print $2}}' $cg/memory.stat)
|
||||
ia=$(awk '$1=="inactive_anon"{{print $2}}' $cg/memory.stat); sh=$(awk '$1=="shmem"{{print $2}}' $cg/memory.stat)
|
||||
pk=$(cat $cg/memory.peak 2>/dev/null || echo 0); ok=$(awk '$1=="oom_kill"{{print $2}}' $cg/memory.events)
|
||||
fi
|
||||
printf '{{"t":%s,"c":"%s","anon":%s,"max":"%s","peak":%s,"oom_kill":%s,"restarts":%s,"running":"%s","started":"%s","oomkilled":"%s","cg":"%s"}}\\n' \\
|
||||
"$(date +%s)" "$nm" "${{anon:-0}}" "$mx" "${{pk:-0}}" "${{ok:-0}}" "$rc" "$run" "$start" "$oomk" "$cg"
|
||||
printf '{{"t":%s,"c":"%s","anon":%s,"file":%s,"active_file":%s,"inactive_file":%s,"active_anon":%s,"inactive_anon":%s,"shmem":%s,"max":"%s","peak":%s,"oom_kill":%s,"restarts":%s,"running":"%s","started":"%s","oomkilled":"%s","cg":"%s"}}\\n' \\
|
||||
"$(date +%s)" "$nm" "${{anon:-0}}" "${{fl:-0}}" "${{af:-0}}" "${{inf:-0}}" "${{aa:-0}}" "${{ia:-0}}" "${{sh:-0}}" "$mx" "${{pk:-0}}" "${{ok:-0}}" "$rc" "$run" "$start" "$oomk" "$cg"
|
||||
done
|
||||
[ "$(date +%s)" -ge "$end" ] && break
|
||||
sleep {int(interval)}
|
||||
@@ -752,12 +756,21 @@ done
|
||||
samples.append(json.loads(line))
|
||||
except ValueError:
|
||||
continue
|
||||
return soak_summary(samples, seconds, interval)
|
||||
|
||||
|
||||
def soak_summary(samples, seconds, interval):
|
||||
"""The soak's samples → the per-container record. The mark's figure (peak_pct) is the LIVE anon (R-1338,
|
||||
memfigure.anon_live: `anon` without the pages the app already gave back); `anon_peak_pct` stays beside it.
|
||||
Pinned by test_memory_live.py."""
|
||||
per = {}
|
||||
for s in samples:
|
||||
c = per.setdefault(s["c"], {"samples": 0, "anon_peak": 0, "cg_peak": 0, "limit": None, "oom_kill": [],
|
||||
c = per.setdefault(s["c"], {"samples": 0, "anon_peak": 0, "live_peak": 0, "cg_peak": 0, "limit": None, "oom_kill": [],
|
||||
"restarts": [], "running": [], "started": set(), "oomkilled": False, "cgroup": s["cg"]})
|
||||
c["samples"] += 1
|
||||
c["anon_peak"] = max(c["anon_peak"], int(s["anon"]))
|
||||
live = anon_live(s)
|
||||
c["live_peak"] = max(c["live_peak"], int(live if live is not None else s["anon"]))
|
||||
c["cg_peak"] = max(c["cg_peak"], int(s["peak"]))
|
||||
c["limit"] = int(s["max"]) if str(s["max"]).isdigit() else None
|
||||
c["oom_kill"].append(int(s["oom_kill"]))
|
||||
@@ -774,15 +787,18 @@ done
|
||||
kills += k + (1 if c["oomkilled"] else 0)
|
||||
restarts += r
|
||||
pct = round(100.0 * c["anon_peak"] / c["limit"], 1) if c["limit"] else None
|
||||
live_pct = round(100.0 * c["live_peak"] / c["limit"], 1) if c["limit"] else None
|
||||
cgp = round(100.0 * c["cg_peak"] / c["limit"], 1) if c["limit"] else None
|
||||
if pct is not None:
|
||||
peaks.append(pct)
|
||||
if live_pct is not None:
|
||||
peaks.append(live_pct)
|
||||
res["containers"][nm] = {"samples": c["samples"], "anon_peak_bytes": c["anon_peak"], "limit_bytes": c["limit"],
|
||||
"anon_peak_pct": pct, "cgroup_peak_pct": cgp, "oom_kill_delta": k,
|
||||
"anon_peak_pct": pct, "anon_live_peak_bytes": c["live_peak"], "anon_live_peak_pct": live_pct,
|
||||
"cgroup_peak_pct": cgp, "oom_kill_delta": k,
|
||||
"oom_killed_flag": c["oomkilled"], "restarts_delta": r,
|
||||
"running_all_samples": all(c["running"]), "cgroup": c["cgroup"]}
|
||||
res["oom_kills"], res["restarts"] = kills, restarts
|
||||
res["peak_pct"] = max(peaks) if peaks else None
|
||||
res["peak_pct"] = max(peaks) if peaks else None # the live anon figure (R-1338)
|
||||
res["peak_basis"] = "anon_live"
|
||||
return res
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
"""memfigure — the memory figure an update test judges an app on (one home; upgrade-test.py and box_walk.py import it)."""
|
||||
|
||||
|
||||
def anon_live(stat: dict):
|
||||
"""R-1338 (2026-10-28 night): the app's anonymous memory WITHOUT the pages it already gave back.
|
||||
|
||||
MEASURED (felhom.eu audits/night-2026-10-28/r1338-meili/, bench and 9202): Wanderer's Meilisearch read `anon` at
|
||||
84-96 % of its 384 MiB limit for ten minutes while it used ~100 MB. An allocator that frees with MADV_FREE leaves
|
||||
the pages mapped — `anon` keeps counting them — and the kernel moves them to the INACTIVE FILE list and takes them
|
||||
back first at the limit (thousands of limit hits, 0 kills, no swap). They are no file cache: `file` stayed at ~1 MB
|
||||
while `inactive_file` held ~280 MB. Two estimates of the anon the app still holds:
|
||||
(a) anon - max(0, active_file + inactive_file - file) — the file-list pages beyond the file cache are given back;
|
||||
(b) active_anon + inactive_anon - shmem — the kernel's own anon lists (given-back pages left them).
|
||||
The LARGER is taken, capped at `anon`, so the figure errs high, never low (the bench measured (b) 10-22 MB above (a);
|
||||
a reused given-back page can sit on the file list until the next reclaim pass — (b) still counts it). Missing
|
||||
fields fall back to `anon`. None when `anon` is missing. Pinned by test_memory_live.py."""
|
||||
try:
|
||||
anon = int(stat["anon"])
|
||||
except (KeyError, TypeError, ValueError):
|
||||
return None
|
||||
try:
|
||||
a = anon - max(0, int(stat.get("active_file", 0)) + int(stat.get("inactive_file", 0)) - int(stat.get("file", 0)))
|
||||
except (TypeError, ValueError):
|
||||
return anon
|
||||
if "active_anon" in stat or "inactive_anon" in stat:
|
||||
try:
|
||||
b = int(stat.get("active_anon", 0)) + int(stat.get("inactive_anon", 0)) - int(stat.get("shmem", 0))
|
||||
except (TypeError, ValueError):
|
||||
b = anon
|
||||
a = max(a, b)
|
||||
return max(0, min(anon, a))
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env python3
|
||||
"""R-1338 (2026-10-28 night): the update test's memory figure counts only the memory the app still holds.
|
||||
|
||||
Measured on the bench (felhom.eu audits/night-2026-10-28/r1338/): Wanderer's Meilisearch read `anon` 382 MB of its
|
||||
384 MB limit for ten minutes, while 297 MB sat on the inactive FILE list with only 1 MB of real file cache — pages the
|
||||
allocator gave back (MADV_FREE), which the kernel reclaims first (0 kills). The mark read 95–96 % on every venue; the
|
||||
live figure is ~86 MB (22 %). These tests use those numbers.
|
||||
|
||||
Run: python3 test_memory_live.py (pure Python; no Docker)."""
|
||||
import importlib.util
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, HERE)
|
||||
from memfigure import anon_live # noqa: E402
|
||||
|
||||
MB = 1000 * 1000
|
||||
|
||||
|
||||
def _load_upgrade_test():
|
||||
spec = importlib.util.spec_from_file_location("upgrade_test_mod", os.path.join(HERE, "upgrade-test.py"))
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
|
||||
class AnonLive(unittest.TestCase):
|
||||
def test_the_measured_spike(self):
|
||||
# The cap run's sample at +112 s (bench, MB = 10^6 B): estimate (a) 86 MB, the anon lists (b) 99 MB → 99 MB.
|
||||
# RED-PROOF: return stat["anon"] → 382 MB → FAILS.
|
||||
self.assertEqual(anon_live({"anon": 382 * MB, "file": 1 * MB, "active_file": 0, "inactive_file": 297 * MB,
|
||||
"active_anon": 99 * MB, "inactive_anon": 0, "shmem": 0}), 99 * MB)
|
||||
# without the anon-list fields: estimate (a) alone
|
||||
self.assertEqual(anon_live({"anon": 382 * MB, "file": 1 * MB, "active_file": 0, "inactive_file": 297 * MB}), 86 * MB)
|
||||
|
||||
def test_it_errs_high_never_above_anon(self):
|
||||
# RED-PROOF: drop the max(a, b) → 86 MB → FAILS; drop the cap → 69 MB above anon's 59 → FAILS.
|
||||
self.assertEqual(anon_live({"anon": 300 * MB, "file": 0, "active_file": 0, "inactive_file": 214 * MB,
|
||||
"active_anon": 100 * MB, "inactive_anon": 0, "shmem": 0}), 100 * MB)
|
||||
self.assertEqual(anon_live({"anon": 59 * MB, "file": 1 * MB, "active_file": 0, "inactive_file": 0,
|
||||
"active_anon": 69 * MB, "inactive_anon": 0, "shmem": 0}), 59 * MB)
|
||||
|
||||
def test_before_the_spike_nothing_is_given_back(self):
|
||||
self.assertEqual(anon_live({"anon": 59 * MB, "file": 1 * MB, "active_file": 0, "inactive_file": 0}), 59 * MB)
|
||||
|
||||
def test_real_file_cache_is_not_subtracted(self):
|
||||
# a page cache of 200 MB on the file lists (file == the lists): nothing is given-back anon
|
||||
self.assertEqual(anon_live({"anon": 300 * MB, "file": 200 * MB, "active_file": 120 * MB, "inactive_file": 80 * MB}), 300 * MB)
|
||||
|
||||
def test_missing_anon_is_unknown(self):
|
||||
self.assertIsNone(anon_live({"file": 1}))
|
||||
|
||||
|
||||
class SoakSummary(unittest.TestCase):
|
||||
def test_the_mark_reads_the_live_figure(self):
|
||||
os.environ.setdefault("TARGET", "9202")
|
||||
import box_walk
|
||||
lim = 402653184
|
||||
samples = [
|
||||
{"c": "wanderer-search", "anon": 59 * MB, "file": 1 * MB, "active_file": 0, "inactive_file": 0, "max": str(lim),
|
||||
"peak": 76 * MB, "oom_kill": 0, "restarts": 0, "running": "true", "started": "s", "oomkilled": "false", "cg": "x"},
|
||||
{"c": "wanderer-search", "anon": 382 * MB, "file": 1 * MB, "active_file": 0, "inactive_file": 297 * MB,
|
||||
"active_anon": 99 * MB, "inactive_anon": 0, "shmem": 0, "max": str(lim),
|
||||
"peak": lim, "oom_kill": 0, "restarts": 0, "running": "true", "started": "s", "oomkilled": "false", "cg": "x"},
|
||||
]
|
||||
r = box_walk.soak_summary(samples, 20, 10)
|
||||
c = r["containers"]["wanderer-search"]
|
||||
# RED-PROOF: let peaks take anon_peak_pct again → peak_pct 94.9 → FAILS.
|
||||
self.assertEqual(r["peak_pct"], round(100.0 * 99 * MB / lim, 1))
|
||||
self.assertEqual(c["anon_peak_pct"], round(100.0 * 382 * MB / lim, 1))
|
||||
self.assertEqual(r["peak_basis"], "anon_live")
|
||||
|
||||
|
||||
class TightMark(unittest.TestCase):
|
||||
def test_the_bench_mark_prefers_the_live_figure(self):
|
||||
ut = _load_upgrade_test()
|
||||
per = {"search": {"anon_live_peak_pct": 0.224, "anon_peak_pct": 0.995, "peak_pct": 1.0},
|
||||
"old": {"anon_peak_pct": 0.95, "peak_pct": 1.0}, # a record without the live figure: decision 22 stands
|
||||
"small": {"anon_live_peak_pct": 0.10, "anon_peak_pct": 0.12, "peak_pct": 0.5}}
|
||||
# RED-PROOF: look up anon_peak_pct before anon_live_peak_pct → "search" is tight → FAILS.
|
||||
self.assertEqual(ut.tight_containers(per, 0.80), ["old"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+38
-5
@@ -48,6 +48,7 @@ Usage: python3 upgrade-test.py [--soak SECONDS] <edge-id> [<edge-id> …] (se
|
||||
Layout: templates under /opt/upg/templates, evidence under /opt/upg/evidence
|
||||
"""
|
||||
import importlib.util, json, os, re, shutil, subprocess, sys, time
|
||||
from memfigure import anon_live # R-1338: the mark's memory figure, shared with box_walk.py
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
@@ -441,6 +442,29 @@ def _stat_anon(cg: str):
|
||||
return None
|
||||
|
||||
|
||||
def _stat_fields(cg: str):
|
||||
out = {}
|
||||
try:
|
||||
for line in open(os.path.join(cg, "memory.stat")):
|
||||
k, _, v = line.partition(" ")
|
||||
if k in ("anon", "file", "active_file", "inactive_file", "active_anon", "inactive_anon", "shmem"):
|
||||
out[k] = int(v)
|
||||
except (OSError, ValueError):
|
||||
return {}
|
||||
return out
|
||||
|
||||
|
||||
def tight_containers(per: dict, limit_frac: float):
|
||||
"""The containers the memory_tight mark names: the live anon figure (R-1338) where measured, else anon (decision
|
||||
22), else the cgroup peak — each as a fraction of the limit, above limit_frac."""
|
||||
def pct(p):
|
||||
for k in ("anon_live_peak_pct", "anon_peak_pct", "peak_pct"):
|
||||
if p.get(k) is not None:
|
||||
return p[k]
|
||||
return None
|
||||
return [n for n, p in per.items() if pct(p) is not None and pct(p) > limit_frac]
|
||||
|
||||
|
||||
def venue_swap_bytes(meminfo: str | None = None):
|
||||
"""R-733: the venue's own swap (SwapTotal of /proc/meminfo, in bytes) — None when it cannot be read.
|
||||
The bench guest had NONE while every box guest reads `swap: 512`: immich passed on 9202 by swapping
|
||||
@@ -483,6 +507,8 @@ def memory_snapshot(project: str, workdir: Path):
|
||||
# too, which the kernel reclaims before it kills anything (night 2026-09-23, nextcloud
|
||||
# read 100 % with 0 kills). Reported, not yet used for the verdict or the mark.
|
||||
"anon": _stat_anon(cg) if cg else None,
|
||||
# R-1338: the anon pages the app has NOT given back (MADV_FREE pages excluded) — the mark's figure.
|
||||
"anon_live": anon_live(_stat_fields(cg)) if cg else None,
|
||||
# R-733: swap beside anon — a box guest has 512 MiB swap, the bench had none.
|
||||
"swap": _read_int(os.path.join(cg, "memory.swap.current")) if cg else None,
|
||||
"swap_peak": _read_int(os.path.join(cg, "memory.swap.peak")) if cg else None,
|
||||
@@ -589,10 +615,14 @@ def memory_watch(app: str, project: str, workdir: Path, seconds: int, say, ev: P
|
||||
b = base0.get(n, {})
|
||||
pk, lim = v["peak"], v["limit"]
|
||||
anon_max = max([smp["containers"].get(n, {}).get("anon") or 0 for smp in samples] + [v.get("anon") or 0])
|
||||
lives = [x for x in [smp["containers"].get(n, {}).get("anon_live") for smp in samples] + [v.get("anon_live")] if x is not None]
|
||||
live_max = max(lives) if lives else None
|
||||
per[n] = {"limit": lim, "peak": pk,
|
||||
"peak_pct": round(pk / lim, 3) if (pk and lim) else None,
|
||||
"anon_peak_sampled": anon_max or None,
|
||||
"anon_peak_pct": round(anon_max / lim, 3) if (anon_max and lim) else None,
|
||||
"anon_live_peak_sampled": live_max,
|
||||
"anon_live_peak_pct": round(live_max / lim, 3) if (live_max is not None and lim) else None,
|
||||
"swap_peak": swap_peak_of(samples, n, v),
|
||||
"oom_kills": None if v["oom_kill"] is None else v["oom_kill"] - (b.get("oom_kill") or 0),
|
||||
"restarts": (v["restarts"] or 0) - (b.get("restarts") or 0),
|
||||
@@ -603,9 +633,10 @@ def memory_watch(app: str, project: str, workdir: Path, seconds: int, say, ev: P
|
||||
# reads the APP's own memory (anon, sampled) where it was measured. memory.peak counts the file cache,
|
||||
# which the kernel drops before it kills anything: nextcloud and immich's postgres read 100 % with 0
|
||||
# kills. The cgroup peak stays in the record; a kill or a restart still FAILS the edge either way.
|
||||
def _tight_pct(p):
|
||||
return p.get("anon_peak_pct") if p.get("anon_peak_pct") is not None else p["peak_pct"]
|
||||
tight = [n for n, p in per.items() if _tight_pct(p) is not None and _tight_pct(p) > MEMORY_TIGHT]
|
||||
# R-1338 (2026-10-28 night, the brief's „the gate reads the right figure"): the live anon figure — `anon` without the
|
||||
# pages the app already gave back (MADV_FREE), which the kernel reclaims first. anon and the cgroup peak stay in the
|
||||
# record beside it.
|
||||
tight = tight_containers(per, MEMORY_TIGHT)
|
||||
rec = {"soak_s": round(time.time() - t0, 1), "requested_s": seconds, "requests": hits["n"],
|
||||
"codes": hits["codes"], "first_kill": first_bad, "containers": per,
|
||||
"unmeasured": [n for n, p in per.items() if not p["measured"]],
|
||||
@@ -1298,7 +1329,9 @@ def write_ladder(argv) -> int:
|
||||
return 1
|
||||
digests[svc] = d
|
||||
conts = (bench["memory"].get("containers") or {}).values()
|
||||
anon = [c.get("anon_peak_pct") for c in conts if isinstance(c.get("anon_peak_pct"), (int, float))]
|
||||
live = [c.get("anon_live_peak_pct") for c in conts if isinstance(c.get("anon_live_peak_pct"), (int, float))]
|
||||
anon_raw = [c.get("anon_peak_pct") for c in conts if isinstance(c.get("anon_peak_pct"), (int, float))]
|
||||
anon = live or anon_raw # R-1338: the live figure where the watch measured it
|
||||
cg = [c.get("peak_pct") for c in conts if isinstance(c.get("peak_pct"), (int, float))]
|
||||
# the watch records FRACTIONS of the limit (0.81); the ladder carries PERCENT. memory_peak_pct is the
|
||||
# figure the mark is judged on: the app's own memory (anon) when the watch measured it (decision 22),
|
||||
@@ -1325,7 +1358,7 @@ def write_ladder(argv) -> int:
|
||||
entry = {"from": bfrom, "to": bto, "digest": digests, "verdict": "proven",
|
||||
"tested_at": bench["measured_at"], "harness_version": bench["harness_version"],
|
||||
"evidence": arg("--evidence"), "box_evidence": arg("--box-evidence"),
|
||||
"memory_peak_pct": peak, "memory_basis": "anon" if anon else "cgroup_peak",
|
||||
"memory_peak_pct": peak, "memory_basis": ("anon_live" if live else "anon") if anon else "cgroup_peak",
|
||||
"memory_cgroup_peak_pct": cg_peak,
|
||||
"marks": {"files_may_change": "files_may_change" in marks,
|
||||
"needs_person": None, "memory_tight": peak > ladder.MEMORY_TIGHT_PCT}}
|
||||
|
||||
@@ -852,6 +852,113 @@ class NZBGet:
|
||||
return True
|
||||
|
||||
|
||||
class Plex:
|
||||
"""Plex's own HTTP API makes a library section and the same API proves it survived (felhom.eu R-1238).
|
||||
|
||||
NO plex.tv ACCOUNT. An UNCLAIMED Plex answers a request from a private address with no token (felhom.eu
|
||||
`architecture/13-threat-model.md`, the R-1045 row) - the harness calls from the bench host at the container's own
|
||||
IP, so the caller is the docker bridge gateway (172.x.0.1), a private address. Measured on the bench 2026-10-28
|
||||
night (felhom.eu audits/night-2026-10-28/bench/plex/): POST /library/sections answered 201 with the new section;
|
||||
GET read it back before and after 1.41.4.9463 -> 1.43.5.11029, with PLEX_CLAIM absent AND with a junk PLEX_CLAIM
|
||||
(the image's first-run claim exchange fails and the server stays unclaimed). A CLAIMED server would answer 401 to
|
||||
this route - seed() then records why and returns None, it never reads that as "no data".
|
||||
|
||||
The server says it is ready only when /identity carries no `startState`: the healthcheck (curl -f /identity) is
|
||||
healthy while `startState` is `startingPlugins`, and a POST then answers 400 "the server is still starting up"
|
||||
(measured, the first spike attempt). JSON only with `Accept: application/json` - XML otherwise.
|
||||
|
||||
What is proven: the section (its name, uuid and folder) lives in Plex's own database in the config volume. No media
|
||||
is scanned; the scanner and the metadata agents are NOT measured, and no record claims they are."""
|
||||
port = 32400
|
||||
container = "plex"
|
||||
J = ("-H", "Accept: application/json")
|
||||
|
||||
def _base(self, ipfn):
|
||||
ip = ipfn(self.container)
|
||||
return f"http://{ip}:{self.port}" if ip else ""
|
||||
|
||||
def _ready(self, base, say, tries=90, delay=4):
|
||||
"""(True, identity) once /identity answers 200 JSON with no startState; (False, last answer) otherwise."""
|
||||
last = ""
|
||||
for _ in range(tries):
|
||||
rc, code, out = _curl(base + "/identity", *self.J, timeout=15)
|
||||
last = f"rc={rc} http={code} {out[:160]}"
|
||||
if rc == 0 and code == "200":
|
||||
try:
|
||||
mc = json.loads(out).get("MediaContainer") or {}
|
||||
except ValueError:
|
||||
mc = {}
|
||||
if "claimed" in mc and "startState" not in mc:
|
||||
return True, mc
|
||||
time.sleep(delay)
|
||||
say(f" plex: never finished starting ({last})")
|
||||
return False, None
|
||||
|
||||
def _sections(self, base):
|
||||
rc, code, out = _curl(base + "/library/sections", *self.J, timeout=30)
|
||||
if rc != 0 or code != "200":
|
||||
return None, f"rc={rc} http={code} {out[:160]}"
|
||||
try:
|
||||
return (json.loads(out).get("MediaContainer") or {}).get("Directory") or [], out
|
||||
except ValueError:
|
||||
return None, f"non-JSON http={code} {out[:160]}"
|
||||
|
||||
def seed(self, ipfn, say):
|
||||
base = self._base(ipfn)
|
||||
if not base:
|
||||
say(" plex: no container IP")
|
||||
return None
|
||||
ok, ident = self._ready(base, say)
|
||||
if not ok:
|
||||
return None
|
||||
if ident.get("claimed") is not False:
|
||||
self.tried = "the unclaimed private-address route: the server reports claimed=%r" % ident.get("claimed")
|
||||
say(f" plex: {self.tried} - this route needs an UNCLAIMED server")
|
||||
return None
|
||||
name = "felhom" + secrets.token_hex(4)
|
||||
q = ("name=%s&type=movie&agent=tv.plex.agents.movie&scanner=Plex%%20Movie&language=en-US&location=%%2Fmedia" % name)
|
||||
rc, code, out = _curl(base + "/library/sections?" + q, *self.J, method="POST", timeout=60)
|
||||
say(f" plex: POST /library/sections {name} http={code} (server {ident.get('version')}, claimed=false)")
|
||||
if rc != 0 or code not in ("200", "201"):
|
||||
self.tried = f"POST /library/sections answered rc={rc} http={code}: {out[:160]}"
|
||||
say(f" plex: the app refused the section ({out[:160]})")
|
||||
return None
|
||||
try:
|
||||
made = [d for d in (json.loads(out).get("MediaContainer") or {}).get("Directory") or [] if d.get("title") == name]
|
||||
except ValueError:
|
||||
made = []
|
||||
if not made or not made[0].get("uuid"):
|
||||
say(f" plex: the create answer does not carry the section ({out[:160]})")
|
||||
return None
|
||||
say(f" plex: seeded library section {name} key={made[0].get('key')} uuid={made[0]['uuid']}")
|
||||
return {"name": name, "uuid": made[0]["uuid"]}
|
||||
|
||||
def verify(self, ipfn, seeded, say):
|
||||
base = self._base(ipfn)
|
||||
if not base:
|
||||
return False
|
||||
ok, ident = self._ready(base, say)
|
||||
if not ok:
|
||||
return False
|
||||
secs, out = self._sections(base)
|
||||
if secs is None:
|
||||
say(f" plex: the app would not list its sections ({out})")
|
||||
return False
|
||||
# negative control first: a name nobody created must be absent
|
||||
ghost = "felhom" + secrets.token_hex(4)
|
||||
if any(d.get("title") == ghost for d in secs) or ghost in out:
|
||||
say(" plex: READBACK IS UNUSABLE - a section nobody created is present")
|
||||
return False
|
||||
hit = [d for d in secs if d.get("title") == seeded["name"]]
|
||||
if not hit:
|
||||
say(f" plex: the seeded section {seeded['name']} is GONE ({len(secs)} section(s) listed)")
|
||||
return False
|
||||
same = hit[0].get("uuid") == seeded["uuid"]
|
||||
locs = [l.get("path") for l in hit[0].get("Location") or []]
|
||||
say(f" plex: section {seeded['name']} read back (server {ident.get('version')}), same uuid={same}, folders={locs}")
|
||||
return same and "/media" in locs
|
||||
|
||||
|
||||
FIXTURES = {
|
||||
"privatebin": PrivateBin(),
|
||||
"docmost": Docmost(),
|
||||
@@ -865,4 +972,5 @@ FIXTURES = {
|
||||
"transmission": Transmission(),
|
||||
"sabnzbd": SABnzbd(),
|
||||
"nzbget": NZBGet(),
|
||||
"plex": Plex(),
|
||||
}
|
||||
@@ -509,6 +509,106 @@ class Gitea:
|
||||
return ok
|
||||
|
||||
|
||||
# =============================================================================================
|
||||
class PlexBox:
|
||||
"""Plex on the box (felhom.eu R-1238): the bench fixture's route (upgrade_fixtures.Plex — an UNCLAIMED Plex answers
|
||||
a private-address request with no token) through the household's FRONT DOOR behind the setup gate (Traefik → Plex;
|
||||
the request reaches Plex from Traefik's private address). When Plex will not take the front-door request as local,
|
||||
the same API is asked from Plex's OWN container (curl to 127.0.0.1, the image's own healthcheck tool) — R-156's
|
||||
other allowed route — and the record says which route was used. One library section is the seed; its name, uuid
|
||||
and folder are read back. Measured on 9202 2026-10-28 night (felhom.eu audits/night-2026-10-28/plex/)."""
|
||||
sub = "plex"
|
||||
J = ("-H", "Accept: application/json")
|
||||
|
||||
def _call(self, w, path, method=None):
|
||||
if getattr(self, "route", "front") == "front":
|
||||
rc, code, body = w.app_curl(self.sub, path, *self.J, method=method, timeout=60)
|
||||
return rc, code, body
|
||||
cmd = ["curl", "-s", "-w", "\\n%{http_code}", "-H", "Accept: application/json"]
|
||||
if method:
|
||||
cmd += ["-X", method]
|
||||
out = _gx(w, "plex", *(cmd + ["http://127.0.0.1:32400" + path]), timeout=90)
|
||||
body, _, code = out.rpartition("\n")
|
||||
return 0, code.strip(), body
|
||||
|
||||
def _ready(self, w, say, tries=90, delay=4):
|
||||
last = ""
|
||||
for _ in range(tries):
|
||||
rc, code, out = self._call(w, "/identity")
|
||||
last = f"rc={rc} http={code} {out[:160]}"
|
||||
if code == "200":
|
||||
try:
|
||||
mc = json.loads(out).get("MediaContainer") or {}
|
||||
except ValueError:
|
||||
mc = {}
|
||||
if "claimed" in mc and "startState" not in mc:
|
||||
return mc
|
||||
time.sleep(delay)
|
||||
say(f" plex: never finished starting ({last})")
|
||||
return None
|
||||
|
||||
def seed(self, w, sub, say):
|
||||
self.route = "front"
|
||||
if not w.wait_app(self.sub, "/identity", want=("200",), tries=72):
|
||||
return None
|
||||
ident = self._ready(w, say)
|
||||
if ident is None:
|
||||
return None
|
||||
if ident.get("claimed") is not False:
|
||||
say(f" plex: the server reports claimed={ident.get('claimed')!r} — this route needs an UNCLAIMED server")
|
||||
return None
|
||||
name = "felhom" + secrets.token_hex(4)
|
||||
q = "name=%s&type=movie&agent=tv.plex.agents.movie&scanner=Plex%%20Movie&language=en-US&location=%%2Fmedia" % name
|
||||
rc, code, out = self._call(w, "/library/sections?" + q, method="POST")
|
||||
say(f" plex: POST /library/sections through the front door http={code}")
|
||||
if code not in ("200", "201"):
|
||||
say(f" plex: the front door was not taken as local ({out[:120]}) — asking from Plex's own container")
|
||||
self.route = "own-container"
|
||||
rc, code, out = self._call(w, "/library/sections?" + q, method="POST")
|
||||
say(f" plex: POST /library/sections from its own container http={code}")
|
||||
if code not in ("200", "201"):
|
||||
say(f" plex: refused ({out[:160]})")
|
||||
return None
|
||||
try:
|
||||
made = [d for d in (json.loads(out).get("MediaContainer") or {}).get("Directory") or [] if d.get("title") == name]
|
||||
except ValueError:
|
||||
made = []
|
||||
if not made or not made[0].get("uuid"):
|
||||
say(f" plex: the create answer does not carry the section ({out[:160]})")
|
||||
return None
|
||||
say(f" plex: seeded library section {name} uuid={made[0]['uuid']} (route {self.route}, server {ident.get('version')})")
|
||||
return {"name": name, "uuid": made[0]["uuid"], "route": self.route}
|
||||
|
||||
def verify(self, w, sub, t, say):
|
||||
self.route = t.get("route", "front")
|
||||
if not w.wait_app(self.sub, "/identity", want=("200",), tries=72):
|
||||
return False
|
||||
ident = self._ready(w, say)
|
||||
if ident is None:
|
||||
return False
|
||||
rc, code, out = self._call(w, "/library/sections")
|
||||
if code != "200":
|
||||
say(f" plex: the app would not list its sections http={code} ({out[:120]})")
|
||||
return False
|
||||
try:
|
||||
secs = (json.loads(out).get("MediaContainer") or {}).get("Directory") or []
|
||||
except ValueError:
|
||||
say(" plex: the section list is not JSON")
|
||||
return False
|
||||
ghost = "felhom" + secrets.token_hex(4)
|
||||
if any(d.get("title") == ghost for d in secs) or ghost in out:
|
||||
say(" plex: READBACK UNUSABLE — a section nobody created is present")
|
||||
return False
|
||||
hit = [d for d in secs if d.get("title") == t["name"]]
|
||||
if not hit:
|
||||
say(f" plex: the seeded section {t['name']} is GONE ({len(secs)} listed)")
|
||||
return False
|
||||
same = hit[0].get("uuid") == t["uuid"]
|
||||
locs = [l.get("path") for l in hit[0].get("Location") or []]
|
||||
say(f" plex: section {t['name']} read back (server {ident.get('version')}, route {self.route}), same uuid={same}, folders={locs}")
|
||||
return same and "/media" in locs
|
||||
|
||||
|
||||
# =============================================================================================
|
||||
class Navidrome:
|
||||
"""Navidrome's own REST API: create the first admin through /auth/createAdmin, then prove the
|
||||
@@ -3365,6 +3465,7 @@ FIXTURES = {
|
||||
"opengist": OpenGist(),
|
||||
"papra": Papra(),
|
||||
"wanderer": Wanderer(),
|
||||
"plex": PlexBox(),
|
||||
"homepage": Homepage(),
|
||||
"seerr": Seerr(),
|
||||
"mealie": Mealie(),
|
||||
|
||||
Reference in new issue
Block a user