carlos / platform Public

console: what the creating release says, and whether a placement is the account's own boxes (rootfs spec §5.0, §5.7)

rootfsHeadFor reads the channel head, else the app's established kind
(history, then the first ship's marker); a head it cannot read never
decides binary, and a history it cannot read refuses with C08.
rootfsPlacementRefusal refuses pools first (D9), allows any box on a
single-tenant deployment, and otherwise asks ownsFleet; a fleet read error
answers 500 as the place door does. rootfsReadyRefusal counts only fresh,
rootfs_ready heartbeats of boxes ListFleetBoxes reports active, or platform
boxes of the region; C06 names the region by its place. No
rootfsOnOwnBoxes (preflight 2.5). Rows RFS-4-C01, C02, C05 to C08 built.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev dbae21bedc2bbcbfc1a01352fe57d4b39022cc98 parent 01f53ed
3 files changed, +485 −0
  • approved_rootfs_copy_test.go +3 −0
  • internal/console/rootfs.go +181 −0
  • internal/console/rootfs_test.go +301 −0
diff --git a/approved_rootfs_copy_test.go b/approved_rootfs_copy_test.go
index a2474c7eb..12e4ad14d 100644
--- a/approved_rootfs_copy_test.go
+++ b/approved_rootfs_copy_test.go
@@ -192,6 +192,9 @@ var rootfsCopyBuilt = []string{
// Plan 3 Task 13: the move doors and carlos apps place refuse rootfs
// instances (internal/console/seedmove.go)
"RFS-3-C23", "RFS-3-C24",
+ // Plan 4 Task 2: what the creating release says, and where a rootfs row
+ // may run (internal/console/rootfs.go)
+ "RFS-4-C01", "RFS-4-C02", "RFS-4-C05", "RFS-4-C06", "RFS-4-C07", "RFS-4-C08",
}
func mustParseRootfsRecord(t *testing.T) []copyRow {
diff --git a/internal/console/rootfs.go b/internal/console/rootfs.go
new file mode 100644
index 000000000..f0b946b9d
--- /dev/null
+++ b/internal/console/rootfs.go
@@ -0,0 +1,181 @@
+package console
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "net/http"
+ "time"
+
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/status"
+)
+
+// The three questions every rootfs door asks (rootfs apps spec §5.0, §5.7;
+// Plan 4 Task 2): what the creating release says (rootfsHeadFor), whether a
+// placement is the account's own boxes (rootfsPlacementRefusal), and whether
+// a box there has passed its rootfs check (rootfsReadyRefusal). The console
+// asks for a clear message; the box's own refusal (Plan 2) is the one that
+// counts, and nothing here replaces it.
+
+// The refusals, one row of the copy deck each (RFS-4-C01, C02, C05 to C08).
+const (
+ // rootfsNotOwnBoxesMsg is RFS-4-C01, filled with the app. <name> and
+ // <fleet> stay as written: the user fills them in.
+ rootfsNotOwnBoxesMsg = "%s is a rootfs app, and a rootfs app runs only on boxes your account owns. a rootfs app is placed when it is made: create a new app with carlos apps create <name> --place fleet/<fleet> and ship to it"
+ // rootfsPoolMsg is RFS-4-C02, filled with the app.
+ rootfsPoolMsg = "%s is a rootfs app, and a rootfs app does not run in a dedicated pool yet. create the instance without a pool"
+ // rootfsFleetNotReadyMsg is RFS-4-C05, filled with the fleet's name.
+ rootfsFleetNotReadyMsg = "none of fleet %s's boxes can run a rootfs app yet. a box can once it runs a platform release with rootfs support, on the nested layout, with overlap deploys on, and has passed its rootfs check"
+ // rootfsRegionNotReadyMsg is RFS-4-C06, filled with the region's name.
+ rootfsRegionNotReadyMsg = "no box in %s can run a rootfs app yet. a box can once it runs a platform release with rootfs support, on the nested layout, with overlap deploys on, and has passed its rootfs check"
+ // rootfsReadyUnreadableMsg is RFS-4-C07.
+ rootfsReadyUnreadableMsg = "could not check which boxes can run a rootfs app. try again"
+ // rootfsReleasesUnreadableMsg is RFS-4-C08.
+ rootfsReleasesUnreadableMsg = "could not read this app's releases. try again"
+)
+
+// rootfsHead is what the release an instance would be created from says
+// about its runtime. Kind and hibernation are per app and fixed at the first
+// ship (§5.0), so any readable release of the app answers for all of them.
+type rootfsHead struct {
+ Rootfs bool // the creating release is a rootfs release
+ Hibernate bool // its manifest's opt-in (spec §5.0, R5)
+ Version string // the release it was read from
+ Unfixed bool // no release and no kind marker: no first ship has fixed the app's kind yet (Astra R2 finding 2); Rootfs is false
+}
+
+// rootfsHeadFor reads the channel's head and, when it names a version, that
+// manifest: a readable head answers alone, the same two reads
+// staticHeadRefusal makes. With no pointer, an empty version, or any pointer
+// or manifest read error, it falls back to release.EstablishedKind (the
+// release history, then the kind marker of a first ship still publishing),
+// so a head the console cannot read never decides binary by itself (Review
+// Focus 1). A history it cannot read refuses with C08 at 502.
+//
+// A binary or static app answers the zero rootfsHead, wherever the answer
+// came from: only a rootfs head carries a version and hibernation.
+func (s *Server) rootfsHeadFor(ctx context.Context, sqid, app, channel string) (rootfsHead, *doorRefusal) {
+ if s.cfg.Releases == nil {
+ return rootfsHead{}, &doorRefusal{http.StatusBadGateway, rootfsReleasesUnreadableMsg}
+ }
+ if ptr, err := release.Channel(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid, app, channel); err == nil && ptr != nil && ptr.Version != "" {
+ if m, err := release.GetManifest(ctx, s.cfg.Releases, sqid, app, ptr.Version); err == nil && m != nil {
+ if m.Kind != release.KindRootfs {
+ return rootfsHead{}, nil
+ }
+ return rootfsHead{Rootfs: true, Hibernate: m.Hibernate, Version: ptr.Version}, nil
+ }
+ }
+ info, err := release.EstablishedKind(ctx, s.cfg.Releases, sqid, app)
+ switch {
+ case err != nil:
+ log.Printf("console: rootfs head %s/%s: read the app's kind: %v", sqid, app, err)
+ return rootfsHead{}, &doorRefusal{http.StatusBadGateway, rootfsReleasesUnreadableMsg}
+ case info.Kind == "":
+ return rootfsHead{Unfixed: true}, nil
+ case info.Kind != release.KindRootfs:
+ return rootfsHead{}, nil
+ }
+ return rootfsHead{Rootfs: true, Hibernate: info.Hibernate, Version: info.Version}, nil
+}
+
+// rootfsPlacementRefusal is the ownership half of the box's placement
+// predicate (spec §5.7, host.OwnBoxAllowed, mirrored), read from the fleet
+// row the fleet owner record is written from (D7). Pools refuse first, on
+// every deployment, because Plan 3 D6 refuses a pooled rootfs record
+// whatever the deployment (D9). Then a single-tenant deployment allows any
+// box; a shared one allows only a fleet the account owns (ownsFleet, the
+// rule plans-caps already uses). A fleet row that cannot be read answers as
+// the place door does, 500 "could not check the fleet".
+func (s *Server) rootfsPlacementRefusal(reg consoleRegistry, acct *Account, app, placed, pool string) *doorRefusal {
+ if pool != "" {
+ return &doorRefusal{http.StatusConflict, fmt.Sprintf(rootfsPoolMsg, app)}
+ }
+ if s.cfg.DeploymentSingleTenant {
+ return nil
+ }
+ own, err := ownsFleet(reg, acct, placed)
+ if err != nil {
+ log.Printf("console: rootfs placement %s/%s: read fleet %q: %v", acct.Sqid, app, placed, err)
+ return &doorRefusal{http.StatusInternalServerError, "could not check the fleet"}
+ }
+ if !own {
+ return &doorRefusal{http.StatusConflict, fmt.Sprintf(rootfsNotOwnBoxesMsg, app)}
+ }
+ return nil
+}
+
+// rootfsReadyRefusal is the box-local half of the predicate
+// (host.RootfsBoxReady, as each box publishes it): one fresh box of the
+// placement that says rootfs_ready is enough. For a fleet the candidates are
+// its heartbeats whose label the registry lists as an active box of that
+// fleet, the same join the fleet page makes, so a detached box's heartbeat,
+// still fresh for a while, never counts. Otherwise they are the platform's
+// boxes whose region is region (the home is ""). Box snapshots carry no
+// pools, so on a single-tenant deployment a box serving dedicated pools only
+// still counts; the box's own refusal covers it.
+//
+// None ready: 409 C05 naming the fleet, or C06 naming the region. A read
+// that fails: 503 C07.
+func (s *Server) rootfsReadyRefusal(ctx context.Context, reg consoleRegistry, placed, region string) *doorRefusal {
+ unreadable := &doorRefusal{http.StatusServiceUnavailable, rootfsReadyUnreadableMsg}
+ if s.cfg.Releases == nil {
+ return unreadable
+ }
+ now := time.Now()
+ ready := func(b status.Box) bool { return !status.BoxStale(b, now, status.SnapshotPeriod) && boxRootfsReady(b) }
+ if fleet, ok := registry.FleetPlacement(placed); ok {
+ regBoxes, err := reg.ListFleetBoxes(fleet)
+ if err != nil {
+ log.Printf("console: rootfs ready: list fleet %s's boxes: %v", fleet, err)
+ return unreadable
+ }
+ active := map[string]bool{}
+ for _, b := range regBoxes {
+ if b.Status == "active" {
+ active[b.Label] = true
+ }
+ }
+ hbs, err := status.LoadBoxes(ctx, release.NewPrefixStore(s.cfg.Releases, "fleets/"+fleet+"/"))
+ if err != nil {
+ log.Printf("console: rootfs ready: load fleet %s's heartbeats: %v", fleet, err)
+ return unreadable
+ }
+ for _, b := range hbs {
+ if active[b.Label] && ready(b) {
+ return nil
+ }
+ }
+ return &doorRefusal{http.StatusConflict, fmt.Sprintf(rootfsFleetNotReadyMsg, fleet)}
+ }
+ hbs, err := status.LoadBoxes(ctx, s.cfg.Releases)
+ if err != nil {
+ log.Printf("console: rootfs ready: load the platform's heartbeats: %v", err)
+ return unreadable
+ }
+ for _, b := range hbs {
+ if s.homeRegionIn(b.Region) == region && ready(b) {
+ return nil
+ }
+ }
+ return &doorRefusal{http.StatusConflict, fmt.Sprintf(rootfsRegionNotReadyMsg, s.rootfsRegionName(ctx, region))}
+}
+
+// rootfsRegionName is a region as C06 names it: its place, the name the
+// create door's other region refusals give (hostsTargetRefusal), or the word
+// home for a home with no name configured, as offlineName says it.
+func (s *Server) rootfsRegionName(ctx context.Context, region string) string {
+ if name := s.placeOf(region, s.candsOrHome(ctx)); name != "" {
+ return name
+ }
+ return s.offlineName(region)
+}
+
+// boxRootfsReady is the one reader of a box's rootfs_ready (D2): the box
+// folds every box-local rule into it (claim control off, the nested layout,
+// the rootfs probe passed this boot, overlap swaps).
+func boxRootfsReady(b status.Box) bool {
+ return b.Metrics != nil && b.Metrics.RootfsReady
+}
diff --git a/internal/console/rootfs_test.go b/internal/console/rootfs_test.go
new file mode 100644
index 000000000..8ae3aee72
--- /dev/null
+++ b/internal/console/rootfs_test.go
@@ -0,0 +1,301 @@
+package console
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "net/http"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/geo"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/status"
+)
+
+// The three questions every rootfs door asks (rootfs apps Plan 4 Task 2):
+// what the creating release says, whether a placement is the account's own
+// boxes, and whether a box there has passed its rootfs check. App shop in
+// account bab, fleets home and away, hosts under example.com.
+
+// shipRootfsRelease ships a rootfs release of app (Plan 1's shape).
+func shipRootfsRelease(t *testing.T, fx *consoleFixture, app, version string, hibernate bool) {
+ t.Helper()
+ m := release.Manifest{
+ Schema: 1, App: app, Version: version, Kind: release.KindRootfs, BuiltAt: "2026-10-24T10:00:00Z",
+ Artifacts: map[string]release.Artifact{release.RootfsArtifactKey: {File: release.RootfsArtifactFile}},
+ Processes: map[string]release.Process{release.ProcessWeb: {Command: []string{"/rails/bin/web"}}},
+ Hibernate: hibernate,
+ }
+ if err := release.Ship(context.Background(), fx.rel, fx.sqid, m,
+ map[string][]byte{release.RootfsArtifactKey: []byte("hsqs" + version)}); err != nil {
+ t.Fatal(err)
+ }
+ fx.forgetFrame(app)
+}
+
+// writeFleetBox writes one heartbeat for a box of fleet (fleet == "" is a
+// platform box in region).
+func writeFleetBox(t *testing.T, fx *consoleFixture, fleet, label, region string, ready bool, at time.Time) {
+ t.Helper()
+ var s release.Store = fx.rel
+ if fleet != "" {
+ s = release.NewPrefixStore(fx.rel, "fleets/"+fleet+"/")
+ }
+ b := status.Box{GeneratedAt: at, Label: label, Region: region,
+ Metrics: &status.BoxMetrics{Layout: &status.LayoutReport{Mode: "nested"}, RootfsReady: ready}}
+ if err := status.WriteBox(context.Background(), s, b); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// registerFleetBox adds label to fleet's box list in the registry, active.
+func registerFleetBox(t *testing.T, reg *registry.Registry, fleet, label string) {
+ t.Helper()
+ if err := reg.AddFleetBox(registry.FleetBox{Fleet: fleet, Label: label,
+ TokenHash: strings.Repeat("a", 64), Status: "active", AddedAt: time.Now().Unix()}); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func refStatus(ref *doorRefusal) int {
+ if ref == nil {
+ return 0
+ }
+ return ref.Status
+}
+
+// rootfsDoorWorld is a console with the app shop in bab, a token, the
+// registry, the owned fleets home and away (through the real door), and a
+// fleet theirs that belongs to another account.
+func rootfsDoorWorld(t *testing.T, code string) (*consoleFixture, *registry.Registry) {
+ t.Helper()
+ fx, token := fleetFixture(t, code)
+ if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ reg := openTestReg(t, fx)
+ t.Cleanup(func() { reg.Close() })
+ for _, f := range []string{"home", "away"} {
+ if st, body := postJSON(t, fleetsURL(fx, fx.sqid)+"/new",
+ map[string]string{"name": f, "bucket": f + "-fleet-data"}, token); st != http.StatusOK {
+ t.Fatalf("create fleet %s = %d %v", f, st, body)
+ }
+ }
+ if _, err := reg.CreateFleet(registry.Fleet{Name: "theirs", Account: "zzz", Bucket: "theirs-data"}); err != nil {
+ t.Fatal(err)
+ }
+ return fx, reg
+}
+
+// fleetFailReg is the registry with GetFleet and ListFleetBoxes failing.
+type fleetFailReg struct{ consoleRegistry }
+
+func (fleetFailReg) GetFleet(string) (*registry.Fleet, error) {
+ return nil, errors.New("injected fleet read failure")
+}
+
+func (fleetFailReg) ListFleetBoxes(string) ([]registry.FleetBox, error) {
+ return nil, errors.New("injected fleet box list failure")
+}
+
+func TestRootfsHeadReadsTheChannelHead(t *testing.T) {
+ fx, _ := rootfsDoorWorld(t, "code-rfs-head")
+ shipRootfsRelease(t, fx, "shop", "r1", true)
+ seedChannel(t, fx, "shop", "edge", "r1")
+ head, ref := fx.srv.rootfsHeadFor(context.Background(), fx.sqid, "shop", "edge")
+ if ref != nil || head != (rootfsHead{Rootfs: true, Hibernate: true, Version: "r1"}) {
+ t.Fatalf("head %+v, %v", head, ref)
+ }
+}
+
+// Review Focus 1: a channel pointer the console cannot read or verify never
+// decides binary for an app whose history holds rootfs releases.
+func TestRootfsHeadFallsBackToHistory(t *testing.T) {
+ fx, _ := rootfsDoorWorld(t, "code-rfs-history")
+ shipRootfsRelease(t, fx, "shop", "r1", false)
+ // No pointer at all, then a pointer the console cannot verify.
+ for _, ch := range []string{"edge", "broken"} {
+ if ch == "broken" {
+ if _, err := fx.rel.Put(context.Background(), release.ChannelKey(fx.sqid, "shop", "broken"), []byte(`{"payload":"x","sig":"y"}`), ""); err != nil {
+ t.Fatal(err)
+ }
+ }
+ head, ref := fx.srv.rootfsHeadFor(context.Background(), fx.sqid, "shop", ch)
+ if ref != nil || head != (rootfsHead{Rootfs: true, Version: "r1"}) {
+ t.Fatalf("%s: head %+v, %v; want rootfs from history", ch, head, ref)
+ }
+ }
+ // A pointer whose manifest cannot be read falls back too, and the
+ // history read then fails closed: never binary.
+ seedChannel(t, fx, "shop", "edge", "r1")
+ fx.srv.cfg.Releases = &failGetStore{Store: fx.rel, key: release.ManifestKey(fx.sqid, "shop", "r1")}
+ if head, ref := fx.srv.rootfsHeadFor(context.Background(), fx.sqid, "shop", "edge"); refStatus(ref) != http.StatusBadGateway || head != (rootfsHead{}) {
+ t.Fatalf("unreadable head manifest: head %+v, %v; want 502", head, ref)
+ }
+}
+
+func TestRootfsHeadIsBinaryForBinaryAndNewApps(t *testing.T) {
+ fx, _ := rootfsDoorWorld(t, "code-rfs-binary")
+ // kass is binary: its readable head, and its history with no pointer.
+ for _, ch := range []string{"stable", "nosuch"} {
+ if head, ref := fx.srv.rootfsHeadFor(context.Background(), fx.sqid, "kass", ch); ref != nil || head != (rootfsHead{}) {
+ t.Errorf("kass %s: head %+v, %v; want binary", ch, head, ref)
+ }
+ }
+ // shop has no release and no marker: no first ship has fixed its kind.
+ if head, ref := fx.srv.rootfsHeadFor(context.Background(), fx.sqid, "shop", "edge"); ref != nil || head != (rootfsHead{Unfixed: true}) {
+ t.Errorf("shop: head %+v, %v; want unfixed", head, ref)
+ }
+}
+
+// Astra R2 finding 2: a first ship that has written its kind marker but not
+// its manifest already decides.
+func TestRootfsHeadReadsAnUnpublishedFirstShip(t *testing.T) {
+ fx, _ := rootfsDoorWorld(t, "code-rfs-marker")
+ m := release.Manifest{Schema: 1, App: "shop", Version: "r1", Kind: release.KindRootfs, Hibernate: true,
+ Artifacts: map[string]release.Artifact{release.RootfsArtifactKey: {File: release.RootfsArtifactFile, SHA256: strings.Repeat("a", 64), Size: 1}},
+ Processes: map[string]release.Process{release.ProcessWeb: {Command: []string{"/rails/bin/web"}}}}
+ if err := release.EstablishFirstKind(context.Background(), fx.rel, fx.sqid, &m); err != nil {
+ t.Fatal(err)
+ }
+ head, ref := fx.srv.rootfsHeadFor(context.Background(), fx.sqid, "shop", "edge")
+ if ref != nil || head != (rootfsHead{Rootfs: true, Hibernate: true, Version: "r1"}) {
+ t.Fatalf("head %+v, %v", head, ref)
+ }
+}
+
+func TestRootfsHeadRefusesWhenHistoryIsUnreadable(t *testing.T) {
+ fx, _ := rootfsDoorWorld(t, "code-rfs-unreadable")
+ fx.srv.cfg.Releases = listFailStore{fx.rel}
+ head, ref := fx.srv.rootfsHeadFor(context.Background(), fx.sqid, "shop", "edge")
+ if refStatus(ref) != http.StatusBadGateway || ref.Msg != rootfsReleasesUnreadableMsg || head != (rootfsHead{}) {
+ t.Fatalf("head %+v, %v; want 502 C08", head, ref)
+ }
+}
+
+func TestRootfsPlacementRefusal(t *testing.T) {
+ fx, reg := rootfsDoorWorld(t, "code-rfs-place")
+ acct := fixtureAccount(fx)
+ notOwn := fmt.Sprintf(rootfsNotOwnBoxesMsg, "shop")
+ pooled := fmt.Sprintf(rootfsPoolMsg, "shop")
+ for _, tc := range []struct {
+ single bool
+ placed, pool string
+ status int
+ msg string
+ }{
+ {false, "fleet/home", "", 0, ""},
+ {false, "fleet/away", "", 0, ""},
+ {false, "", "", http.StatusConflict, notOwn},
+ {false, "fleet/theirs", "", http.StatusConflict, notOwn}, // another account's fleet
+ {false, "fleet/nosuch", "", http.StatusConflict, notOwn},
+ {false, "uk", "", http.StatusConflict, notOwn},
+ {false, "fleet/home", "gold", http.StatusConflict, pooled}, // pools never in v1
+ {true, "", "", 0, ""},
+ {true, "fleet/theirs", "", 0, ""},
+ {true, "", "gold", http.StatusConflict, pooled}, // Plan 3 D6 refuses a pooled rootfs record on every deployment (D9)
+ } {
+ fx.srv.cfg.DeploymentSingleTenant = tc.single
+ ref := fx.srv.rootfsPlacementRefusal(reg, acct, "shop", tc.placed, tc.pool)
+ if got := refStatus(ref); got != tc.status || (ref != nil && ref.Msg != tc.msg) {
+ t.Errorf("%+v: got %v", tc, ref)
+ }
+ }
+ // A fleet row that cannot be read answers as the place door does.
+ fx.srv.cfg.DeploymentSingleTenant = false
+ ref := fx.srv.rootfsPlacementRefusal(fleetFailReg{reg}, acct, "shop", "fleet/home", "")
+ if refStatus(ref) != http.StatusInternalServerError || ref.Msg != "could not check the fleet" {
+ t.Errorf("GetFleet error: %v", ref)
+ }
+}
+
+// Review Focus 3: a ready box that is stale, detached, on another fleet of
+// the same account, or never registered to the fleet does not count.
+func TestRootfsReadyCountsOnlyFreshBoxesOfThePlacement(t *testing.T) {
+ fx, reg := rootfsDoorWorld(t, "code-rfs-ready")
+ for _, l := range []string{"pi-1", "pi-2", "pi-4"} {
+ registerFleetBox(t, reg, "home", l)
+ }
+ registerFleetBox(t, reg, "away", "pi-3")
+ if err := reg.SetFleetBoxStatus("home", "pi-4", "detached"); err != nil {
+ t.Fatal(err)
+ }
+ now := time.Now()
+ writeFleetBox(t, fx, "home", "pi-1", "", false, now) // fresh, not ready
+ writeFleetBox(t, fx, "home", "pi-2", "", true, now.Add(-2*time.Hour)) // ready, stale
+ writeFleetBox(t, fx, "away", "pi-3", "", true, now) // ready, another fleet
+ writeFleetBox(t, fx, "home", "pi-4", "", true, now) // ready, detached
+ writeFleetBox(t, fx, "home", "pi-5", "", true, now) // ready, never registered
+ writeFleetBox(t, fx, "", "pi-6", "", true, now) // ready, a platform box
+ want := fmt.Sprintf(rootfsFleetNotReadyMsg, "home")
+ if ref := fx.srv.rootfsReadyRefusal(context.Background(), reg, "fleet/home", ""); refStatus(ref) != http.StatusConflict || ref.Msg != want {
+ t.Fatalf("not ready: %v", ref)
+ }
+ writeFleetBox(t, fx, "home", "pi-1", "", true, now)
+ if ref := fx.srv.rootfsReadyRefusal(context.Background(), reg, "fleet/home", ""); ref != nil {
+ t.Fatalf("ready: %v", ref)
+ }
+ // A heartbeat with no metrics is not ready.
+ if boxRootfsReady(status.Box{Label: "pi-1"}) {
+ t.Error("a box with no metrics read as ready")
+ }
+}
+
+func TestRootfsReadyOnASingleTenantRegion(t *testing.T) {
+ fx, reg := rootfsDoorWorld(t, "code-rfs-region")
+ fx.srv.cfg.DeploymentSingleTenant = true
+ fx.srv.cfg.HomeRegion = "ie"
+ now := time.Now()
+ writeFleetBox(t, fx, "", "box-1", "ie", false, now) // home, fresh, not ready
+ writeFleetBox(t, fx, "", "box-2", "", true, now.Add(-2*time.Hour)) // home, ready, stale
+ writeFleetBox(t, fx, "", "box-3", "uk", true, now) // uk, ready
+ writeFleetBox(t, fx, "", "box-4", "us", false, now) // us, not ready
+ writeFleetBox(t, fx, "home", "pi-1", "", true, now) // a fleet box: not the platform's
+ registerFleetBox(t, reg, "home", "pi-1")
+ // Row 2.8: C06 names the region by its place, as the create door's
+ // other region refusals do, never by its code.
+ ref := fx.srv.rootfsReadyRefusal(context.Background(), reg, "", "")
+ if refStatus(ref) != http.StatusConflict || ref.Msg != fmt.Sprintf(rootfsRegionNotReadyMsg, "ie") {
+ t.Fatalf("home with no edges: %v", ref)
+ }
+ // With no home name and no edges the sentence still names a place.
+ fx.srv.cfg.HomeRegion = ""
+ if ref := fx.srv.rootfsReadyRefusal(context.Background(), reg, "", ""); refStatus(ref) != http.StatusConflict ||
+ ref.Msg != fmt.Sprintf(rootfsRegionNotReadyMsg, "home") {
+ t.Fatalf("unnamed home: %v", ref)
+ }
+ fx.srv.cfg.HomeRegion = "ie"
+ setEdges(t, fx, map[string]string{"edge-ie": edgeJSON("edge-ie", "5.6.7.8", "eu-west-1", "", eligibleBox)})
+ place := geo.PlaceName("eu-west-1", "")
+ if place == "" || place == "ie" {
+ t.Fatalf("no place for eu-west-1: %q", place)
+ }
+ ref = fx.srv.rootfsReadyRefusal(context.Background(), reg, "", "")
+ if want := fmt.Sprintf(rootfsRegionNotReadyMsg, place); refStatus(ref) != http.StatusConflict || ref.Msg != want {
+ t.Fatalf("home: %v, want %q", ref, want)
+ }
+ if ref := fx.srv.rootfsReadyRefusal(context.Background(), reg, "", "uk"); ref != nil {
+ t.Fatalf("uk: %v", ref)
+ }
+ if ref := fx.srv.rootfsReadyRefusal(context.Background(), reg, "", "us"); refStatus(ref) != http.StatusConflict {
+ t.Fatalf("us: %v", ref)
+ }
+}
+
+func TestRootfsReadyRefusesWhenItCannotLook(t *testing.T) {
+ fx, reg := rootfsDoorWorld(t, "code-rfs-ready-err")
+ registerFleetBox(t, reg, "home", "pi-1")
+ writeFleetBox(t, fx, "home", "pi-1", "", true, time.Now())
+ if ref := fx.srv.rootfsReadyRefusal(context.Background(), fleetFailReg{reg}, "fleet/home", ""); refStatus(ref) != http.StatusServiceUnavailable || ref.Msg != rootfsReadyUnreadableMsg {
+ t.Errorf("box list error: %v", ref)
+ }
+ fx.srv.cfg.Releases = listFailStore{fx.rel}
+ for _, placed := range []string{"fleet/home", ""} {
+ if ref := fx.srv.rootfsReadyRefusal(context.Background(), reg, placed, ""); refStatus(ref) != http.StatusServiceUnavailable || ref.Msg != rootfsReadyUnreadableMsg {
+ t.Errorf("%q heartbeat error: %v", placed, ref)
+ }
+ }
+}