hub (unreleased): the hub keeps and shows which boxes were accepted on a small system disk (D83, R-1398 part 2)
gates / gates (push) Successful in 3m40s
gates / gates (push) Successful in 3m40s
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
8378dc446b
commit
c3fa43a486
10 files changed
+407
-1
No files matched your search
@@ -476,7 +476,7 @@ seam (no real disk).
|
|||||||
| The size cannot be read (no `pve` group, two physical volumes, a RAID, no size) | appliance: stops and names the flag; with the flag it goes on, recorded as small with size „unknown” | `…_size_that_cannot_be_read_refuses_and_names_the_flag` |
|
| The size cannot be read (no `pve` group, two physical volumes, a RAID, no size) | appliance: stops and names the flag; with the flag it goes on, recorded as small with size „unknown” | `…_size_that_cannot_be_read_refuses_and_names_the_flag` |
|
||||||
| A small system disk and a large second one | the system disk decides, in both directions | `…_a_large_second_disk_does_not_help` |
|
| A small system disk and a large second one | the system disk decides, in both directions | `…_a_large_second_disk_does_not_help` |
|
||||||
| The existing 120 GiB pool warning | stays | `test_lvm_minimum_is_named_as_what_it_does` |
|
| The existing 120 GiB pool warning | stays | `test_lvm_minimum_is_named_as_what_it_does` |
|
||||||
| The public image, nobody watching | **NOT built — R-1398.** The first-boot unit runs the installer again until it succeeds, so a refused machine prints the refusal on its own screen every 30 seconds; the hub is not told why, and the hub does not read `small_disk` | — |
|
| The public image, nobody watching | **NOT built — R-1398.** The first-boot unit runs the installer again until it succeeds, so a refused machine prints the refusal on its own screen every 30 seconds; the hub is not told why (R-1398 part 1). **The hub's half of the mark is built, not released (2026-11-15 evening):** the hub keeps `small_disk` from the enrolment and the box's page shows „System disk: small — accepted below 200 GB”; the size shows when an installer sends `system_disk_bytes` (installer 1.38.0 sends only the flag) | hub `TestD83_*`, `TestSmallDisk_*` |
|
||||||
|
|
||||||
**The sentences, as built (the installer's output, English only — the installer has no Hungarian text):**
|
**The sentences, as built (the installer's output, English only — the installer has no Hungarian text):**
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
## run in a private copy of hub/ (another helper edits the shared tree; a mutation tool rewrites whole files)
|
||||||
|
== MUTATION: a box whose id only starts with this id reads the mark
|
||||||
|
*** NOT A RED-PROOF *** (mutant rc=0 built=True real rc=0)
|
||||||
|
== MUTATION: a size at or above the line is kept
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestSmallDisk_NotedPerBox_ReadBack_LookAlikeApart (0.04s)
|
||||||
|
small_disk_test.go:39: size 200000000000 was kept: &{Bytes:200000000000 NotedAt:2026-11-16 09:00:00 +0000 UTC}
|
||||||
|
== MUTATION: told again leaves two marks
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestSmallDisk_NotedPerBox_ReadBack_LookAlikeApart (0.05s)
|
||||||
|
small_disk_test.go:30: told again: &{Bytes:128035676160 NotedAt:2026-11-16 09:00:00 +0000 UTC}
|
||||||
|
== MUTATION: an id with a colon makes a mark
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestSmallDisk_NotedPerBox_ReadBack_LookAlikeApart (0.05s)
|
||||||
|
small_disk_test.go:45: an id with a colon made 1 mark(s)
|
||||||
|
== MUTATION: the mark is not under the names a box delete removes
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestSmallDisk_GoesWithTheBox (0.05s)
|
||||||
|
small_disk_test.go:66: the deleted box's mark stayed: &{Bytes:128000000000 NotedAt:2026-11-15 14:59:58 +0000 UTC}
|
||||||
|
|
||||||
|
5 mutations, 1 not a red-proof
|
||||||
|
== MUTATION: any value of small_disk is the flag
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestD83_OnlyTrueIsTheFlag_AndARefusedRequestMarksNothing (0.04s)
|
||||||
|
d83_small_disk_test.go:77: {"customer_id":"c%d","small_disk":"true"} was read as the flag
|
||||||
|
== MUTATION: the first enrolment does not store the mark
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestD83_EnrolmentStoresTheSmallDiskMark (0.05s)
|
||||||
|
d83_small_disk_test.go:40: the hub did not keep the mark of c1-370d7b: <nil>
|
||||||
|
== MUTATION: a reinstall over the record does not store the mark
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestD83_EnrolmentStoresTheSmallDiskMark (0.05s)
|
||||||
|
d83_small_disk_test.go:48: the size of the second enrolment was not kept: &{Bytes:0 NotedAt:2026-11-15 15:00:10 +0000 UTC}
|
||||||
|
== MUTATION: the size is not read
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestD83_EnrolmentStoresTheSmallDiskMark (0.05s)
|
||||||
|
d83_small_disk_test.go:48: the size of the second enrolment was not kept: &{Bytes:0 NotedAt:2026-11-15 15:00:13 +0000 UTC}
|
||||||
|
|
||||||
|
4 mutations, 0 not a red-proof
|
||||||
|
== MUTATION: the page never shows the line
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestD83_HostPageShowsTheSmallDiskLine (0.06s)
|
||||||
|
d83_small_disk_test.go:34: the page of a box accepted on 128 GB does not say so
|
||||||
|
== MUTATION: every box shows the line
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestD83_HostPageShowsTheSmallDiskLine (0.07s)
|
||||||
|
d83_small_disk_test.go:40: the page of a box the hub was never told about shows the small-disk line
|
||||||
|
== MUTATION: the size is shown in GiB as GB
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestD83_HostPageShowsTheSmallDiskLine (0.06s)
|
||||||
|
d83_small_disk_test.go:34: the page of a box accepted on 128 GB does not say so
|
||||||
|
|
||||||
|
3 mutations, 0 not a red-proof
|
||||||
|
|
||||||
|
== MUTATION: a box whose id only starts with this id reads the mark (redone: the first mutant removed one of TWO guards and was equal in effect; this one removes both)
|
||||||
|
RED on the mutant, GREEN on the real file
|
||||||
|
--- FAIL: TestSmallDisk_NotedPerBox_ReadBack_LookAlikeApart (0.05s)
|
||||||
|
small_disk_test.go:22: "demo-hp-bb76e" reads the mark of another box: &{Bytes:128035676160 NotedAt:2026-11-16 09:00:00 +0000 UTC}
|
||||||
|
--- FAIL: TestSmallDisk_GoesWithTheBox (0.05s)
|
||||||
|
small_disk_test.go:66: the deleted box's mark stayed: &{Bytes:128000000000 NotedAt:2026-11-15 15:00:44 +0000 UTC}
|
||||||
|
|
||||||
|
1 mutations, 0 not a red-proof
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
## Unreleased (after v0.182.0)
|
## Unreleased (after v0.182.0)
|
||||||
|
|
||||||
|
- **D83, the hub's half (2026-11-15 evening, R-1398 part 2; `16` §14.5): the hub shows which boxes were accepted on a
|
||||||
|
small system disk.** `POST /host-enroll` reads `small_disk` (only the JSON `true`) and, when a later installer sends
|
||||||
|
it, `system_disk_bytes`; `store.NoteSmallDisk` / `SmallDiskOf` keep it as one of the marks that name the box
|
||||||
|
(`os_alarm:small_disk:<host>:<bytes>`), so a box delete removes it with no new delete code. The box's page shows
|
||||||
|
„System disk: small — accepted below 200 GB (128 GB, noted …)”; a box the hub was never told about shows nothing.
|
||||||
|
A refused enrolment marks nothing. Tests `TestSmallDisk_*`, `TestD83_*` (api, web); 13 mutations seen red.
|
||||||
- **D86 (2026-11-15 evening, `09` §3 decision 314; `05` §14.3): the delete journal keeps no id after one year.**
|
- **D86 (2026-11-15 evening, `09` §3 decision 314; `05` §14.3): the delete journal keeps no id after one year.**
|
||||||
`store.PruneDeletedCustomerAudit` now runs each deleted household's year-end in ONE transaction and, with the audit
|
`store.PruneDeletedCustomerAudit` now runs each deleted household's year-end in ONE transaction and, with the audit
|
||||||
rows, empties the ids of that deleted life's journal rows (`customer_resets.customer_id`,
|
rows, empties the ids of that deleted life's journal rows (`customer_resets.customer_id`,
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
func enrollBody(h http.Handler, body, pass string) *httptest.ResponseRecorder {
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/host-enroll", strings.NewReader(body))
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
if pass != "" {
|
||||||
|
req.Header.Set("X-Retrieval-Password", pass)
|
||||||
|
}
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
h.ServeHTTP(rr, req)
|
||||||
|
return rr
|
||||||
|
}
|
||||||
|
|
||||||
|
// D83 (R-1398 part 2): an install that went on with --accept-small-disk says so at its enrolment, and the hub keeps
|
||||||
|
// it for the box's page — at the first enrolment and at a reinstall over the same record. An ordinary enrolment, and
|
||||||
|
// an older installer, mark nothing.
|
||||||
|
func TestD83_EnrolmentStoresTheSmallDiskMark(t *testing.T) {
|
||||||
|
h, st, _ := newTestHandler(t)
|
||||||
|
st.SaveCustomerConfig(&store.CustomerConfig{CustomerID: "c1", APIKey: "k1", RetrievalPassword: "pass-phrase"})
|
||||||
|
st.SaveCustomerConfig(&store.CustomerConfig{CustomerID: "c2", APIKey: "k2", RetrievalPassword: "pass-phrase"})
|
||||||
|
|
||||||
|
rr := enrollBody(h, `{"customer_id":"c1","small_disk":true}`, "pass-phrase") // what installer 1.38.0 sends
|
||||||
|
if rr.Code != http.StatusCreated {
|
||||||
|
t.Fatalf("status %d: %s", rr.Code, rr.Body.String())
|
||||||
|
}
|
||||||
|
var got enrollResp
|
||||||
|
_ = json.Unmarshal(rr.Body.Bytes(), &got)
|
||||||
|
sd := st.SmallDiskOf(got.HostID)
|
||||||
|
if sd == nil || sd.Bytes != 0 || sd.NotedAt.IsZero() {
|
||||||
|
t.Fatalf("the hub did not keep the mark of %s: %+v", got.HostID, sd)
|
||||||
|
}
|
||||||
|
// a reinstall over the same record, now with the size (a later installer): the size is kept
|
||||||
|
rr = enrollBody(h, `{"customer_id":"c1","small_disk":true,"system_disk_bytes":128035676160}`, "pass-phrase")
|
||||||
|
if rr.Code != http.StatusOK {
|
||||||
|
t.Fatalf("reuse status %d", rr.Code)
|
||||||
|
}
|
||||||
|
if sd := st.SmallDiskOf(got.HostID); sd == nil || sd.Bytes != 128035676160 {
|
||||||
|
t.Fatalf("the size of the second enrolment was not kept: %+v", sd)
|
||||||
|
}
|
||||||
|
// the control: an ordinary enrolment marks nothing
|
||||||
|
rr = enrollBody(h, `{"customer_id":"c2"}`, "pass-phrase")
|
||||||
|
var other enrollResp
|
||||||
|
_ = json.Unmarshal(rr.Body.Bytes(), &other)
|
||||||
|
if rr.Code != http.StatusCreated || st.SmallDiskOf(other.HostID) != nil {
|
||||||
|
t.Fatalf("an ordinary enrolment (status %d) was marked small: %+v", rr.Code, st.SmallDiskOf(other.HostID))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// What a box sends is a box's word: only the JSON `true` is the flag, a size that is not a whole number is „not
|
||||||
|
// told”, and a request that is REFUSED marks nothing.
|
||||||
|
func TestD83_OnlyTrueIsTheFlag_AndARefusedRequestMarksNothing(t *testing.T) {
|
||||||
|
h, st, _ := newTestHandler(t)
|
||||||
|
for i, body := range []string{
|
||||||
|
`{"customer_id":"c%d","small_disk":"true"}`, `{"customer_id":"c%d","small_disk":1}`,
|
||||||
|
`{"customer_id":"c%d","small_disk":false}`, `{"customer_id":"c%d","small_disk":null}`,
|
||||||
|
`{"customer_id":"c%d","small_disk":{"a":true}}`,
|
||||||
|
} {
|
||||||
|
cid := "c" + string(rune('a'+i))
|
||||||
|
st.SaveCustomerConfig(&store.CustomerConfig{CustomerID: cid, APIKey: "k" + cid, RetrievalPassword: "pass-phrase"})
|
||||||
|
rr := enrollBody(h, strings.Replace(body, "c%d", cid, 1), "pass-phrase")
|
||||||
|
var got enrollResp
|
||||||
|
_ = json.Unmarshal(rr.Body.Bytes(), &got)
|
||||||
|
if rr.Code != http.StatusCreated {
|
||||||
|
t.Fatalf("%s: status %d — the enrolment itself must not fail on a strange flag", body, rr.Code)
|
||||||
|
}
|
||||||
|
if st.SmallDiskOf(got.HostID) != nil {
|
||||||
|
t.Fatalf("%s was read as the flag", body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// a size that is not a whole number: the flag stands, the size is „not told”
|
||||||
|
st.SaveCustomerConfig(&store.CustomerConfig{CustomerID: "cz", APIKey: "kz", RetrievalPassword: "pass-phrase"})
|
||||||
|
rr := enrollBody(h, `{"customer_id":"cz","small_disk":true,"system_disk_bytes":"<b>big</b>"}`, "pass-phrase")
|
||||||
|
var got enrollResp
|
||||||
|
_ = json.Unmarshal(rr.Body.Bytes(), &got)
|
||||||
|
if sd := st.SmallDiskOf(got.HostID); rr.Code != http.StatusCreated || sd == nil || sd.Bytes != 0 {
|
||||||
|
t.Fatalf("status %d, mark %+v", rr.Code, sd)
|
||||||
|
}
|
||||||
|
// a wrong passphrase: refused, and nothing is marked for any box of that household
|
||||||
|
st.SaveCustomerConfig(&store.CustomerConfig{CustomerID: "cw", APIKey: "kw", RetrievalPassword: "pass-phrase"})
|
||||||
|
if rr := enrollBody(h, `{"customer_id":"cw","small_disk":true}`, "wrong"); rr.Code != http.StatusUnauthorized {
|
||||||
|
t.Fatalf("status %d, want 401", rr.Code)
|
||||||
|
}
|
||||||
|
if n := len(st.OSAlarmKeys("small_disk:cw")); n != 0 {
|
||||||
|
t.Fatalf("a refused enrolment left %d mark(s)", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1264,11 +1264,29 @@ func (h *Handler) handleHostEnroll(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
var req struct {
|
var req struct {
|
||||||
CustomerID string `json:"customer_id"`
|
CustomerID string `json:"customer_id"`
|
||||||
|
// D83 (R-1398 part 2): an install that went on with --accept-small-disk says so; a later installer may add
|
||||||
|
// the size. An older installer sends neither. Anything but the JSON `true` is „not said”.
|
||||||
|
SmallDisk json.RawMessage `json:"small_disk"`
|
||||||
|
SystemDiskBytes json.RawMessage `json:"system_disk_bytes"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(body, &req); err != nil || req.CustomerID == "" {
|
if err := json.Unmarshal(body, &req); err != nil || req.CustomerID == "" {
|
||||||
http.Error(w, "Invalid payload: customer_id required", http.StatusBadRequest)
|
http.Error(w, "Invalid payload: customer_id required", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// noteSmallDisk is called only where the enrolment is ANSWERED with a host id (after the passphrase check): a
|
||||||
|
// request that is refused marks nothing.
|
||||||
|
noteSmallDisk := func(hostID string) {
|
||||||
|
if string(req.SmallDisk) != "true" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var n int64
|
||||||
|
_ = json.Unmarshal(req.SystemDiskBytes, &n) // not a whole number → 0 = „not told”
|
||||||
|
if err := h.store.NoteSmallDisk(hostID, n, time.Now().UTC()); err != nil {
|
||||||
|
h.logger.Printf("[WARN] host-enroll: the small-disk mark of %s was not stored: %v", hostID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.logger.Printf("[WARN] host-enroll: %s was installed with --accept-small-disk (a system disk below 200 GB); shown on the box's page", hostID)
|
||||||
|
}
|
||||||
|
|
||||||
// Passphrase auth — mirrors handleConfigRetrieve exactly (header, 404-then-401 order,
|
// Passphrase auth — mirrors handleConfigRetrieve exactly (header, 404-then-401 order,
|
||||||
// constant-time compare). Happens BEFORE any mint.
|
// constant-time compare). Happens BEFORE any mint.
|
||||||
@@ -1322,6 +1340,7 @@ func (h *Handler) handleHostEnroll(w http.ResponseWriter, r *http.Request) {
|
|||||||
h.refusePassphraseKeys(w, r, req.CustomerID, "POST /host-enroll", why)
|
h.refusePassphraseKeys(w, r, req.CustomerID, "POST /host-enroll", why)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
noteSmallDisk(existing.HostID)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(map[string]string{"host_id": existing.HostID, "api_key": existing.APIKey})
|
json.NewEncoder(w).Encode(map[string]string{"host_id": existing.HostID, "api_key": existing.APIKey})
|
||||||
@@ -1356,6 +1375,7 @@ func (h *Handler) handleHostEnroll(w http.ResponseWriter, r *http.Request) {
|
|||||||
// customer (first provision). Also re-issue the off-site login (F3) — since hub v0.127.0 that is the
|
// customer (first provision). Also re-issue the off-site login (F3) — since hub v0.127.0 that is the
|
||||||
// HUB's own Storage Box login, not something the fresh box receives (R-1158; see offsiteReissuer).
|
// HUB's own Storage Box login, not something the fresh box receives (R-1158; see offsiteReissuer).
|
||||||
h.reissueOnReenroll(cc)
|
h.reissueOnReenroll(cc)
|
||||||
|
noteSmallDisk(hostID)
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
@@ -3682,6 +3702,9 @@ func (h *Handler) noteAppList(customerID string, body []byte) {
|
|||||||
Deployed []string `json:"deployed"`
|
Deployed []string `json:"deployed"`
|
||||||
} `json:"stacks"`
|
} `json:"stacks"`
|
||||||
Offsite *struct {
|
Offsite *struct {
|
||||||
|
// Enabled: the report shows the off-site tier switched on. Only then is an app that is missing from
|
||||||
|
// ended_apps a take-back (store.NoteEndNotices).
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
EndedApps []struct {
|
EndedApps []struct {
|
||||||
App string `json:"app"`
|
App string `json:"app"`
|
||||||
// The box's own dates. Carried on the wire for the operator's reading of a stored report; the
|
// The box's own dates. Carried on the wire for the operator's reading of a stored report; the
|
||||||
@@ -3695,11 +3718,22 @@ func (h *Handler) noteAppList(customerID string, body []byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var claimed []string
|
var claimed []string
|
||||||
|
var presses []store.EndClaim
|
||||||
if p.Offsite != nil {
|
if p.Offsite != nil {
|
||||||
for _, e := range p.Offsite.EndedApps {
|
for _, e := range p.Offsite.EndedApps {
|
||||||
claimed = append(claimed, e.App)
|
claimed = append(claimed, e.App)
|
||||||
|
presses = append(presses, store.EndClaim{App: e.App, Press: e.RemovedAt}) // the press's KEY, never a date
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// The notice lock (`09` §3 decision 315): the hub's own record of who must be told, and the sends (end_notice.go).
|
||||||
|
// After the app record below, whatever it returns — a notice must not wait on another table's write.
|
||||||
|
defer func() {
|
||||||
|
if nerr := h.store.NoteEndNotices(customerID, p.Stacks.Deployed, presses, p.Offsite != nil && p.Offsite.Enabled, time.Now()); nerr != nil {
|
||||||
|
h.logger.Printf("[WARN] [api] report from %s: the hub's own notice record could not be updated: %v", customerID, nerr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.kickEndNotices(customerID)
|
||||||
|
}()
|
||||||
unseen, err := h.store.NoteAppListClaims(customerID, p.Stacks.Deployed, claimed, time.Now())
|
unseen, err := h.store.NoteAppListClaims(customerID, p.Stacks.Deployed, claimed, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logger.Printf("[WARN] [api] report from %s: the hub's own app record could not be updated: %v", customerID, err)
|
h.logger.Printf("[WARN] [api] report from %s: the hub's own app record could not be updated: %v", customerID, err)
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A box that was installed on a small system disk with the operator's flag (D83, `16-storage-physical-identity.md`
|
||||||
|
// §14.5; R-1398 part 2). The installer says so in its enrolment request (`small_disk: true`, and — a later installer
|
||||||
|
// — `system_disk_bytes`); the hub keeps it so that the operator can see which boxes were accepted below 200 GB.
|
||||||
|
//
|
||||||
|
// Kept as one of the hub's small marks that NAME the box (`os_alarm:small_disk:<host>:<bytes>`, the value is when it
|
||||||
|
// was noted): DeleteHost already removes every mark that names a deleted box, so this needs no delete of its own and
|
||||||
|
// leaves nothing behind (D73). The size is part of the key, 0 = not told. The values come from a box's installer:
|
||||||
|
// the flag must be the JSON `true`, and the size is kept only when it is a plausible disk size.
|
||||||
|
//
|
||||||
|
// Pinned by TestSmallDisk_* (small_disk_test.go) and TestD83_* (api, web).
|
||||||
|
const (
|
||||||
|
smallDiskMark = "small_disk:"
|
||||||
|
smallDiskMaxBytes = int64(200) * 1000 * 1000 * 1000 // a box marked small is BELOW the 200 GB line
|
||||||
|
)
|
||||||
|
|
||||||
|
// SmallDisk is what the hub knows of a box that was accepted on a small system disk.
|
||||||
|
type SmallDisk struct {
|
||||||
|
Bytes int64 // 0 = the installer did not say
|
||||||
|
NotedAt time.Time // when the hub was told (the hub's clock)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NoteSmallDisk records that hostID was installed with the small-disk flag. bytes outside (0, 200 GB) is kept as
|
||||||
|
// „not told” — a size at or above the line contradicts the flag and is a box's word. Told again, the newest wins.
|
||||||
|
func (s *Store) NoteSmallDisk(hostID string, bytes int64, now time.Time) error {
|
||||||
|
if hostID == "" || strings.Contains(hostID, ":") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if bytes <= 0 || bytes >= smallDiskMaxBytes {
|
||||||
|
bytes = 0
|
||||||
|
}
|
||||||
|
for _, k := range s.smallDiskKeys(hostID) {
|
||||||
|
_ = s.SetOSAlarmRaised(k, time.Time{})
|
||||||
|
}
|
||||||
|
return s.SetOSAlarmRaised(smallDiskMark+hostID+":"+strconv.FormatInt(bytes, 10), now)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SmallDiskOf returns the mark of hostID, or nil when the hub was never told (an older installer says nothing, and a
|
||||||
|
// box on a disk of 200 GB or more has no mark).
|
||||||
|
func (s *Store) SmallDiskOf(hostID string) *SmallDisk {
|
||||||
|
for _, k := range s.smallDiskKeys(hostID) {
|
||||||
|
n, err := strconv.ParseInt(k[strings.LastIndex(k, ":")+1:], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return &SmallDisk{Bytes: n, NotedAt: s.OSAlarmRaised(k)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// smallDiskKeys lists the marks of exactly this box: a box whose id only STARTS with hostID is another box.
|
||||||
|
func (s *Store) smallDiskKeys(hostID string) []string {
|
||||||
|
if hostID == "" || strings.Contains(hostID, ":") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var out []string
|
||||||
|
for _, k := range s.OSAlarmKeys(smallDiskMark + hostID + ":") {
|
||||||
|
if rest := strings.TrimPrefix(k, smallDiskMark+hostID+":"); rest != "" && !strings.Contains(rest, ":") {
|
||||||
|
out = append(out, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The stored effect: a box told as small is read back with its size and the hub's time; another box — also one whose
|
||||||
|
// id only starts with this id — is not; a size that is not below the line is kept as „not told”.
|
||||||
|
func TestSmallDisk_NotedPerBox_ReadBack_LookAlikeApart(t *testing.T) {
|
||||||
|
s := newTestStore(t)
|
||||||
|
now := time.Date(2026, 11, 16, 9, 0, 0, 0, time.UTC)
|
||||||
|
if err := s.NoteSmallDisk("demo-hp-bb76ea", 128035676160, now); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
got := s.SmallDiskOf("demo-hp-bb76ea")
|
||||||
|
if got == nil || got.Bytes != 128035676160 || !got.NotedAt.Equal(now) {
|
||||||
|
t.Fatalf("read back %+v, want 128035676160 bytes noted at %s", got, now)
|
||||||
|
}
|
||||||
|
for _, other := range []string{"demo-hp-bb76e", "demo-hp-bb76ea2", "demo-hp", "tester-1-d70be4", ""} {
|
||||||
|
if g := s.SmallDiskOf(other); g != nil {
|
||||||
|
t.Fatalf("%q reads the mark of another box: %+v", other, g)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// told again with no size: the newest wins, and ONE mark stays
|
||||||
|
if err := s.NoteSmallDisk("demo-hp-bb76ea", 0, now.Add(time.Hour)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := s.SmallDiskOf("demo-hp-bb76ea"); got == nil || got.Bytes != 0 || !got.NotedAt.Equal(now.Add(time.Hour)) {
|
||||||
|
t.Fatalf("told again: %+v", got)
|
||||||
|
}
|
||||||
|
if n := len(s.OSAlarmKeys("small_disk:")); n != 1 {
|
||||||
|
t.Fatalf("%d marks for one box, want 1", n)
|
||||||
|
}
|
||||||
|
// a size that contradicts the flag, or is not a size, is kept as „not told”
|
||||||
|
for _, bad := range []int64{200 * 1000 * 1000 * 1000, 5e15, -1} {
|
||||||
|
_ = s.NoteSmallDisk("b-1", bad, now)
|
||||||
|
if got := s.SmallDiskOf("b-1"); got == nil || got.Bytes != 0 {
|
||||||
|
t.Fatalf("size %d was kept: %+v", bad, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// an id with a colon cannot be a box's id and makes no mark
|
||||||
|
_ = s.NoteSmallDisk("x:y", 1, now)
|
||||||
|
if n := len(s.OSAlarmKeys("small_disk:x")); n != 0 {
|
||||||
|
t.Fatalf("an id with a colon made %d mark(s)", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A deleted box leaves no small-disk mark (D73: nothing that names a box outlives it) — and the mark of a box whose id
|
||||||
|
// only starts with the deleted one's stays.
|
||||||
|
func TestSmallDisk_GoesWithTheBox(t *testing.T) {
|
||||||
|
s := newTestStore(t)
|
||||||
|
now := time.Now().UTC().Truncate(time.Second)
|
||||||
|
for _, h := range []string{"cust-a-111111", "cust-a-1111112"} {
|
||||||
|
if err := s.UpsertHost(&Host{HostID: h, CustomerID: "cust-a", APIKey: "k-" + h}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := s.NoteSmallDisk(h, 128000000000, now); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := s.DeleteHost("cust-a-111111", false); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := s.SmallDiskOf("cust-a-111111"); got != nil {
|
||||||
|
t.Fatalf("the deleted box's mark stayed: %+v", got)
|
||||||
|
}
|
||||||
|
if got := s.SmallDiskOf("cust-a-1111112"); got == nil {
|
||||||
|
t.Fatal("the mark of the OTHER box (its id starts with the deleted one's) went too")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
// D83 (R-1398 part 2): the box's page says when the box was accepted on a small system disk — and says NOTHING for a
|
||||||
|
// box the hub was never told about (an older installer, or a disk of 200 GB or more). One render per branch.
|
||||||
|
func TestD83_HostPageShowsTheSmallDiskLine(t *testing.T) {
|
||||||
|
s, st := newTestServer(t)
|
||||||
|
for _, h := range []string{"small-1", "small-2", "plain-1"} {
|
||||||
|
if err := st.UpsertHost(&store.Host{HostID: h, CustomerID: "c1", APIKey: "k-" + h}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
at := time.Date(2026, 11, 16, 9, 0, 0, 0, time.UTC)
|
||||||
|
_ = st.NoteSmallDisk("small-1", 128035676160, at)
|
||||||
|
_ = st.NoteSmallDisk("small-2", 0, at)
|
||||||
|
page := func(id string) string {
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
s.handleHostDetail(rr, httptest.NewRequest(http.MethodGet, "/hosts/"+id, nil), id)
|
||||||
|
if rr.Code != http.StatusOK {
|
||||||
|
t.Fatalf("%s: status %d", id, rr.Code)
|
||||||
|
}
|
||||||
|
return rr.Body.String()
|
||||||
|
}
|
||||||
|
if b := page("small-1"); !strings.Contains(b, `id="small-disk"`) || !strings.Contains(b, "accepted below 200 GB (128 GB, noted 2026-11-16)") {
|
||||||
|
t.Fatalf("the page of a box accepted on 128 GB does not say so")
|
||||||
|
}
|
||||||
|
if b := page("small-2"); !strings.Contains(b, "accepted below 200 GB (size not told, noted 2026-11-16)") {
|
||||||
|
t.Fatalf("the page of a box whose installer sent no size does not say „size not told”")
|
||||||
|
}
|
||||||
|
if b := page("plain-1"); strings.Contains(b, `id="small-disk"`) || strings.Contains(b, "accepted below 200 GB") {
|
||||||
|
t.Fatalf("the page of a box the hub was never told about shows the small-disk line")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -871,6 +871,7 @@ func (s *Server) hostDetailData(host *store.Host, r *http.Request) map[string]in
|
|||||||
"CustomerID": host.CustomerID,
|
"CustomerID": host.CustomerID,
|
||||||
"CustomerName": s.customerName(host.CustomerID),
|
"CustomerName": s.customerName(host.CustomerID),
|
||||||
"AgentVersion": host.AgentVersion,
|
"AgentVersion": host.AgentVersion,
|
||||||
|
"SmallDisk": smallDiskLine(s.store.SmallDiskOf(host.HostID)),
|
||||||
"CreatedAt": host.CreatedAt,
|
"CreatedAt": host.CreatedAt,
|
||||||
"Status": status,
|
"Status": status,
|
||||||
"StatusLabel": hostStatusLabel(s.hostDisplayStatus(host)),
|
"StatusLabel": hostStatusLabel(s.hostDisplayStatus(host)),
|
||||||
@@ -1169,3 +1170,21 @@ func (s *Server) offsiteIntegrityForHost(customerID string) string {
|
|||||||
}
|
}
|
||||||
return offsiteIntegrityLine(rj)
|
return offsiteIntegrityLine(rj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// smallDiskLine is the box page's line for a box that was installed with --accept-small-disk (D83, `16` §14.5;
|
||||||
|
// R-1398 part 2). "" = the hub was never told: an older installer, or a disk of 200 GB or more — the page then says
|
||||||
|
// nothing. Pinned by TestD83_HostPageShowsTheSmallDiskLine.
|
||||||
|
func smallDiskLine(sd *store.SmallDisk) string {
|
||||||
|
if sd == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
size := "size not told"
|
||||||
|
if sd.Bytes > 0 {
|
||||||
|
size = fmt.Sprintf("%d GB", sd.Bytes/1000000000)
|
||||||
|
}
|
||||||
|
since := ""
|
||||||
|
if !sd.NotedAt.IsZero() {
|
||||||
|
since = ", noted " + sd.NotedAt.UTC().Format("2006-01-02")
|
||||||
|
}
|
||||||
|
return "accepted below 200 GB (" + size + since + ")"
|
||||||
|
}
|
||||||
@@ -22,6 +22,12 @@
|
|||||||
<span class="label">Agent Version</span>
|
<span class="label">Agent Version</span>
|
||||||
<span class="value">{{if .AgentVersion}}<code>{{.AgentVersion}}</code>{{else}}—{{end}}</span>
|
<span class="value">{{if .AgentVersion}}<code>{{.AgentVersion}}</code>{{else}}—{{end}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
{{if .SmallDisk}}
|
||||||
|
<div class="info-item" id="small-disk" title="The installer was run with --accept-small-disk: the system disk is below the 200 GB that Felhom needs (D83). The guest gets less space than a household is promised, and the box's local copies can stop when the disk fills.">
|
||||||
|
<span class="label">System disk</span>
|
||||||
|
<span class="value"><span class="badge badge-warn">small</span> {{.SmallDisk}}</span>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
{{if .AgentBinaryDrift}}
|
{{if .AgentBinaryDrift}}
|
||||||
<div class="info-item" id="agent-binary">
|
<div class="info-item" id="agent-binary">
|
||||||
<span class="label">Agent binary</span>
|
<span class="label">Agent binary</span>
|
||||||
|
|||||||
Reference in new issue
Block a user