composer: a machine that fails with no module held is searched for its culprit, bounded by blame_tries (G-24 H2)
The composer program has no settings, so the assigner bounds the search through the request: only the candidate's changed modules placed on the machine are held, one at a time, the search ending at the first whose hold ends the problem; past the bound the untried are named. A request with no blame_tries gets no search. Builds: design 47 G §721, §733; A-468h, A-468i, A-469i, A-469j, A-469k
This commit is contained in:
@@ -172,30 +172,48 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) {
|
||||
return `{"module": "` + module + `", "version": "1", "resources": [{"id": "f", "type": "file", "path": "` + path +
|
||||
`", "mode": "0600", "content": "` + content + `"}]}`
|
||||
}
|
||||
plain := func(module string) string { return `{"module": "` + module + `", "version": "1"}` }
|
||||
secret := `N=${secret:repository}\\n`
|
||||
search := map[string]string{"m1": plain("m1"), "m2": file("m2", "/var/lib/m2/env", secret), "m3": plain("m3")}
|
||||
for _, row := range []struct {
|
||||
name string
|
||||
manifests map[string]string
|
||||
assigned []string
|
||||
how *compose.ComposedHow
|
||||
tries int // the request's blame_tries
|
||||
blamed []blame // each module blamed, its problem holding the words given
|
||||
}{
|
||||
// G-24 H-AC1: a fixture module whose manifest is refused on the machine is blamed by name.
|
||||
{"a module the change refuses is blamed by name", map[string]string{"app": file("app", "/var/lib/app/env", `N=${secret:repository}\\n`)},
|
||||
[]string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, []blame{{Module: "app", Problem: "repository"}}},
|
||||
[]string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, 0, []blame{{Module: "app", Problem: "repository"}}},
|
||||
// Held composing without the change (HeldBefore): left out of blamed.
|
||||
{"a module held before the change is not blamed", map[string]string{"app": file("app", "/var/lib/app/env", `N=${secret:repository}\\n`)},
|
||||
[]string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}, HeldBefore: map[string]string{"app": "held"}}, []blame{}},
|
||||
[]string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}, HeldBefore: map[string]string{"app": "held"}}, 0, []blame{}},
|
||||
// G-24 H-AC2 (A-468l): two modules owning one path are both blamed, with that path.
|
||||
{"two modules owning one path are both blamed", map[string]string{"one": file("one", "/etc/shared.conf", "x"), "two": file("two", "/etc/shared.conf", "y")},
|
||||
[]string{"one", "two"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}},
|
||||
[]string{"one", "two"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, 0,
|
||||
[]blame{{Module: "one", Problem: `one and two both declare the path "/etc/shared.conf"`}, {Module: "two", Problem: `one and two both declare the path "/etc/shared.conf"`}}},
|
||||
// The same, on a node whose input says not how it composes: nothing is held, both owners are blamed from the refusal.
|
||||
{"two path owners, composed without how the node composes", map[string]string{"one": file("one", "/etc/shared.conf", "x"), "two": file("two", "/etc/shared.conf", "y")},
|
||||
[]string{"one", "two"}, nil,
|
||||
[]string{"one", "two"}, nil, 20,
|
||||
[]blame{{Module: "one", Problem: `one and two both declare the path "/etc/shared.conf"`}, {Module: "two", Problem: `one and two both declare the path "/etc/shared.conf"`}}},
|
||||
// G-24 H-AC5: a machine that fails with no module held is searched over the changed modules placed on it (here every
|
||||
// one, the input naming no manifest its builds were made of, A-469k), in assignment order; the search ends at the
|
||||
// first whose hold ends the problem, so m3 is never tried.
|
||||
{"the search ends at the first module whose hold ends the problem", search, []string{"m1", "m2", "m3"}, nil, 20,
|
||||
[]blame{{Module: "m2", Problem: "repository"}}},
|
||||
// A module whose case manifest is the one its build was made of is not changed (A-469k), so never held: m2's
|
||||
// problem is then no changed module's, and none is blamed.
|
||||
{"a module its build was made of is not tried", search, []string{"m1", "m2", "m3"},
|
||||
&compose.ComposedHow{Node: "b", Manifests: map[string]string{"m2": digest(t, search["m2"])}}, 20, []blame{}},
|
||||
// G-24 H-AC4: past the request's blame_tries the modules not yet tried are named so.
|
||||
{"past blame_tries the untried are named", search, []string{"m1", "m2", "m3"}, nil, 1,
|
||||
[]blame{{Module: "m2", Problem: composer.NotTried}, {Module: "m3", Problem: composer.NotTried}}},
|
||||
// A-468i: a request with no blame_tries gets no search; the machine fails on the node's own account (H-AC3).
|
||||
{"a request with no blame_tries is not searched", search, []string{"m1", "m2", "m3"}, nil, 0, []blame{}},
|
||||
} {
|
||||
t.Run(row.name, func(t *testing.T) {
|
||||
r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Machines: []string{"a"}, Seats: seats(t),
|
||||
r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Machines: []string{"a"}, Seats: seats(t), BlameTries: row.tries,
|
||||
Cases: []composer.Case{{Name: "change", Manifests: map[string]composer.Manifest{}}}}
|
||||
for name, raw := range row.manifests {
|
||||
r.Cases[0].Manifests[name] = composer.Manifest{Raw: json.RawMessage(raw)}
|
||||
@@ -213,8 +231,8 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := v.Cases[0].Machines["a"]
|
||||
if len(row.blamed) > 0 && m.Composes {
|
||||
t.Errorf("a machine that blames a module composes: %+v", m)
|
||||
if held := row.how != nil && row.how.HeldBefore != nil; m.Composes != held {
|
||||
t.Errorf("composes = %v, want %v: %+v", m.Composes, held, m)
|
||||
}
|
||||
if len(m.Blamed) != len(row.blamed) {
|
||||
t.Fatalf("blamed %+v, want %+v (%+v)", m.Blamed, row.blamed, m)
|
||||
@@ -228,6 +246,16 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// digest is the content digest of a manifest (compose.ContentDigest).
|
||||
func digest(t *testing.T, raw string) string {
|
||||
t.Helper()
|
||||
d, err := compose.ContentDigest([]byte(raw))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// blame is one module a machine's verdict blames (composer.Machine.Blamed).
|
||||
type blame = struct {
|
||||
Module string `json:"module"`
|
||||
|
||||
Reference in New Issue
Block a user