Node-engine: an unanswered requirement costs its consumer, not the machine (A-452) #232
@@ -605,15 +605,16 @@ 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)
|
||||
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
|
||||
@@ -708,7 +709,7 @@ func unansweredWords(want, consumer, remedy string) string {
|
||||
// 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) (map[string]string, []string) {
|
||||
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
|
||||
@@ -725,7 +726,8 @@ func holdUnanswered(modules []mcat.Manifest, unanswered []string, remedies map[s
|
||||
}
|
||||
found = true
|
||||
if m.IsOptional(want) {
|
||||
// Optional for this module: not held (ADR 0330 §3).
|
||||
// Optional for this module: not held, left absent and listed (ADR 0330 §3, §7).
|
||||
absent[want] = true
|
||||
continue
|
||||
}
|
||||
if held == nil {
|
||||
|
||||
@@ -61,6 +61,7 @@ func TestARequirementWithOneAnswerIsTakenSilently(t *testing.T) {
|
||||
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
|
||||
@@ -78,8 +79,8 @@ func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode
|
||||
{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 only optionally", assigned: []string{"viewer", "editor"},
|
||||
shelf: shelf(optional, mod("editor", nil, nil, nil)), absent: true},
|
||||
{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"}},
|
||||
@@ -114,8 +115,8 @@ func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode
|
||||
t.Errorf("%s is held with %q, want %q", m, held[m], w)
|
||||
}
|
||||
}
|
||||
if c.absent && (len(held) != 0 || len(got.Absent) == 0) {
|
||||
t.Errorf("an optional requirement was held or not left absent: held %v absent %v", held, got.Absent)
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user