hub: Restart controller (the agent's closed list on the host-report reply) and Clear hold (D64 = B, the controller's list) on the host page, each behind a confirm; controller_unresponsive (R-1344, alarm only); 04 §6.1 + 09 §3 decision 283; wire gate declares both new wires; R-1344 filed — tests red first
gates / gates (push) Successful in 3m23s
gates / gates (push) Successful in 3m23s
This commit is contained in:
1 parent
70862fa7b3
commit
3d0c907b56
20 files changed
+663
-20
No files matched your search
@@ -18,6 +18,18 @@ type heldAppRow struct {
|
||||
WhoClears string
|
||||
Reminded bool
|
||||
Stale bool // the box has not repeated it for heldAppStale — it may be down
|
||||
// ProtectsData (D64 = B): a restore or put-back hold — the confirm step warns before „Clear hold" (`07` §8).
|
||||
ProtectsData bool
|
||||
}
|
||||
|
||||
// holdProtectsData: the reasons whose hold keeps an app off half-restored data (`07` §8): a failed restore (the
|
||||
// reason is "" or restore_failed on older rows), a mixed restore, a put-back waiting for its drive.
|
||||
func holdProtectsData(reason string) bool {
|
||||
switch reason {
|
||||
case "", "restore_failed", "restore_mixed", "putback_pending":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// heldAppStaleAfter mirrors monitor's heldAppStale: a box repeats app_held daily.
|
||||
@@ -51,7 +63,7 @@ func toHeldAppRows(held []store.HeldApp, hostOf map[string]string, now time.Time
|
||||
}
|
||||
out = append(out, heldAppRow{CustomerID: h.CustomerID, HostID: hostOf[h.CustomerID], Stack: h.Stack, Reason: h.Reason,
|
||||
Since: since, Why: h.Why, WhoClears: monitor.HeldAppWhoClears(h.Reason), Reminded: !h.RemindedAt.IsZero(),
|
||||
Stale: now.Sub(h.LastSeen) > heldAppStaleAfter})
|
||||
Stale: now.Sub(h.LastSeen) > heldAppStaleAfter, ProtectsData: holdProtectsData(h.Reason)})
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
||||
)
|
||||
|
||||
// Operator brief 2026-10-29: „Restart controller" (the AGENT's closed list) and „Clear hold" (D64 = B, the
|
||||
// controller's list) on the host page — each behind a confirm step, CSRF like every form.
|
||||
|
||||
func heldFixture(t *testing.T) (*Server, *store.Store) {
|
||||
t.Helper()
|
||||
s, st := newTestServer(t)
|
||||
if err := st.UpsertHost(&store.Host{HostID: "h1", CustomerID: "c1", APIKey: "k"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now()
|
||||
if err := st.UpsertGuestFromReport(&store.Guest{GuestID: "h1-9201", CustomerID: "c1", HostID: "h1", VMID: 9201, DisplayName: "felhom",
|
||||
Status: "running", ControllerVersion: "0.347.0", LastSeenAt: &now}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := st.UpsertHeldApp("c1", "radicale", "restore_mixed", now.Add(-time.Hour), "a restore stopped half-way", now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := st.UpsertHeldApp("c1", "gokapi", "unhealthy_stop", now.Add(-time.Hour), "stopped in a crash loop", now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return s, st
|
||||
}
|
||||
|
||||
// RED-PROOF: seen failing before the forms existed.
|
||||
func TestHostPage_RestartAndClearHoldRenderBehindAConfirm(t *testing.T) {
|
||||
s, _ := heldFixture(t)
|
||||
body := renderHost(t, s, "h1")
|
||||
for _, want := range []string{
|
||||
`data-restart-controller="9201"`, `name="action" value="restart_controller"`, `name="arg" value="9201"`,
|
||||
"Restart the controller of guest 9201 on h1 (c1)?",
|
||||
`data-clear-hold="radicale"`, `name="action" value="clear_hold"`, `name="arg" value="radicale"`,
|
||||
"This hold protects data from a failed restore. If you clear it, the app may start on half-restored data. Check the restore copy first.",
|
||||
`data-clear-hold="gokapi"`,
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("host page lacks %q", want)
|
||||
}
|
||||
}
|
||||
// the warning only on the data-protecting hold
|
||||
gk := body[strings.Index(body, `data-clear-hold="gokapi"`):]
|
||||
gk = gk[:strings.Index(gk, "</details>")]
|
||||
if strings.Contains(gk, "half-restored") {
|
||||
t.Error("a crash-loop hold shows the restore warning")
|
||||
}
|
||||
if !strings.Contains(gk, "unhealthy_stop") {
|
||||
t.Error("the confirm step does not name the hold's reason")
|
||||
}
|
||||
}
|
||||
|
||||
// restart_controller: a row for the AGENT of this host (never the controller's ACK); clear_hold only for an app that
|
||||
// IS held; every other verb or argument refused with no row. RED-PROOF: seen failing before the handler routed them.
|
||||
func TestHostPage_RestartAndClearHoldPosts(t *testing.T) {
|
||||
s, st := heldFixture(t)
|
||||
if rr := postOperatorAction(t, s, "h1", url.Values{"action": {"restart_controller"}, "arg": {"9201"}}); rr.Code != http.StatusSeeOther {
|
||||
t.Fatalf("restart: %d %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
if a, _ := st.PendingHostOperatorActions("h1"); len(a) != 1 || a[0].Arg != "9201" {
|
||||
t.Fatalf("the agent's reply would list %+v", a)
|
||||
}
|
||||
if c, _ := st.PendingOperatorActions("c1"); len(c) != 0 {
|
||||
t.Fatalf("the restart reached the controller's ACK: %+v", c)
|
||||
}
|
||||
if rr := postOperatorAction(t, s, "h1", url.Values{"action": {"clear_hold"}, "arg": {"radicale"}}); rr.Code != http.StatusSeeOther {
|
||||
t.Fatalf("clear_hold: %d %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
if c, _ := st.PendingOperatorActions("c1"); len(c) != 1 || c[0].Action != "clear_hold" || c[0].Arg != "radicale" {
|
||||
t.Fatalf("the controller's ACK would list %+v", c)
|
||||
}
|
||||
for _, f := range []url.Values{
|
||||
{"action": {"clear_hold"}, "arg": {"vikunja"}}, // not held
|
||||
{"action": {"restart_controller"}, "arg": {"9202"}}, // not a guest of this host
|
||||
{"action": {"restart_controller"}, "arg": {"abc"}},
|
||||
{"action": {"reboot_guest"}, "arg": {"9201"}},
|
||||
} {
|
||||
if rr := postOperatorAction(t, s, "h1", f); rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("%v: status %d, want 400", f, rr.Code)
|
||||
}
|
||||
}
|
||||
if rows, _ := st.ListOperatorActions("c1", 20); len(rows) != 2 {
|
||||
t.Fatalf("rows = %d, want the two accepted presses only", len(rows))
|
||||
}
|
||||
}
|
||||
@@ -174,11 +174,17 @@ func TestHandleHostDetail(t *testing.T) {
|
||||
// Decision 185 (2026-10-08): plus the four operator-action buttons — a closed list, none of which
|
||||
// deletes or mutates the host (TestOperatorActions_* pin what they may do). Every OTHER button
|
||||
// remains absent: 2 log requests + 4 operator actions, and the 4 all post to /operator-action.
|
||||
if got := strings.Count(strings.ToLower(body), "<button"); got != 6 {
|
||||
t.Errorf("host detail has %d buttons, want exactly the 2 log-request + 4 operator-action buttons", got)
|
||||
// 2026-10-29 (operator brief, Part 1): plus ONE „Restart controller" per guest that runs a controller (the AGENT's
|
||||
// closed list, behind a confirm step; this fixture has one such guest). „Clear hold" appears only per held app (none
|
||||
// here). No other button.
|
||||
if got := strings.Count(strings.ToLower(body), "<button"); got != 7 {
|
||||
t.Errorf("host detail has %d buttons, want exactly the 2 log-request + 4 operator-action + 1 restart-controller buttons", got)
|
||||
}
|
||||
if got := strings.Count(body, `action="/hosts/demo-felhom-01/operator-action"`); got != 4 {
|
||||
t.Errorf("operator-action forms = %d, want 4", got)
|
||||
if got := strings.Count(body, `action="/hosts/demo-felhom-01/operator-action"`); got != 5 {
|
||||
t.Errorf("operator-action forms = %d, want 5", got)
|
||||
}
|
||||
if got := strings.Count(body, `value="restart_controller"`); got != 1 {
|
||||
t.Errorf("restart_controller forms = %d, want 1 (one guest with a controller)", got)
|
||||
}
|
||||
if strings.Count(body, `action="/hosts/demo-felhom-01/request-logs"`) != 2 {
|
||||
t.Error("the request-logs forms are missing — every button must be a log-bundle request")
|
||||
|
||||
@@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
||||
@@ -42,11 +43,22 @@ func (s *Server) handleOperatorAction(w http.ResponseWriter, r *http.Request, ho
|
||||
}
|
||||
action := strings.TrimSpace(r.FormValue("action"))
|
||||
arg := strings.TrimSpace(r.FormValue("arg"))
|
||||
// The AGENT's closed list (2026-10-29): its own channel, the host report's reply.
|
||||
if store.IsHostOperatorAction(action) {
|
||||
s.handleHostOperatorAction(w, r, host, action, arg)
|
||||
return
|
||||
}
|
||||
if err := store.ValidateOperatorAction(action, arg); err != nil {
|
||||
s.logger.Printf("[INFO] operator action refused for host %s: %v", hostID, err)
|
||||
http.Error(w, "Refused: "+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// D64 = B: Clear hold only for an app the box reports held now — a stale page or a typo stores nothing.
|
||||
if action == store.OperatorActionClearHold && !s.customerHoldsApp(host.CustomerID, arg) {
|
||||
s.logger.Printf("[INFO] clear_hold refused for host %s: %s is not held on this box", hostID, arg)
|
||||
http.Error(w, "Refused: "+arg+" is not held on this box", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
by := operatorActor(r)
|
||||
id, err := s.store.CreateOperatorAction(host.CustomerID, action, arg, by)
|
||||
if err != nil {
|
||||
@@ -80,3 +92,58 @@ func (s *Server) hostOperatorActionRows(host *store.Host) []store.OperatorAction
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// customerHoldsApp reports whether the box's held-apps mirror lists the app now.
|
||||
func (s *Server) customerHoldsApp(customerID, app string) bool {
|
||||
held, err := s.store.ListHeldApps(customerID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, h := range held {
|
||||
if h.Stack == app {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// handleHostOperatorAction stores an AGENT row (the agent's closed list) and pokes the box, so its out-of-cycle
|
||||
// report carries the action in seconds; the result comes on the report after (the agent requests it at once).
|
||||
// restart_controller names a guest of THIS host — another vmid is refused before anything is stored.
|
||||
func (s *Server) handleHostOperatorAction(w http.ResponseWriter, r *http.Request, host *store.Host, action, arg string) {
|
||||
if err := store.ValidateHostOperatorAction(action, arg); err != nil {
|
||||
s.logger.Printf("[INFO] host operator action refused for host %s: %v", host.HostID, err)
|
||||
http.Error(w, "Refused: "+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if !s.hostHasGuest(host.HostID, arg) {
|
||||
s.logger.Printf("[INFO] host operator action %s refused for host %s: guest %s is not on this host", action, host.HostID, arg)
|
||||
http.Error(w, "Refused: guest "+arg+" is not on this host", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
by := operatorActor(r)
|
||||
id, err := s.store.CreateHostOperatorAction(host.CustomerID, host.HostID, action, arg, by)
|
||||
if err != nil {
|
||||
s.logger.Printf("[ERROR] host operator action %s for %s: %v", action, host.HostID, err)
|
||||
http.Error(w, "Internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
s.logger.Printf("[INFO] host operator action #%d %s%s requested for host %s by %s — the agent acts on its next report (poked now)",
|
||||
id, action, opArgSuffix(arg), host.HostID, by)
|
||||
s.poke.PokeHost(host.HostID) // nil-safe; without the tunnel the 15-min cycle carries it
|
||||
http.Redirect(w, r, "/hosts/"+host.HostID+"#operator-actions", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// hostHasGuest reports whether vmid is one of the host's guests as its reports name them.
|
||||
func (s *Server) hostHasGuest(hostID, vmid string) bool {
|
||||
guests, err := s.store.ListGuestsForHost(hostID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, g := range guests {
|
||||
if strconv.Itoa(g.VMID) == vmid {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -133,7 +133,19 @@
|
||||
<td>{{.VMID}}</td>
|
||||
<td>{{if .DisplayName}}{{.DisplayName}}{{else}}—{{end}}</td>
|
||||
<td>{{if eq .Status "running"}}<span style="color: var(--green)">{{.Status}}</span>{{else if eq .Status "stopped"}}<span style="color: var(--red)">{{.Status}}</span>{{else}}{{.Status}}{{end}}</td>
|
||||
<td>{{if .ControllerVersion}}<code>{{.ControllerVersion}}</code>{{else}}—{{end}}</td>
|
||||
<td>{{if .ControllerVersion}}<code>{{.ControllerVersion}}</code>{{else}}—{{end}}
|
||||
{{if and .ControllerVersion $.CustomerID}}{{/* 2026-10-29: the AGENT restarts it (the supervisor's act and guards; 3 in 15 min, then refused for 30) — works with the controller stopped */}}
|
||||
<details class="op-confirm" data-restart-controller="{{.VMID}}">
|
||||
<summary class="btn btn-sm btn-outline">Restart controller</summary>
|
||||
<form method="POST" action="/hosts/{{$.HostID}}/operator-action">
|
||||
<input type="hidden" name="_csrf" value="{{$.CSRFToken}}">
|
||||
<input type="hidden" name="action" value="restart_controller">
|
||||
<input type="hidden" name="arg" value="{{.VMID}}">
|
||||
<p>Restart the controller of guest {{.VMID}} on {{$.HostID}} ({{$.CustomerID}})? The box's agent restarts it, even when the controller does not answer. The household's dashboard is away for about a minute. At most 3 restarts in 15 minutes; the result shows under Operator Actions.</p>
|
||||
<button type="submit" class="btn btn-sm btn-danger">Restart the controller</button>
|
||||
</form>
|
||||
</details>{{end}}
|
||||
</td>
|
||||
<td>{{timeAgoPtr .LastSeenAt}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
@@ -146,7 +158,8 @@
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<!-- Held apps (D53, `08` §10): apps the box keeps stopped until a person acts. The hub never clears one. -->
|
||||
<!-- Held apps (D53, `08` §10): apps the box keeps stopped until a person acts. D64 = B (operator 2026-10-29): the
|
||||
operator may clear any hold here; the confirm step shows the reason and, for a data-protecting hold, a warning. -->
|
||||
<section class="card" id="held-apps" style="padding: 0; overflow: hidden;">
|
||||
<h2 style="padding: 1.25rem 1.25rem 0.5rem;">Held apps</h2>
|
||||
{{if .HeldApps}}
|
||||
@@ -167,7 +180,19 @@
|
||||
<td><span class="severity-badge severity-warning">{{.Reason}}</span>{{if .Stale}} <span class="text-muted">(not confirmed by the box for 2 days)</span>{{end}}</td>
|
||||
<td>{{timeAgo .Since}}</td>
|
||||
<td>{{.Why}}</td>
|
||||
<td>{{.WhoClears}}{{if .Reminded}} <span class="text-muted">(operator reminded)</span>{{end}}</td>
|
||||
<td>{{.WhoClears}}{{if .Reminded}} <span class="text-muted">(operator reminded)</span>{{end}}
|
||||
<details class="op-confirm" data-clear-hold="{{.Stack}}">
|
||||
<summary class="btn btn-sm btn-outline">Clear hold</summary>
|
||||
<form method="POST" action="/hosts/{{$.HostID}}/operator-action">
|
||||
<input type="hidden" name="_csrf" value="{{$.CSRFToken}}">
|
||||
<input type="hidden" name="action" value="clear_hold">
|
||||
<input type="hidden" name="arg" value="{{.Stack}}">
|
||||
<p>Clear the hold of <code>{{.Stack}}</code> ({{.Reason}}, since {{.Since.Format "2006-01-02 15:04"}})? The box's controller clears it at once; the household can then start the app.</p>
|
||||
{{if .ProtectsData}}<p class="op-warning">This hold protects data from a failed restore. If you clear it, the app may start on half-restored data. Check the restore copy first.</p>{{end}}
|
||||
<button type="submit" class="btn btn-sm btn-danger">Clear the hold</button>
|
||||
</form>
|
||||
</details>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
|
||||
@@ -1031,3 +1031,10 @@ body.js-tabs .tab-panel:not(.tab-panel-active) { display: none; }
|
||||
}
|
||||
.mail-hold-release .text-muted { font-size: 0.8rem; }
|
||||
#mail-hold a { color: var(--text-1); }
|
||||
|
||||
/* 2026-10-29: the confirm fold-out of „Restart controller" and „Clear hold" (no script; the final button is inside). */
|
||||
.op-confirm { margin-top: 0.35rem; }
|
||||
.op-confirm summary { list-style: none; display: inline-block; cursor: pointer; }
|
||||
.op-confirm form { margin-top: 0.5rem; max-width: 34rem; }
|
||||
.op-confirm p { font-size: 0.85rem; margin: 0.25rem 0 0.5rem; }
|
||||
.op-warning { color: var(--warn); }
|
||||
Reference in new issue
Block a user