Files
alzeo/tests/test_install_docker_room.py
Hasan BasbunarandClaude Opus 5.5 9e0e2a67f6 install: the OCR lane's image pull asks SGLang 1.0.0's measured peak, 54 GiB, as the 27B lane's
install-ocr.sh still asked 48 GiB, v0.5.21's peak; the image it pulls is the
27B lane's (the same digest), whose peak the v1.61.0 measured at 51.6 GiB and
counts as 54 in install.sh (DOCKER_NEED_GB), prepare-lane.sh (pull_image 27b)
and the other installers on that image. tests/test_install_docker_room.py now
puts the OCR lane in the PEAK table and holds its IMAGE_GB to the 27B's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:21:19 +01:00

207 lines
10 KiB
Python

#!/usr/bin/env python3
"""The docker room install.sh asks for depends on whether it has anything to pull.
The preflight asked for 40 GB free on the docker root whatever was there, so an update
on a box with the pinned image already in place and 36 GB free was refused, with
nothing to download (reference box, 2026-09-23). These run the installer's own lines,
as written, against a fake docker and a fake df."""
import math
import pathlib
import re
import subprocess
import tempfile
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
INSTALL = REPO / "install.sh"
FAKE_DOCKER = """#!/bin/sh
case "$1 $2" in
"info --format") echo /var/lib/docker ;;
"image inspect") for i in $FAKE_IMAGES; do [ "$i" = "$3" ] && exit 0; done; exit 1 ;;
*) exit 1 ;;
esac
"""
FAKE_DF = """#!/bin/sh
printf 'Disp.\\n %sG\\n' "$FAKE_FREE"
"""
def block() -> str:
text = INSTALL.read_text()
start = text.index("DOCKER_ROOT=$(docker info")
end = text.index("\n", text.index('|| die "Need ~${DOCKER_NEED_GB} GiB free on $DOCKER_ROOT', start)) + 1
return text[start:end]
def run(lane, free, images):
t = pathlib.Path(tempfile.mkdtemp(prefix="docker-room-"))
for name, body in (("docker", FAKE_DOCKER), ("df", FAKE_DF)):
(t / name).write_text(body)
(t / name).chmod(0o755)
need, label = ("35", "30 GB Docker image") if lane == "flash" else ("40", "39 GB Docker image")
script = ("set -euo pipefail\ndie(){ echo \"DIE: $*\"; exit 1; }\n"
f"LANE={lane}; DOCKER_NEED_GB={need}; IMG_LABEL='{label}'; UNITS_ONLY=0\n" # a whole install
"IMAGE=lmsysorg/sglang@sha256:27b; FLASH_IMAGE=lmsysorg/sglang@sha256:flash\n"
+ block() + 'echo "PASS need=$DOCKER_NEED_GB pull=$PULL_TARGET"\n')
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
env={"PATH": f"{t}:/usr/bin:/bin", "FAKE_FREE": str(free),
"FAKE_IMAGES": " ".join(images)})
return r.stdout + r.stderr
class TheDockerRoomFollowsWhatThereIsToPull(unittest.TestCase):
def test_an_update_with_the_image_in_place_is_not_refused_for_its_size(self):
out = run("27b", 36, ["lmsysorg/sglang@sha256:27b"])
self.assertIn("PASS need=5 pull=lmsysorg/sglang@sha256:27b", out)
def test_a_first_pull_still_needs_the_room_for_the_image(self):
out = run("27b", 36, [])
self.assertIn("DIE: Need ~40 GiB free on /var/lib/docker for the 39 GB Docker image; found 36 GiB", out)
def test_even_an_image_in_place_needs_the_containers_room(self):
out = run("27b", 3, ["lmsysorg/sglang@sha256:27b"])
self.assertIn("DIE: Need ~5 GiB free on /var/lib/docker for the container (its image is already here)", out)
def test_the_flash_lane_looks_for_its_own_image(self):
self.assertIn("PASS need=5 pull=lmsysorg/sglang@sha256:flash",
run("flash", 20, ["lmsysorg/sglang@sha256:flash"]))
# the 27B's image being here says nothing about the flash lane's
self.assertIn("DIE: Need ~35 GiB free", run("flash", 20, ["lmsysorg/sglang@sha256:27b"]))
class TheRoomCoversAPullsPeak(unittest.TestCase):
"""What install.sh and prepare-lane.sh ask before a pull covers its peak in either of Docker's
image stores (the containerd one, Docker 29's default on a new install, keeps the downloads
beside the unpacked image), in GiB as df -BG rounds them up. They asked for 40 and 35, the
image alone, and Kolibri's installer 23 (found in review, 2026-10-15)."""
# (GB unpacked, GB to download) of each image, from the registry and the reference box
PEAK = {"27b": (38.54, 16.82), "flash": (34.4, 15.3), "kolibri": (22.1, 9.6), "nemotron": (24.46, 10.30),
"ocr": (38.54, 16.82)} # the OCR lane runs the 27B lane's image (the same digest, install-ocr.sh OCR_IMAGE)
@staticmethod
def need(unpacked, download):
return math.ceil((unpacked + download) * 1e9 / 2 ** 30 * 1.02) + 1
def test_each_lane_asks_for_its_peak_and_the_two_scripts_agree(self):
text = INSTALL.read_text()
n27 = int(re.search(r'^NEED_GB=45; DOCKER_NEED_GB=(\d+);', text, re.M).group(1))
nfl = int(re.search(r'^ NEED_GB=180; DOCKER_NEED_GB=(\d+);', text, re.M).group(1))
prep = (REPO / "prepare-lane.sh").read_text()
p27 = int(re.search(r'pull_image "\$img" 27b (\d+)', prep).group(1))
pfl = int(re.search(r'pull_image "\$img" flash (\d+)', prep).group(1))
self.assertGreaterEqual(n27, self.need(*self.PEAK["27b"]))
self.assertGreaterEqual(nfl, self.need(*self.PEAK["flash"]))
self.assertEqual((p27, pfl), (n27, nfl)) # one number each lane, the same in both
for lane in ("kolibri", "nemotron", "ocr"):
with self.subTest(lane=lane):
inst = (REPO / f"install-{lane}.sh").read_text()
self.assertGreaterEqual(int(re.search(r'^IMAGE_GB=(\d+)', inst, re.M).group(1)), self.need(*self.PEAK[lane]))
# the OCR lane's image is the 27B lane's: it asks the same room as install.sh and prepare-lane.sh, one number
self.assertEqual(int(re.search(r'^IMAGE_GB=(\d+)', (REPO / "install-ocr.sh").read_text(), re.M).group(1)), n27)
class TheCheckpointsRoomIsInOnePlace(unittest.TestCase):
"""The room a text lane's checkpoint asks, with its caches: install.sh's NEED_GB, the switch's
and a first Load's (lanes.sh ckpt_room_gb), one number each lane."""
def test_install_the_switch_and_a_first_load_ask_the_same(self):
text = INSTALL.read_text()
n27 = int(re.search(r"^NEED_GB=(\d+); DOCKER_NEED_GB=", text, re.M).group(1))
nfl = int(re.search(r"^ NEED_GB=(\d+); DOCKER_NEED_GB=", text, re.M).group(1))
lanes = (REPO / "lanes.sh").read_text()
fn = lanes[lanes.index("ckpt_room_gb(){"):]
self.assertIn(f"local n={n27} have dir=", fn)
self.assertIn(f'[ "$1" = flash ] && n={nfl}', fn)
self.assertIn('DL_NEED_GB="$(ckpt_room_gb "$TARGET_LANE" "$HF_CACHE" "$TARGET_REPO" "$TARGET_REV")"', (REPO / "switch-model.sh").read_text())
self.assertIn("ckpt_room_gb flash", (REPO / "prepare-lane.sh").read_text())
self.assertIn("ckpt_room_gb 27b", (REPO / "prepare-lane.sh").read_text())
def test_what_it_answers(self):
# 1 for a target whole in the cache, else the lane's number less what its blobs hold, 10
# at least (a sparse file: its apparent size is what du counts)
d = pathlib.Path(tempfile.mkdtemp(prefix="ckpt-room-"))
repo = d / "hub" / "models--org--m"
(repo / "blobs").mkdir(parents=True)
def ask(lane):
r = subprocess.run(["bash", "-c", f'set -euo pipefail\n. "{REPO}/lanes.sh"\nckpt_room_gb {lane} "{d}" org/m abc123'],
capture_output=True, text=True, timeout=30)
self.assertEqual(r.returncode, 0, r.stderr)
return int(r.stdout)
self.assertEqual((ask("flash"), ask("27b")), (180, 45))
with open(repo / "blobs" / "x.incomplete", "wb") as f:
f.truncate(100 * 1024 ** 3)
self.assertEqual((ask("flash"), ask("27b")), (80, 10))
with open(repo / "blobs" / "x.incomplete", "wb") as f:
f.truncate(200 * 1024 ** 3)
self.assertEqual(ask("flash"), 10)
(repo / "blobs" / "x.incomplete").unlink()
(repo / "snapshots" / "abc123").mkdir(parents=True)
(repo / "snapshots" / "abc123" / "model.safetensors").write_text("w")
self.assertEqual((ask("flash"), ask("27b")), (1, 1))
PIN_DOCKER = """#!/bin/sh
# image inspect REF [--format {{.Id}}] | tag SRC DST ; state in $FAKE_DIR
if [ "$1 $2" = "image inspect" ]; then
f="$FAKE_DIR/$(printf '%s' "$3" | tr '/:@' '___')"
[ -f "$f" ] || exit 1
cat "$f"; exit 0
fi
if [ "$1" = tag ]; then
echo "tag $2 $3" >> "$FAKE_DIR/calls"
cp "$FAKE_DIR/$(printf '%s' "$2" | tr '/:@' '___')" "$FAKE_DIR/$(printf '%s' "$3" | tr '/:@' '___')"; exit 0
fi
exit 1
"""
class ThePinnedImagesAreTagged(unittest.TestCase):
"""An image pulled by digest has no tag, and `docker image prune` deletes untagged
images: both serving images of the reference box were in that set (2026-09-23)."""
def run_pin(self, present, tagged=False, ref="lmsysorg/sglang@sha256:" + "d6e7288627be" + "0" * 52):
# in lanes.sh since prepare-lane.sh tags the image a lane's first Load pulls (2026-10-15)
text = (REPO / "lanes.sh").read_text()
start = text.index("pin_tag() {")
fn = text[start:text.index("\n}\n", start) + 3]
t = pathlib.Path(tempfile.mkdtemp(prefix="pin-"))
(t / "docker").write_text(PIN_DOCKER)
(t / "docker").chmod(0o755)
if present:
(t / ref.replace("/", "_").replace(":", "_").replace("@", "_")).write_text("sha256:img\n")
if tagged:
(t / "qwen38-pinned_27b-d6e7288627be").write_text("sha256:img\n")
r = subprocess.run(["bash", "-c", "set -euo pipefail\n" + fn + f'pin_tag 27b "{ref}"\n'],
capture_output=True, text=True, timeout=30,
env={"PATH": f"{t}:/usr/bin:/bin", "FAKE_DIR": str(t)})
self.assertEqual(r.returncode, 0, r.stderr)
calls = (t / "calls").read_text() if (t / "calls").exists() else ""
return r.stdout, calls
def test_a_digest_pull_gets_its_tag(self):
out, calls = self.run_pin(present=True)
self.assertIn("tagged qwen38-pinned:27b-d6e7288627be", out)
self.assertIn("tag lmsysorg/sglang@sha256:d6e7288627be", calls)
def test_an_image_already_tagged_is_left_alone_and_quiet(self):
out, calls = self.run_pin(present=True, tagged=True)
self.assertEqual((out, calls), ("", ""))
def test_an_image_that_is_not_here_is_not_tagged(self):
self.assertEqual(self.run_pin(present=False), ("", ""))
def test_a_tag_reference_needs_no_tag(self):
self.assertEqual(self.run_pin(present=True, ref="lmsysorg/sglang:v0.5.19"), ("", ""))
def test_install_sh_has_it_before_it_tags(self):
text = INSTALL.read_text()
self.assertLess(text.index('. "$REPO_DIR/lanes.sh"'), text.index('pin_tag "$LANE" "$PULLED_IMAGE"'))
self.assertNotIn("pin_tag() {", text) # one definition, in lanes.sh
if __name__ == "__main__":
unittest.main(verbosity=2)