hostops: backfill tests assert discovery destinations and legacy holder repair (Plan 5 Tasks 5-6 review minors)
Co-Authored-By: Codex <noreply@openai.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+51
−0
internal/hostops/backfill_test.go+51 −0
CI passed — run details
diff --git a/internal/hostops/backfill_test.go b/internal/hostops/backfill_test.go| index 878cb53a2..32ca43ff7 100644 |
| --- a/internal/hostops/backfill_test.go |
| +++ b/internal/hostops/backfill_test.go |
| @@ -8,6 +8,7 @@ import ( |
| "encoding/hex" |
| "encoding/json" |
| "errors" |
| + "reflect" |
| "strings" |
| "testing" |
| "time" |
| @@ -19,6 +20,15 @@ import ( |
| ) |
| func TestReconcileFrozenBackfillAndQuarantine(t *testing.T) { |
| + testReconcileFrozenBackfill(t, false) |
| +} |
| + |
| +func TestReconcileFrozenBackfillRepairsLegacyHolder(t *testing.T) { |
| + testReconcileFrozenBackfill(t, true) |
| +} |
| + |
| +func testReconcileFrozenBackfill(t *testing.T, legacy bool) { |
| + t.Helper() |
| ctx := context.Background() |
| f := newFixture(t) |
| pub, key, err := ed25519.GenerateKey(rand.Reader) |
| @@ -86,6 +96,23 @@ func TestReconcileFrozenBackfillAndQuarantine(t *testing.T) { |
| if err != nil || !obs.Absent { |
| t.Fatal(obs, err) |
| } |
| + var prior hostclaim.Observed |
| + if legacy { |
| + nh := r.Holder |
| + nh.Acquisition = "" |
| + nh.Region = "ie" |
| + prior, err = hostclaim.Update(ctx, f.store, obs, func(claim *hostclaim.Claim) error { |
| + if err := hostclaim.Adopt(nh, "box-a", []string{"us"}, []string{"box-b"}, "legacy-discovery", f.c.NewID)(claim); err != nil { |
| + return err |
| + } |
| + claim.Holder.Stamp = 17 |
| + claim.Holder.Generation = "legacy-generation" |
| + return nil |
| + }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| p := BackfillPlan{V: 1, ID: "backfill", Phase: "adopting", DirectoryRevision: 1, CreatedAt: f.now, Reports: map[string]string{}, Hosts: map[string]BackfillHost{r.Holder.Host: {Key: r.Holder.Key, ETag: r.ETag, Acquisition: "ownership-acquisition", Region: "ie", Box: "box-a"}}} |
| for ref, b := range roster.Boxes { |
| report := CensusReport{Box: ref, Enrollment: b.Enrollment, BootID: "boot", Reservation: p.ID, DirectoryRevision: 1, CapturedAt: f.now, Complete: true, Installations: []CensusInstallation{}} |
| @@ -165,6 +192,30 @@ func TestReconcileFrozenBackfillAndQuarantine(t *testing.T) { |
| if obs.Absent || obs.Claim.Holder.Acquisition != "ownership-acquisition" || obs.Claim.Op.Exec != "box-a" || obs.Claim.Touched.Complete || len(obs.Claim.Obligations) != 2 { |
| t.Fatalf("bad backfill: %+v", obs.Claim) |
| } |
| + wantDestinations := map[string]hostclaim.Obligation{ |
| + "park-replica": {Region: "us", Owner: "region:us"}, |
| + "park-local": {Box: "box-b", Owner: "box:box-b"}, |
| + } |
| + for _, obligation := range obs.Claim.Obligations { |
| + want, ok := wantDestinations[obligation.Kind] |
| + if !ok || obligation.Region != want.Region || obligation.Box != want.Box || obligation.Owner != want.Owner { |
| + t.Fatalf("wrong discovery destination: %+v; want %+v", obligation, want) |
| + } |
| + delete(wantDestinations, obligation.Kind) |
| + } |
| + if len(wantDestinations) != 0 { |
| + t.Fatalf("missing discovery destinations: %+v", wantDestinations) |
| + } |
| + if legacy { |
| + want := *prior.Claim |
| + holder := *want.Holder |
| + holder.Acquisition = "ownership-acquisition" |
| + want.Holder = &holder |
| + want.Gen++ |
| + if obs.ETag == prior.ETag || !reflect.DeepEqual(obs.Claim, &want) { |
| + t.Fatalf("legacy repair changed more than acquisition and claim generation: got %+v (holder %+v), want %+v (holder %+v)", obs.Claim, obs.Claim.Holder, &want, want.Holder) |
| + } |
| + } |
| before := obs.ETag |
| if err = c.ReconcileClaims(ctx); err != nil { |
| t.Fatal(err) |