Keep what an adopted node reports holding, the firewall it found and what is reachable on it (hq ADR 0100)
This commit is contained in:
@@ -175,3 +175,46 @@ func TestAFailureDoesNotBecomeTheAccountOfWhatTheMachineHolds(t *testing.T) {
|
||||
t.Fatalf("a partial report replaced the account of what the machine holds: %v", owned)
|
||||
}
|
||||
}
|
||||
|
||||
// novox/hq ADR 0100: what an adopted node holds, the firewall it found and what is reachable on it
|
||||
// are kept from the report that carries them, and a bare word that the node is there wipes none.
|
||||
func TestWhatAnAdoptedNodeHoldsIsKeptAndAnAliveWordDoesNotWipeIt(t *testing.T) {
|
||||
inv, _, _ := heardFrom(t, link.Report{
|
||||
Node: "anchor", Applied: []string{"hello-web.served"}, Firewall: "ufw",
|
||||
Held: []link.Held{{ID: "hello-web.page", Module: "hello-web", Kind: "file",
|
||||
Target: "/var/lib/hello-web/index.html", Changed: "rewritten", Kept: "/var/lib/mesh/kept/x"}},
|
||||
Reachable: []link.Reach{{Protocol: "tcp", Address: "0.0.0.0", Port: 8080, By: "hello-web",
|
||||
Published: true, ContainerPort: 80}},
|
||||
})
|
||||
ctx := context.Background()
|
||||
check := func(when string) {
|
||||
t.Helper()
|
||||
got, err := inv.AdoptionOf(ctx, "anchor")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Firewall != "ufw" || len(got.Held) != 1 || got.Held[0].Changed != "rewritten" ||
|
||||
len(got.Reachable) != 1 || got.Reachable[0].ContainerPort != 80 || got.At.IsZero() {
|
||||
t.Fatalf("%s: what the node said is not what was kept: %+v", when, got)
|
||||
}
|
||||
}
|
||||
check("after the report")
|
||||
|
||||
if err := (link.Enrolment{Inventory: inv}).Heard(ctx, link.Report{Node: "anchor"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check("after an alive word")
|
||||
|
||||
// A reconcile report carrying only adoption is recorded, though it applied nothing.
|
||||
if err := (link.Enrolment{Inventory: inv}).Heard(ctx, link.Report{Node: "anchor",
|
||||
Firewall: "ufw"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := inv.AdoptionOf(ctx, "anchor")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got.Held) != 0 || got.Firewall != "ufw" {
|
||||
t.Fatalf("a report from an adopted node holding nothing did not empty held: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user