Node-engine: an unanswered requirement costs its consumer, not the machine (A-452) #232
@@ -201,7 +201,9 @@ func TestAGrantIsCreatedForEachCredentialMadeForAConsumer(t *testing.T) {
|
||||
}
|
||||
// A consumer whose set does not resolve is skipped, not fatal.
|
||||
nodeOf(t, &in, "laptop").Assigned = append(nodeOf(t, &in, "laptop").Assigned, "files")
|
||||
in.Catalogue["files"] = catalogue.Manifest{Module: "files", Version: "1", Requires: []string{"s3-bucket", "nothing-gives-this"}}
|
||||
in.Catalogue["files"] = catalogue.Manifest{Module: "files", Version: "1", Requires: []string{"s3-bucket", "two-give-this"}}
|
||||
in.Catalogue["giver-a"] = catalogue.Manifest{Module: "giver-a", Version: "1", Provides: catalogue.Offers("two-give-this")}
|
||||
in.Catalogue["giver-b"] = catalogue.Manifest{Module: "giver-b", Version: "1", Provides: catalogue.Offers("two-give-this")}
|
||||
if got, err := Render(in, "anchor", Foreseeing); err != nil || len(got.Rendering.Grants) != 0 {
|
||||
t.Errorf("a consumer that does not resolve: %v %+v", err, got.Rendering.Grants)
|
||||
}
|
||||
|
||||
@@ -675,7 +675,9 @@ func otherNodeNotResolvedIsNamed(t *testing.T) {
|
||||
given[n] = &p
|
||||
}
|
||||
a := Answer(ctx, b, Mesh{}, Scope{Node: "n1", Assignments: given}, map[string]string{"cons": "src2:" + strings.Repeat("1", 64)}, nil, "p-h1", 1)
|
||||
if a.Verdict != nodeengine.CandidateAnswerVerdictRefused || !strings.Contains(a.Refused, "prov on n2 lacks container-runtime") {
|
||||
// cons is held for the requirement nothing answers (A-452) and its why names n2's provider.
|
||||
if a.Verdict != nodeengine.CandidateAnswerVerdictRefused || len(a.Refusals) != 1 || a.Refusals[0].Module != "cons" ||
|
||||
!strings.Contains(a.Refusals[0].Why, "prov on n2 lacks container-runtime") {
|
||||
t.Errorf("a refusal for want of n2's provider = %+v", a)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,17 @@ func aNode(t *testing.T, manifests ...string) (*bus, map[string]string) {
|
||||
// refusal can be of the held module's stub (node-tools held, then "its build produced 0 bundle(s)", its own why unsaid).
|
||||
func aNodeRefusedWholeSaysWhatItHeld(t *testing.T) {
|
||||
refused := `{"module":"power","version":"1","items":[{"collection":"contribution:node-bar:block","attributes":{"shows":"state"},"template":"files/a"}]}`
|
||||
needs := `{"module":"lamp","version":"1","requires":["nothing-provides-this"]}`
|
||||
b, fps := aNode(t, refused, needs)
|
||||
needs := `{"module":"lamp","version":"1","requires":["two-provide-this"]}`
|
||||
giverA := `{"module":"giver-a","version":"1","provides":[{"name":"two-provide-this"}]}`
|
||||
giverB := `{"module":"giver-b","version":"1","provides":[{"name":"two-provide-this"}]}`
|
||||
b, fps := aNode(t, refused, needs, giverA, giverB)
|
||||
// The two givers are in the catalogue and placed on no node, so lamp's requirement has two answers and nobody chose.
|
||||
placed := b.assignments["n1"]
|
||||
placed.Modules = placed.Modules[:2]
|
||||
b.assignments["n1"] = placed
|
||||
refuse(b, "power", `"shows" is none of them`)
|
||||
_, _, held, err := Compose(context.Background(), b, Mesh{}, Scope{Node: "n1"}, fps)
|
||||
if err == nil || !strings.Contains(err.Error(), "nothing provides") || !strings.Contains(err.Error(), `held before: power: `) ||
|
||||
if err == nil || !strings.Contains(err.Error(), "choose one") || !strings.Contains(err.Error(), `held before: power: `) ||
|
||||
!strings.Contains(err.Error(), `"shows" is none of them`) {
|
||||
t.Errorf("the node refused whole with %v (held %v), want lamp's refusal and power held before, with its why", err, held)
|
||||
}
|
||||
|
||||
@@ -11,12 +11,14 @@ import (
|
||||
|
||||
// fourOnTheNetwork is aMesh and two more machines on the private network at the site `there`: `ace`, dialled at
|
||||
// ace.example:51820, at 10.77.0.3, and `box`, behind no endpoint, at 10.77.0.4. A module `office` requires
|
||||
// `document-server`, which nothing in the catalogue provides: the shape of issue 1833 (nextcloud on the hub wanting a
|
||||
// document server nobody offered).
|
||||
// `document-server`, which two modules of the catalogue provide and nobody chose: a refusal of the node's own set, as
|
||||
// issue 1833 was (nextcloud on the hub wanting a document server; an unanswered requirement now costs only its consumer, A-452).
|
||||
func fourOnTheNetwork(t *testing.T) Input {
|
||||
t.Helper()
|
||||
in := aMesh(t)
|
||||
in.Catalogue["office"] = catalogue.Manifest{Module: "office", Version: "1", Requires: []string{"document-server"}}
|
||||
in.Catalogue["docs-a"] = catalogue.Manifest{Module: "docs-a", Version: "1", Provides: catalogue.Offers("document-server")}
|
||||
in.Catalogue["docs-b"] = catalogue.Manifest{Module: "docs-b", Version: "1", Provides: catalogue.Offers("document-server")}
|
||||
caps := map[string]bool{"container-runtime": true, "wireguard": true, "systemd": true}
|
||||
in.Nodes = append(in.Nodes,
|
||||
Node{Name: "ace", Place: Place{Key: keyOf(t, "ace"), Endpoint: "ace.example:51820", Site: "there", Address: "10.77.0.3"},
|
||||
@@ -26,7 +28,7 @@ func fourOnTheNetwork(t *testing.T) Input {
|
||||
return in
|
||||
}
|
||||
|
||||
// unresolvableBy makes one machine's own set fail to resolve: it is also given `office`, whose requirement nothing provides.
|
||||
// unresolvableBy makes one machine's own set fail to resolve: it is also given `office`, whose requirement two modules provide.
|
||||
func unresolvableBy(t *testing.T, in *Input, name string) {
|
||||
t.Helper()
|
||||
n := nodeOf(t, in, name)
|
||||
@@ -70,7 +72,7 @@ func TestOneMachineThatDoesNotResolveIsRefusedAlone(t *testing.T) {
|
||||
if err == nil || !IsUnresolvable(err) {
|
||||
t.Fatalf("the machine that does not resolve is not refused as its own set failing: %v", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), `nothing provides "document-server", wanted by office`) {
|
||||
if !strings.Contains(err.Error(), `"document-server" is wanted by office and 2 modules provide it`) {
|
||||
t.Errorf("the refusal does not name what could not be resolved: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +181,22 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
absent[want] = true
|
||||
reported[want] = true
|
||||
}
|
||||
// A requirement nothing answers costs the modules that want it, not the machine (A-452, ADR 0636 §3): said once per name,
|
||||
// each consumer is held after the walk, when the set is known.
|
||||
// The value is the remedy the mesh-wide refusal adds, empty for a requirement nothing on the node answers.
|
||||
unanswered := map[string]string{}
|
||||
var unansweredOrder []string
|
||||
holdWhenUnanswered := func(want, remedy string) {
|
||||
if !wantedHard(want) && wantedOptionally(want) {
|
||||
// Only optional consumers: left absent, never held (ADR 0330 §3).
|
||||
leaveAbsent(want)
|
||||
return
|
||||
}
|
||||
if _, ok := unanswered[want]; !ok {
|
||||
unansweredOrder = append(unansweredOrder, want)
|
||||
}
|
||||
unanswered[want] = remedy
|
||||
}
|
||||
|
||||
for {
|
||||
if len(queue) == 0 {
|
||||
@@ -373,9 +389,8 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
} else if len(answers) > 1 {
|
||||
remedy = "— assign one of these to a node: " + strings.Join(answers, ", ")
|
||||
}
|
||||
problems = append(problems, fmt.Sprintf(
|
||||
"nothing in this mesh provides %q, wanted by %s %s",
|
||||
want, because[want], remedy))
|
||||
// Not answered on the node nor in the rest of the mesh: costs its consumers only (A-452).
|
||||
holdWhenUnanswered(want, remedy)
|
||||
case len(where) == 1:
|
||||
if c, pinned := world.Pinned[want]; pinned && !chosenMatches(c, where[0]) {
|
||||
// One provider, and it is not the one this machine was told to use. Silently
|
||||
@@ -483,8 +498,7 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
continue
|
||||
}
|
||||
reported[want] = true
|
||||
problems = append(problems, fmt.Sprintf(
|
||||
"nothing provides %q, wanted by %s", want, because[want]))
|
||||
holdWhenUnanswered(want, "")
|
||||
continue
|
||||
case 1:
|
||||
// No choice to make, so none is made. This is the case that lets `install i3` bring
|
||||
@@ -591,14 +605,17 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
resolution := mcat.Resolution{Node: node.Name, At: node.At, PublicDomain: node.PublicDomain,
|
||||
Account: node.Account, AccountHome: node.AccountHome, AgentAccount: node.AgentAccount,
|
||||
AgentAccountHome: node.AgentAccountHome, Capabilities: node.Capabilities,
|
||||
Because: because, Needs: needs, Unhostable: unhostable, Kept: kept,
|
||||
Absent: absentOf(absent, order, catalogue)}
|
||||
Because: because, Needs: needs, Unhostable: unhostable, Kept: kept}
|
||||
for _, n := range providersFirst(order, catalogue) {
|
||||
resolution.Modules = append(resolution.Modules, catalogue[n])
|
||||
}
|
||||
|
||||
problems = append(problems, checkCapabilities(resolution.Modules, node)...)
|
||||
claims, held := holdClaims(resolution.Modules, node, elsewhere, world.Holdings)
|
||||
held, unheld := holdUnanswered(resolution.Modules, unansweredOrder, unanswered, because, held, absent)
|
||||
// Listed after the holding: an optional consumer of a requirement nothing answers is left absent there (ADR 0330 §3, §7).
|
||||
resolution.Absent = absentOf(absent, order, catalogue)
|
||||
problems = append(problems, unheld...)
|
||||
problems = append(problems, checkResources(resolution.Modules)...)
|
||||
resolution.Claims = claims
|
||||
|
||||
@@ -680,6 +697,58 @@ func checkCapabilities(modules []mcat.Manifest, node mcat.Node) []string {
|
||||
return problems
|
||||
}
|
||||
|
||||
// unansweredWords is why a consumer is held for a requirement nothing answers, naming the provision.
|
||||
func unansweredWords(want, consumer, remedy string) string {
|
||||
if remedy == "" {
|
||||
return fmt.Sprintf("nothing provides %q, wanted by %s", want, consumer)
|
||||
}
|
||||
return fmt.Sprintf("nothing in this mesh provides %q, wanted by %s %s", want, consumer, remedy)
|
||||
}
|
||||
|
||||
// holdUnanswered holds each module of the set that wants a requirement nothing answers, with the words "nothing provides" naming the
|
||||
// provision (A-452): it stays in the set, so what it provides still counts for the others. A requirement none of the set's modules
|
||||
// wants (an assigned name the catalogue does not know) has no consumer to hold and comes back as a problem of the node; so does a
|
||||
// set whose every module is held, since then nothing could be composed.
|
||||
func holdUnanswered(modules []mcat.Manifest, unanswered []string, remedies map[string]string, because map[string]string, held map[string]string, absent map[string]bool) (map[string]string, []string) {
|
||||
var problems []string
|
||||
for _, want := range unanswered {
|
||||
found := false
|
||||
for _, m := range modules {
|
||||
wants := false
|
||||
for _, w := range m.Wants() {
|
||||
if w == want {
|
||||
wants = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !wants {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if m.IsOptional(want) {
|
||||
// Optional for this module: not held, left absent and listed (ADR 0330 §3, §7).
|
||||
absent[want] = true
|
||||
continue
|
||||
}
|
||||
if held == nil {
|
||||
held = map[string]string{}
|
||||
}
|
||||
why := unansweredWords(want, m.Module, remedies[want])
|
||||
if prior, ok := held[m.Module]; ok {
|
||||
why = prior + "; " + why
|
||||
}
|
||||
held[m.Module] = why
|
||||
}
|
||||
if !found {
|
||||
problems = append(problems, unansweredWords(want, because[want], remedies[want]))
|
||||
}
|
||||
}
|
||||
if len(unanswered) > 0 && len(held) >= len(modules) {
|
||||
problems = append(problems, "no module of the node could be composed: every one is held")
|
||||
}
|
||||
return held, problems
|
||||
}
|
||||
|
||||
// holdClaims refuses two modules holding one singular thing, within this node's own set and against what is held elsewhere for
|
||||
// the wider scopes: the claims that hold, and for each module that cannot hold what it claims, why (every reason, joined).
|
||||
func holdClaims(modules []mcat.Manifest, node mcat.Node, elsewhere []mcat.Held, holdings []mcat.Held) ([]mcat.Held, map[string]string) {
|
||||
|
||||
@@ -53,31 +53,75 @@ func TestARequirementWithOneAnswerIsTakenSilently(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestARequirementWithSeveralAnswersIsRefusedAndNamed(t *testing.T) {
|
||||
// The mesh does not pick. A default would be a choice made for somebody who finds out later,
|
||||
// and naming the candidates is the whole remedy.
|
||||
_, err := Resolve(shelf(
|
||||
mod("editor", nil, []string{"shell"}, nil),
|
||||
mod("bash", []string{"shell"}, nil, nil),
|
||||
mod("zsh", []string{"shell"}, nil, nil),
|
||||
mod("fish", []string{"shell"}, nil, nil),
|
||||
), []string{"editor"}, workstation(), mcat.World{})
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("a requirement with three answers was resolved without asking")
|
||||
}
|
||||
for _, want := range []string{"bash", "fish", "zsh", "choose one"} {
|
||||
if !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("the refusal does not mention %q: %v", want, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestARequirementWithNoAnswerIsRefused(t *testing.T) {
|
||||
_, err := Resolve(shelf(mod("i3", nil, []string{"xorg"}, nil)), []string{"i3"}, workstation(), mcat.World{})
|
||||
|
||||
if err == nil || !strings.Contains(err.Error(), "nothing provides") {
|
||||
t.Fatalf("a requirement nothing satisfies gave %v", err)
|
||||
// A requirement nothing answers costs the modules that want it, not the machine (A-452; ace, 2026-11-16 23:11: ten unanswered
|
||||
// requirements refused the whole composition), whether nothing on the node or nothing in the whole mesh answers it; one that
|
||||
// only optional consumers want is left absent (ADR 0330 §3); several answers are still the node's refusal, naming them (the
|
||||
// mesh does not pick: a default would be a choice made for somebody who finds out later); and a node whose every module is held,
|
||||
// or an assigned name nobody wants, is still refused.
|
||||
func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode(t *testing.T) {
|
||||
optional := mod("viewer", nil, []string{"codec"}, nil)
|
||||
optional.OptionalRequires = map[string]bool{"codec": true}
|
||||
hard := mod("player", nil, []string{"codec"}, nil)
|
||||
meshDB := mcat.Manifest{Module: "postgres", Provides: []mcat.Offer{{Name: "postgres-database", Scope: mcat.ScopeMesh}}}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
shelf map[string]mcat.Manifest
|
||||
assigned []string
|
||||
held map[string]string // module -> words in its why
|
||||
refused []string // words of the node's refusal
|
||||
absent bool
|
||||
}{
|
||||
{name: "on the node", assigned: []string{"ca-trust", "baserow", "sheet-viewer", "editor"},
|
||||
shelf: shelf(mod("ca-trust", nil, []string{"internal-acme-ca"}, nil),
|
||||
mod("baserow", []string{"spreadsheet"}, []string{"route"}, nil),
|
||||
mod("sheet-viewer", nil, []string{"spreadsheet"}, nil), mod("editor", nil, nil, nil)),
|
||||
held: map[string]string{"ca-trust": `nothing provides "internal-acme-ca"`, "baserow": `nothing provides "route"`}},
|
||||
{name: "in the whole mesh", assigned: []string{"baserow", "editor"},
|
||||
shelf: shelf(meshDB, mod("baserow", nil, []string{"postgres-database"}, nil), mod("editor", nil, nil, nil)),
|
||||
held: map[string]string{"baserow": `nothing in this mesh provides "postgres-database", wanted by baserow`}},
|
||||
{name: "wanted hard by one and optionally by another", assigned: []string{"player", "viewer"},
|
||||
shelf: shelf(hard, optional), held: map[string]string{"player": `nothing provides "codec"`}, absent: true},
|
||||
{name: "every module held", assigned: []string{"ca-trust"},
|
||||
shelf: shelf(mod("ca-trust", nil, []string{"internal-acme-ca"}, nil)),
|
||||
refused: []string{"nothing provides", "every one is held"}},
|
||||
{name: "nobody wants it", assigned: []string{"ghost"}, shelf: shelf(mod("editor", nil, nil, nil)),
|
||||
refused: []string{"nothing provides"}},
|
||||
{name: "several answers", assigned: []string{"editor"},
|
||||
shelf: shelf(mod("editor", nil, []string{"shell"}, nil), mod("bash", []string{"shell"}, nil, nil),
|
||||
mod("zsh", []string{"shell"}, nil, nil), mod("fish", []string{"shell"}, nil, nil)),
|
||||
refused: []string{"bash", "fish", "zsh", "choose one"}},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
got, held, err := ResolveHolding(c.shelf, c.assigned, workstation(), mcat.World{})
|
||||
if c.refused != nil {
|
||||
if err == nil {
|
||||
t.Fatal("the node was composed, not refused")
|
||||
}
|
||||
for _, w := range c.refused {
|
||||
if !strings.Contains(err.Error(), w) {
|
||||
t.Errorf("the refusal does not mention %q: %v", w, err)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("the node was refused whole: %v", err)
|
||||
}
|
||||
if len(held) != len(c.held) {
|
||||
t.Errorf("held %v, want modules %v", held, c.held)
|
||||
}
|
||||
for m, w := range c.held {
|
||||
if !strings.Contains(held[m], w) {
|
||||
t.Errorf("%s is held with %q, want %q", m, held[m], w)
|
||||
}
|
||||
}
|
||||
if _, heldToo := held["viewer"]; c.absent && (heldToo || len(got.Absent) != 1 || got.Absent[0] != (mcat.Absent{Consumer: "viewer", Requirement: "codec"})) {
|
||||
t.Errorf("the optional consumer was held or not listed absent: held %v absent %v", held, got.Absent)
|
||||
}
|
||||
if len(got.Modules) != len(c.assigned) {
|
||||
t.Errorf("the node does not keep every module of its set: %v", names(got))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -291,22 +291,31 @@ func (c *composer) resolutionHolding(nodeName string) (catalogue.Resolution, map
|
||||
At: onNetwork[nodeName], PublicDomain: node.PublicDomain,
|
||||
Account: node.Account, AccountHome: node.AccountHome,
|
||||
AgentAccount: node.AgentAccount, AgentAccountHome: node.AgentAccountHome}, world)
|
||||
if err != nil {
|
||||
// What another node's set would have offered is missing when that set does not resolve here: said with the
|
||||
// refusal, so "nothing provides" is read beside why (issue 1126, probe #532).
|
||||
// What another node's set would have offered is missing when that set does not resolve here: said with the refusal, and with
|
||||
// each module held for a requirement nothing answers, so "nothing provides" is read beside why (issue 1126, probe #532).
|
||||
why := func() string {
|
||||
var out string
|
||||
if len(left) > 0 {
|
||||
var why []string
|
||||
var parts []string
|
||||
for _, l := range left {
|
||||
why = append(why, l.String())
|
||||
parts = append(parts, l.String())
|
||||
}
|
||||
err = fmt.Errorf("%w\n\nand %d node(s) offer nothing here, as they could not be resolved: %s", err, len(left), strings.Join(why, "; "))
|
||||
out += fmt.Sprintf("\n\nand %d node(s) offer nothing here, as they could not be resolved: %s", len(left), strings.Join(parts, "; "))
|
||||
}
|
||||
if len(c.unhostable) > 0 {
|
||||
err = fmt.Errorf("%w\n\nand these modules offer nothing here, as their node cannot run them in this composition: %s",
|
||||
err, strings.Join(c.unhostable, "; "))
|
||||
out += fmt.Sprintf("\n\nand these modules offer nothing here, as their node cannot run them in this composition: %s",
|
||||
strings.Join(c.unhostable, "; "))
|
||||
}
|
||||
return out
|
||||
}
|
||||
if err != nil {
|
||||
// The node's own set does not compose: the only failure a mesh-wide gatherer may pass over.
|
||||
return catalogue.Resolution{}, nil, notResolvable{err}
|
||||
return catalogue.Resolution{}, nil, notResolvable{fmt.Errorf("%w%s", err, why())}
|
||||
}
|
||||
for m, w := range held {
|
||||
if strings.Contains(w, "nothing provides") || strings.Contains(w, "nothing in this mesh provides") {
|
||||
held[m] = w + why()
|
||||
}
|
||||
}
|
||||
return resolved, held, nil
|
||||
}
|
||||
|
||||
@@ -295,7 +295,9 @@ func TestARecordAnsweredNeedGetsItsKeyAndTheManagerItsPublicKey(t *testing.T) {
|
||||
// 1362/AC5: a node whose own set does not compose returns an error callers can tell from an unreadable Input.
|
||||
func TestANodeWhoseOwnSetDoesNotComposeIsToldApartFromAnUnreadableInput(t *testing.T) {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Requires: []string{"nothing-gives-this"}}
|
||||
in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Requires: []string{"two-give-this"}}
|
||||
in.Catalogue["giver-a"] = catalogue.Manifest{Module: "giver-a", Version: "1", Provides: catalogue.Offers("two-give-this")}
|
||||
in.Catalogue["giver-b"] = catalogue.Manifest{Module: "giver-b", Version: "1", Provides: catalogue.Offers("two-give-this")}
|
||||
laptop := nodeOf(t, &in, "laptop")
|
||||
laptop.Assigned = append(laptop.Assigned, "rival-one")
|
||||
if _, err := Resolve(in, "laptop"); err == nil || !IsUnresolvable(err) {
|
||||
|
||||
Reference in New Issue
Block a user