mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-10 12:47:04 +00:00
The svc-cache-package CLI probe GETs every declared route path through the frontend and fails on 502/503/504. registry.ollama.ai declared no paths, so the probe asked for /, which upstream now answers with 503; Nexus relays an upstream 5xx as its own 503, so package#0 (CI run 40979252521) failed with 'registry.ollama.ai/ on port 443 answered 503'. The host now declares /v2/, the registry API root every ollama pull goes through (manifests and blobs); upstream answers it with 404, which Nexus relays as 404 and the probe accepts. On a TLS host the frontend still proxies the whole host through location /, because upstreams.conf.j2 reads routes only for plain-HTTP listeners: the rendered upstreams.conf is byte-identical before and after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
3.0 KiB
Python
93 lines
3.0 KiB
Python
"""Unit tests for writing the generated package-cache files.
|
|
|
|
The shape measured in a gate run: a container had rendered
|
|
compose/package-cache/pip.conf under its own uid, and the next host-side
|
|
render died on it with PermissionError while the directory stayed writable.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import stat
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from utils.cache.hosts import host_records
|
|
from utils.cache.render import _write, upstreams_conf
|
|
|
|
OLLAMA_HOST = "registry.ollama.ai"
|
|
OLLAMA_REPO = "raw-ollama-registry"
|
|
|
|
|
|
class TestWrite(unittest.TestCase):
|
|
"""A file the renderer cannot overwrite is replaced, not given up on."""
|
|
|
|
def test_an_unwritable_file_is_replaced(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
target = Path(directory, "pip.conf")
|
|
target.write_text("stale", encoding="utf-8")
|
|
target.chmod(stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
|
|
|
|
_write(target, "fresh")
|
|
|
|
self.assertEqual(
|
|
target.read_text(
|
|
encoding="utf-8"
|
|
), # nocheck: cache-read tempdir fixture rewritten in this test
|
|
"fresh",
|
|
)
|
|
|
|
def test_a_writable_file_keeps_its_inode(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
target = Path(directory, "arch.list")
|
|
target.write_text("stale", encoding="utf-8")
|
|
before = target.stat().st_ino
|
|
|
|
_write(target, "fresh")
|
|
|
|
self.assertEqual(
|
|
target.read_text(
|
|
encoding="utf-8"
|
|
), # nocheck: cache-read tempdir fixture rewritten in this test
|
|
"fresh",
|
|
)
|
|
self.assertEqual(target.stat().st_ino, before)
|
|
|
|
def test_a_missing_parent_is_created(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
target = Path(directory, "apt", "debian.list")
|
|
|
|
_write(target, "fresh")
|
|
|
|
self.assertEqual(
|
|
target.read_text(
|
|
encoding="utf-8"
|
|
), # nocheck: cache-read tempdir fixture rewritten in this test
|
|
"fresh",
|
|
)
|
|
|
|
|
|
class TestOllamaRegistry(unittest.TestCase):
|
|
def test_the_probe_requests_a_path_under_v2(self) -> None:
|
|
self.assertEqual(
|
|
host_records()[OLLAMA_HOST]["routes"],
|
|
[{"path": "/v2/", "repo": OLLAMA_REPO}],
|
|
f"{OLLAMA_HOST} answers 503 on its bare root, so the package-cache "
|
|
"probe must request a path under /v2/, which it serves",
|
|
)
|
|
|
|
def test_the_tls_frontend_still_proxies_the_whole_host(self) -> None:
|
|
block = next(
|
|
block
|
|
for block in upstreams_conf().split("server {")
|
|
if f"server_name {OLLAMA_HOST};" in block
|
|
)
|
|
|
|
self.assertIn("location / {", block)
|
|
self.assertIn(f"/repository/{OLLAMA_REPO}/;", block)
|
|
self.assertNotIn("location /v2/", block)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|