Files
serverAppConfigs/tests/dankserver_quadlet.bats
dank 183a6d5442 feat(fleet): give the media servers an I/O share that actually exists
A Plex section scan walked 50k files at ~850 r/s and nothing bounded it.
`IOWeight=` in a quadlet looks like the fix and does nothing: systemd delegates
`cpu memory pids` to user@.service and NOT io, and it drops a resource line it
cannot honour without a word — the container boots healthy and its cgroup has no
io.weight file at all. Same family as RequiresMountsFor= (inert in the user
manager) and ConditionPathIsMountPoint= (fail-dead).

Place the two system drop-ins that make the controller reachable (user.slice
IOAccounting=yes puts io in user.slice/cgroup.subtree_control, measured
immediately; user@1000.service DelegateControllers gains io and lands at the
next reboot, because restarting the user manager would kill every rootless
container on the host), then ask for the share: IOWeight=10 on jellyfin and plex.
10 is a convention, not a measured optimum — proportional share, only bites
under contention, only requirement is far below the default 100.

ensure_user_io_delegate places both from git and prints NOTE: io is not
delegated … inert until the next reboot, so the quadlet line never reads as live
config. Verified on the host: subtree_control flipped to `cpu io memory pids`,
the drop-in is attached and parsed (systemctl cat), and the podman 5.7 generator
emits IOWeight=10 for both units (bare key; UnitConfigItem= not needed).

Two limits recorded instead of hidden: a container's weight covers its whole
cgroup (scan and playback share it), and the comparison happens inside
user.slice, so it cannot push a rootless unit below a root unit such as
frank-archon — that pairing is user.slice's own weight, a separate call.

Docs: Quadlet Lifecycle 4b (the three-command read of the chain), Pi-hole (all
rootless containers share one 10.0.2.100, so one chatty container throttles DNS
for the host — 8 events today), E2E Suite gotcha 7 (the gate depends on the
runner's resolver: 21 reds on a lost wired link, 37/37 minutes later).

Seam: an in-repo IOWeight= may only exist when both drop-ins exist AND the
deployer places them. ./tests/run.sh: 789 ok, exit 0.
2026-10-31 18:42:27 -07:00

130 lines
7.5 KiB
Bash
Executable File

#!/usr/bin/env bats
# Seam: the eight cutover-era dankserver quadlet units (romm trio, jellyfin,
# calibre-web, copyparty, plex, tautulli) must keep their boot-persistence and v1-generator
# contracts. The podman 5.x v1 Quadlet generator silently drops or hard-fails
# on several keys; these tests pin the contract that keeps the units loadable
# and secret-free in the repo.
load helpers
@test "all eight cutover units exist under dankserver/<svc>/quadlet/" {
for unit in romm/quadlet/romm romm/quadlet/romm-mariadb romm/quadlet/romm-redis jellyfin/quadlet/jellyfin calibre-web/quadlet/calibre-web copyparty/quadlet/copyparty plex/quadlet/plex tautulli/quadlet/tautulli; do
[ -f "$REPO_ROOT/dankserver/$unit.container" ] || return 1
done
}
@test "every cutover unit is boot-persistent (WantedBy=default.target)" {
for unit in romm/quadlet/romm romm/quadlet/romm-mariadb romm/quadlet/romm-redis jellyfin/quadlet/jellyfin calibre-web/quadlet/calibre-web copyparty/quadlet/copyparty plex/quadlet/plex tautulli/quadlet/tautulli; do
grep -q '^WantedBy=default.target$' "$REPO_ROOT/dankserver/$unit.container" || return 1
done
}
@test "copyparty uses Exec= not Command= (v1 generator hard-fails on Command=)" {
unit="$REPO_ROOT/dankserver/copyparty/quadlet/copyparty.container"
grep -q '^Command=' "$unit" && return 1
grep -q '^Exec=-a ${COPAY_ACCOUNT}:${COPAY_PASSWORD}' "$unit" || return 1
}
@test "copyparty and romm consume host-local env files, never in-repo secrets" {
grep -q '^EnvironmentFile=/home/dank/Containers/copyparty/env$' \
"$REPO_ROOT/dankserver/copyparty/quadlet/copyparty.container" || return 1
for unit in romm/quadlet/romm romm/quadlet/romm-mariadb; do
grep -q '^EnvironmentFile=/home/dank/Containers/romm/env$' \
"$REPO_ROOT/dankserver/$unit.container" || return 1
done
# No literal credential may ever appear in a tracked unit file: the only
# Exec= arguments must be variable expansions, never a literal account:secret.
! grep -qE '\-a [A-Za-z0-9]+:[A-Za-z0-9]' "$REPO_ROOT/dankserver/copyparty/quadlet/copyparty.container" || return 1
}
@test "romm db services keep their service-discovery aliases on the appnet" {
grep -q '^Network=dankserver_appnet:alias=mariadb$' \
"$REPO_ROOT/dankserver/romm/quadlet/romm-mariadb.container" || return 1
grep -q '^Network=dankserver_appnet:alias=redis$' \
"$REPO_ROOT/dankserver/romm/quadlet/romm-redis.container" || return 1
}
@test "no unit uses the unsupported Device= key (v1 generator needs AddDevice=)" {
# A rejected file kills its own unit silently: the deploy would then die
# with "Unit jellyfin.service not found" only on the target. Device= was
# the first offender (jellyfin GPU passthrough); Command= is guarded
# above. Keep this list current with every generator finding.
for unit in dankserver/romm/quadlet/romm dankserver/romm/quadlet/romm-mariadb \
dankserver/romm/quadlet/romm-redis dankserver/jellyfin/quadlet/jellyfin \
dankserver/calibre-web/quadlet/calibre-web dankserver/copyparty/quadlet/copyparty \
dankserver/plex/quadlet/plex dankserver/tautulli/quadlet/tautulli; do
! grep -q '^Device=' "$REPO_ROOT/$unit.container" || return 1
done
grep -q '^AddDevice=/dev/dri$' "$REPO_ROOT/dankserver/jellyfin/quadlet/jellyfin.container" || return 1
}
@test "every host-served port is explicitly published (no silent bridge-only)" {
grep -q '^PublishPort=8085:8080$' "$REPO_ROOT/dankserver/romm/quadlet/romm.container" || return 1
grep -q '^PublishPort=8096:8096$' "$REPO_ROOT/dankserver/jellyfin/quadlet/jellyfin.container" || return 1
grep -q '^PublishPort=8083:8083$' "$REPO_ROOT/dankserver/calibre-web/quadlet/calibre-web.container" || return 1
grep -q '^PublishPort=3923:3923$' "$REPO_ROOT/dankserver/copyparty/quadlet/copyparty.container" || return 1
grep -q '^PublishPort=32400:32400$' "$REPO_ROOT/dankserver/plex/quadlet/plex.container" || return 1
grep -q '^PublishPort=8181:8181$' "$REPO_ROOT/dankserver/tautulli/quadlet/tautulli.container" || return 1
}
@test "plex runs the fleet identity model (PUID=0/PGID=0, no userns remap)" {
# Rootless podman cannot map the real host uid 997 (subuid range is
# 100000:65536), so the fleet model applies: container root maps to the
# dank user and the deployer chowns /var/lib/plexmediaserver to
# 1000:1000 on first cutover; rollback chowns back to 997:984. Pin both
# keys and the ABSENCE of any userns key — UsernsMode= is compose syntax
# (the v1 generator hard-fails the whole unit on it) and UserNS= would
# remap the container away from the fleet identity.
unit="$REPO_ROOT/dankserver/plex/quadlet/plex.container"
grep -q '^Environment=PUID=0$' "$unit" || return 1
grep -q '^Environment=PGID=0$' "$unit" || return 1
! grep -qE '^(UserNS|UsernsMode)=' "$unit" || return 1
}
@test "calibre-server unit exists and is boot-persistent" {
unit="$REPO_ROOT/dankserver/calibre-server/quadlet/calibre-server.container"
[ -f "$unit" ] || return 1
grep -q '^WantedBy=default.target$' "$unit" || return 1
grep -q '^Restart=always$' "$unit" || return 1
}
@test "calibre-server serves the content server auth-gated on the published port" {
# The security contract: the content server runs with --enable-auth and
# --auth-mode=basic (Digest is the non-SSL default and rejects Basic
# clients with 400), on the internal port the unit publishes as 8084.
unit="$REPO_ROOT/dankserver/calibre-server/quadlet/calibre-server.container"
grep -q '^Exec=calibre-server --port 8090 --enable-auth --auth-mode=basic --userdb /userdb.sqlite /books$' "$unit" || return 1
grep -q '^PublishPort=8084:8090$' "$unit" || return 1
}
@test "calibre-server consumes host-local credential stores, never in-repo secrets" {
unit="$REPO_ROOT/dankserver/calibre-server/quadlet/calibre-server.container"
grep -q '^EnvironmentFile=/home/dank/Containers/calibre-server/env$' "$unit" || return 1
grep -q '^Volume=/home/dank/Containers/calibre-server/userdb.sqlite:/userdb.sqlite$' "$unit" || return 1
# The userdb's pw column is plaintext: no literal password may appear in
# the tracked unit, and the desktop basic-auth credential comes from the
# env file, not an Environment= line.
! grep -qE '^Environment=CUSTOM_(USER|PASSWORD)=' "$unit" || return 1
}
@test "a quadlet that asks for an I/O share ships the host permission that makes it real" {
# IOWeight= is silently inert unless the system manager both enables io for
# user.slice and delegates it to the user manager: systemd drops a resource
# line it cannot honour without a word and the container still starts healthy.
# So an in-repo weight is only honest together with both drop-ins AND with a
# deployer that places them. Measured 2026-10-31; verification chain in
# Architecture/Quadlet Lifecycle 4b.
if grep -lq '^IOWeight=' "$REPO_ROOT"/dankserver/*/quadlet/*.container; then
asked=1
else
skip "no dankserver quadlet asks for an I/O share"
fi
grep -q '^IOAccounting=yes$' \
"$REPO_ROOT/dankserver/host/systemd/user.slice.d/io-accounting.conf" || return 1
grep -q '^DelegateControllers=.* io' \
"$REPO_ROOT/dankserver/host/systemd/user@1000.service.d/io-delegate.conf" || return 1
for f in user.slice.d/io-accounting.conf 'user@1000.service.d/io-delegate.conf'; do
grep -q "dankserver/host/systemd/$f" "$REPO_ROOT/scripts/deploy-remote.sh" || return 1
done
}