912f7c127e
gates / gates (push) Successful in 27s
- internal place: the record /var/lib/felhom-agent/internal-place.json -> mounted at /mnt/belso by fs-UUID like an enrolled drive (startup + 20 s tick), kind "internal" in GET /disks; never takes a household drive's /mnt/belso; eject/decommission/format refused (dm on the system disk). - configs/felhom-internal-place: the ruled size rule and the only lvcreate/mkfs of a system-disk volume (installer + the new signed op add_internal_place, operator key, no parameters). - partitions listed per free disk (empty / filesystem / in_use); a data-bearing part's wipe id binds disk id + part number + fs-UUID. - felhom-mkfs-guarded: Felhom's own sibling drive no longer blocks formatting the free part; an unlistable disk refuses. Tests red-proved (script mutations, Go mutations, the old wrapper measured against the new tests). Claude-Session: https://claude.ai/code/session_012qRErfCoiTkvDK9N5XHbzb
74 lines
3.0 KiB
Go
74 lines
3.0 KiB
Go
package storage
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// Partitions as places (felhom.eu architecture/16 §6, agent v0.158.0): every partition of a free disk with its own
|
|
// state; Felhom's own drive shown but never offered; anything foreign, layered or a member never listed.
|
|
|
|
const partTree = `{"blockdevices":[
|
|
{"name":"sdb","fstype":null,"mountpoint":null,"children":[
|
|
{"name":"sdb1","fstype":"ext4","mountpoint":"/mnt/felhom-drives/hdd_1"},
|
|
{"name":"sdb2","fstype":null,"mountpoint":null},
|
|
{"name":"sdb3","fstype":"ntfs","mountpoint":null},
|
|
{"name":"sdb4","fstype":"xfs","mountpoint":null},
|
|
{"name":"sdb5","fstype":"ext4","mountpoint":"/mnt/films"},
|
|
{"name":"sdb6","fstype":"ext4","mountpoint":"/srv/data"},
|
|
{"name":"sdb7","fstype":"LVM2_member","mountpoint":null,"children":[{"name":"vg-lv","fstype":"ext4","mountpoint":null}]},
|
|
{"name":"sdb8","fstype":"crypto_LUKS","mountpoint":null}
|
|
]},
|
|
{"name":"sdc","fstype":null,"mountpoint":null,"children":[{"name":"sdc1","fstype":null,"mountpoint":null}]}
|
|
]}`
|
|
|
|
func listParts(owned map[string]bool) map[string]CandidatePartition {
|
|
got := candidatePartitions([]byte(partTree), "sdb",
|
|
func(n string) int64 { return int64(len(n)) << 30 },
|
|
func(n string) int { return int(n[len(n)-1] - '0') },
|
|
func(dev string) (string, bool) { return "uuid-of-" + strings.TrimPrefix(dev, "/dev/"), true },
|
|
owned)
|
|
m := map[string]CandidatePartition{}
|
|
for _, p := range got {
|
|
m[p.Device] = p
|
|
}
|
|
return m
|
|
}
|
|
|
|
func TestPartitions_StatesPerPartition(t *testing.T) {
|
|
m := listParts(map[string]bool{"/mnt/films": true})
|
|
want := map[string]string{"/dev/sdb1": PartInUse, "/dev/sdb2": PartEmpty, "/dev/sdb3": PartFilesystem,
|
|
"/dev/sdb4": PartFilesystem, "/dev/sdb5": PartInUse}
|
|
if len(m) != len(want) {
|
|
t.Fatalf("want exactly %d listed partitions, got %+v", len(want), m)
|
|
}
|
|
for dev, st := range want {
|
|
if m[dev].State != st {
|
|
t.Fatalf("%s: want %s, got %+v", dev, st, m[dev])
|
|
}
|
|
}
|
|
if m["/dev/sdb2"].DurableID != "" || m["/dev/sdb2"].Mountable {
|
|
t.Fatalf("an empty part has no attach key: %+v", m["/dev/sdb2"])
|
|
}
|
|
if !m["/dev/sdb4"].Mountable || m["/dev/sdb4"].DurableID != "uuid:uuid-of-sdb4" || m["/dev/sdb4"].Number != 4 {
|
|
t.Fatalf("an xfs part is usable by its fs-UUID: %+v", m["/dev/sdb4"])
|
|
}
|
|
if m["/dev/sdb3"].Mountable {
|
|
t.Fatalf("ntfs is a filesystem the agent does not mount as-is: %+v", m["/dev/sdb3"])
|
|
}
|
|
}
|
|
|
|
// A raw /mnt/<name> mount counts as Felhom's own ONLY when corroborated (felhomOwnedMounts); else it is foreign and
|
|
// the part is not listed. Positive control: TestPartitions_StatesPerPartition (the same mount, corroborated).
|
|
func TestPartitions_UncorroboratedMountIsNotOffered(t *testing.T) {
|
|
m := listParts(nil)
|
|
if _, ok := m["/dev/sdb5"]; ok {
|
|
t.Fatalf("an uncorroborated /mnt/films mount must not be listed, got %+v", m["/dev/sdb5"])
|
|
}
|
|
for _, dev := range []string{"/dev/sdb6", "/dev/sdb7", "/dev/sdb8", "/dev/sdc1"} {
|
|
if _, ok := m[dev]; ok {
|
|
t.Fatalf("%s must never be listed (foreign mount, LVM, LUKS, another disk)", dev)
|
|
}
|
|
}
|
|
}
|