Files
vvvomitandClaude Opus 5.5 c7c384402f Blackout mode picks mirrors that carry what the server needs
Choosing blackout on the Server step now points every source at the
in-country defaults (playbook and roles on Forgejo, images from zot,
packages and PyPI from infamous), not only the empty mirror fields.

A blackout deploy then checks them before using them and swaps in the
first known mirror that has everything: PyPI before installing Ansible,
the registry against every image the enabled services use (the one
missing fewest when none has all), the OS and Docker package mirrors
against the server's distro and release. Each switch is logged and sent
back as a Sources event, which the UI saves; vars.yml is rewritten when
it names the mirror. The run works on a copy of the config, as migrations
already did, so the UI never reads it mid-change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 22:07:20 +03:30

63 lines
2.0 KiB
Go

package deploy
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
"interzone/internal/config"
)
func TestPickFor(t *testing.T) {
fresh := "Date: " + time.Now().UTC().Format(time.RFC1123) + "\n"
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/good/ubuntu/dists/noble-security/Release" {
http.NotFound(w, r)
return
}
w.Write([]byte(fresh))
}))
defer srv.Close()
defer func(k []config.Mirror) { config.KnownMirrors = k }(config.KnownMirrors)
config.KnownMirrors = []config.Mirror{
{Kind: config.MirrorOS, URL: srv.URL + "/debian-only", Covers: []string{config.Debian}},
{Kind: config.MirrorOS, URL: srv.URL + "/empty", Covers: []string{config.Ubuntu}},
{Kind: config.MirrorOS, URL: srv.URL + "/good", Covers: []string{config.Ubuntu}},
}
needs := []need{{config.Ubuntu, "noble"}}
for _, tc := range []struct{ set, want string }{
{srv.URL + "/broken", srv.URL + "/good"}, // the set one lacks it: the first known one that has it
{srv.URL + "/good", srv.URL + "/good"},
{"", srv.URL + "/good"},
} {
c := config.Default()
c.Sources.Blackout, c.Sources.APTMirror = true, tc.set
r := &Runner{cfg: c, events: make(chan Event, 64)}
r.pickFor(context.Background(), config.MirrorOS, &c.Sources.APTMirror, needs, "x86_64")
if c.Sources.APTMirror != tc.want {
t.Errorf("set %q: picked %q, want %q", tc.set, c.Sources.APTMirror, tc.want)
}
saved := false
for len(r.events) > 0 {
if (<-r.events).Sources != nil {
saved = true
}
}
if saved != (tc.set != tc.want) {
t.Errorf("set %q: Sources event sent = %v", tc.set, saved)
}
}
// nothing carries it: the set one stays
c := config.Default()
c.Sources.APTMirror = srv.URL + "/broken"
r := &Runner{cfg: c, events: make(chan Event, 64)}
r.pickFor(context.Background(), config.MirrorOS, &c.Sources.APTMirror, []need{{config.Ubuntu, "jammy"}}, "x86_64")
if c.Sources.APTMirror != srv.URL+"/broken" {
t.Errorf("with no mirror carrying it, picked %q", c.Sources.APTMirror)
}
}