Feature 57 (config and provisioning): modules declare config and provisions, their files rendered from templates; synced with main (issues of feature 57, 874)

This commit is contained in:
2026-10-16 07:37:43 +00:00
parent 1a2c917abf
commit 9652b2d5ce
771 changed files with 52063 additions and 1774 deletions
@@ -0,0 +1,64 @@
package main
import (
"encoding/json"
"os"
"path/filepath"
"testing"
)
// The module's directory, where its manifest and its files/ are.
const moduleDir = "../.."
// templateText is the text a file resource places on the machine: its template's, in the module's files/
// (novox/hq ADR 0349 §2). A resource that names no template, or a template that is not there, fails the test.
func templateText(t *testing.T, r map[string]any) string {
t.Helper()
name, _ := r["template"].(string)
if name == "" {
t.Fatalf("resource %v names no template", r["id"])
}
raw, err := os.ReadFile(filepath.Join(moduleDir, filepath.FromSlash(name)))
if err != nil {
t.Fatalf("resource %v names %s: %v", r["id"], name, err)
}
return string(raw)
}
// No file resource carries its text inline: each names its template in files/, and the build packs files/
// into the one archive the controller reads the templates back from (novox/hq ADR 0349 §2).
func TestEveryFileTakesItsTextFromATemplate(t *testing.T) {
raw, err := os.ReadFile(filepath.Join(moduleDir, "module.json"))
if err != nil {
t.Fatal(err)
}
var m struct {
Resources []map[string]any `json:"resources"`
Build struct {
Artifacts []map[string]any `json:"artifacts"`
} `json:"build"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
for _, r := range m.Resources {
if _, inline := r["content"]; inline {
t.Errorf("resource %v keeps its text inline: keep it in files/ and name it as the template", r["id"])
}
if r["type"] == "file" {
templateText(t, r)
}
}
packs := 0
for _, a := range m.Build.Artifacts {
if a["kind"] == "archive" && a["from"] == "files" {
packs++
if a["name"] != "files" {
t.Errorf("the templates archive is named %v, not files", a["name"])
}
}
}
if packs != 1 {
t.Errorf("the build packs files/ into %d archives, not one", packs)
}
}
@@ -0,0 +1,35 @@
# Managed by the mesh (module systemd-networkd). Replaced on every push; edit
# the catalogue instead.
#
# This machine's uplink is systemd-networkd's, and the mesh asks one thing of it
# here (novox/hq ADR 0117): leave the private network's interface alone. mesh0
# is the mesh's; the mesh brings it up and configures it itself. The mesh never
# declares a link, an address, a route, a wireless network or its credentials,
# nor a network file for any of this machine's own interfaces — those are
# the operator's, and the link they make is the only channel the mesh reaches
# this machine over.
#
# 00-: networkd applies the first .network file, in alphanumeric order across
# every directory, that matches an interface, and ignores every later one even
# if it matches too (systemd.network(5), [Match]). A catch-all of the operator's
# — Name=*, Type=ether, a file with no [Match] at all — sorted before
# this one would claim mesh0 first. 00 sorts before every numbered prefix the
# man page recommends.
#
# Unmanaged=yes: "no attempts are made to bring up or configure matching links,
# equivalent to when there are no matching network files" (systemd.network(5),
# [Link], since 233). A match that ends the search, and does nothing else.
#
# No DNS setting, because none is needed: networkd never writes
# /etc/resolv.conf. What it learns from a lease it hands only to
# systemd-resolved, which the mesh does not run (novox/hq ADR 0196). So this
# module declares the resolver file itself, beside this one, listing the
# mesh's resolvers (novox/hq ADR 0223).
#
# The service is reloaded when this file changes, never restarted: a restart
# drops the links networkd holds, this machine's channel to the mesh among them.
[Match]
Name=mesh0
[Link]
Unmanaged=yes
+6 -1
View File
@@ -31,6 +31,11 @@
"loads": [
"uplink-tools"
]
},
{
"name": "files",
"kind": "archive",
"from": "files"
}
]
},
@@ -46,7 +51,7 @@
"type": "file",
"path": "/etc/systemd/network/00-mesh0.network",
"mode": "0644",
"content": "# Managed by the mesh (module systemd-networkd). Replaced on every push; edit\n# the catalogue instead.\n#\n# This machine's uplink is systemd-networkd's, and the mesh asks one thing of it\n# here (novox/hq ADR 0117): leave the private network's interface alone. mesh0\n# is the mesh's; the mesh brings it up and configures it itself. The mesh never\n# declares a link, an address, a route, a wireless network or its credentials,\n# nor a network file for any of this machine's own interfaces — those are\n# the operator's, and the link they make is the only channel the mesh reaches\n# this machine over.\n#\n# 00-: networkd applies the first .network file, in alphanumeric order across\n# every directory, that matches an interface, and ignores every later one even\n# if it matches too (systemd.network(5), [Match]). A catch-all of the operator's\n# — Name=*, Type=ether, a file with no [Match] at all — sorted before\n# this one would claim mesh0 first. 00 sorts before every numbered prefix the\n# man page recommends.\n#\n# Unmanaged=yes: \"no attempts are made to bring up or configure matching links,\n# equivalent to when there are no matching network files\" (systemd.network(5),\n# [Link], since 233). A match that ends the search, and does nothing else.\n#\n# No DNS setting, because none is needed: networkd never writes\n# /etc/resolv.conf. What it learns from a lease it hands only to\n# systemd-resolved, which the mesh does not run (novox/hq ADR 0196). So this\n# module declares the resolver file itself, beside this one, listing the\n# mesh's resolvers (novox/hq ADR 0223).\n#\n# The service is reloaded when this file changes, never restarted: a restart\n# drops the links networkd holds, this machine's channel to the mesh among them.\n[Match]\nName=mesh0\n\n[Link]\nUnmanaged=yes\n"
"template": "files/00-mesh0.network"
},
{
"id": "service",