hub 0.177.0: Reboot guest on the host page (D65 = A, reboot_guest in the agent's closed list, 30-minute expiry); R-1346: the slow-request line and the vouch save's per-leg timing
gates / gates (push) Successful in 1m52s
gates / gates (push) Successful in 1m52s
This commit is contained in:
1 parent
dd3e4137ee
commit
636022dc31
10 files changed
+223
-16
No files matched your search
@@ -38,6 +38,13 @@ const (
|
||||
// HostOperatorActionRestartController (operator brief 2026-10-29, Part 1): the AGENT restarts a guest's controller
|
||||
// (the supervisor's own act and guards). The agent's list holds this one verb.
|
||||
HostOperatorActionRestartController = "restart_controller"
|
||||
// HostOperatorActionRebootGuest (D65 = A, operator ruling 2026-10-29 15:50; `04` §6.1): the AGENT reboots one guest
|
||||
// (`pct reboot` of THAT guest, never the host) with its own guards — no backup, restore, update or swap; at most
|
||||
// once an hour; the restart brake. No signature: a reboot destroys nothing.
|
||||
HostOperatorActionRebootGuest = "reboot_guest"
|
||||
// HostOperatorActionRebootTTL: a reboot the agent did not pick up in 30 minutes expires — a box that was off must not
|
||||
// reboot by itself when it comes back hours later.
|
||||
HostOperatorActionRebootTTL = 30 * time.Minute
|
||||
|
||||
// Outcomes: the box's three, plus two the hub sets itself.
|
||||
OperatorActionDone = "done"
|
||||
@@ -64,7 +71,7 @@ var operatorActionNames = []string{OperatorActionOffsiteBackupNow, OperatorActio
|
||||
|
||||
// hostOperatorActionNames is the AGENT's closed list (the host report's reply). Pinned by
|
||||
// TestHostOperatorActions_ClosedList; never shares a verb with the controller's list.
|
||||
var hostOperatorActionNames = []string{HostOperatorActionRestartController}
|
||||
var hostOperatorActionNames = []string{HostOperatorActionRestartController, HostOperatorActionRebootGuest}
|
||||
|
||||
// stackNameRe is an app's stack name as the controller names it (a catalog slug).
|
||||
var stackNameRe = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]{0,63}$`)
|
||||
@@ -75,11 +82,11 @@ func HostOperatorActionNames() []string { return sortedStrings(hostOperatorActio
|
||||
// IsHostOperatorAction reports whether the verb belongs to the agent's list.
|
||||
func IsHostOperatorAction(action string) bool { return inList(hostOperatorActionNames, action) }
|
||||
|
||||
// ValidateHostOperatorAction refuses anything outside the agent's closed list. restart_controller takes the guest's
|
||||
// vmid (Proxmox: 100–999999999).
|
||||
// ValidateHostOperatorAction refuses anything outside the agent's closed list. Both verbs take the guest's vmid
|
||||
// (Proxmox: 100–999999999).
|
||||
func ValidateHostOperatorAction(action, arg string) error {
|
||||
switch action {
|
||||
case HostOperatorActionRestartController:
|
||||
case HostOperatorActionRestartController, HostOperatorActionRebootGuest:
|
||||
v, err := strconv.Atoi(arg)
|
||||
if err != nil || strconv.Itoa(v) != arg || v < 100 || v > 999999999 {
|
||||
return fmt.Errorf("the guest id must be a number 100-999999999")
|
||||
@@ -215,6 +222,12 @@ func (s *Store) PendingHostOperatorActions(hostID string) ([]OperatorActionDirec
|
||||
now, OperatorActionExpired, "the agent did not answer within a day", hostID, now.Add(-OperatorActionTTL)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := s.db.Exec(`UPDATE operator_actions SET done_at = ?, outcome = ?, message = ?
|
||||
WHERE host_id = ? AND action = ? AND done_at IS NULL AND requested_at < ?`,
|
||||
now, OperatorActionExpired, "the agent did not pick the reboot up within 30 minutes — press again if it is still needed",
|
||||
hostID, HostOperatorActionRebootGuest, now.Add(-HostOperatorActionRebootTTL)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows, err := s.db.Query(`SELECT id, action, arg FROM operator_actions
|
||||
WHERE host_id = ? AND done_at IS NULL ORDER BY id LIMIT ?`, hostID, operatorActionsListed)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,6 +2,7 @@ package store
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -110,9 +111,10 @@ func TestOperatorActions_ExpireAndResetCancel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The AGENT's closed list (operator brief 2026-10-29, Part 1): one verb. RED-PROOF: seen failing before the list existed.
|
||||
// The AGENT's closed list (operator brief 2026-10-29, Part 1; D65 = A adds reboot_guest). RED-PROOF: seen failing before
|
||||
// the list existed, and again before reboot_guest joined it.
|
||||
func TestHostOperatorActions_ClosedList(t *testing.T) {
|
||||
if got, want := HostOperatorActionNames(), []string{"restart_controller"}; !reflect.DeepEqual(got, want) {
|
||||
if got, want := HostOperatorActionNames(), []string{"reboot_guest", "restart_controller"}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("host operator actions = %v, want exactly %v — a new verb needs the operator's word", got, want)
|
||||
}
|
||||
for _, a := range OperatorActionNames() {
|
||||
@@ -127,8 +129,8 @@ func TestHostOperatorActions_RefusedBeforeStoring(t *testing.T) {
|
||||
s := newTestStore(t)
|
||||
bad := []struct{ action, arg string }{
|
||||
{"restart_controller", ""}, {"restart_controller", "abc"}, {"restart_controller", "99"}, {"restart_controller", "9201 "},
|
||||
{"restart_controller", "-1"}, {"restart_controller", "10000000000"}, {"reboot_guest", "9201"}, {"clear_hold", "radicale"},
|
||||
{"offsite_backup_now", ""},
|
||||
{"restart_controller", "-1"}, {"restart_controller", "10000000000"}, {"reboot_host", "9201"}, {"clear_hold", "radicale"},
|
||||
{"offsite_backup_now", ""}, {"reboot_guest", ""}, {"reboot_guest", "abc"}, {"reboot_guest", "99"},
|
||||
}
|
||||
for _, b := range bad {
|
||||
if _, err := s.CreateHostOperatorAction("c1", "h1", b.action, b.arg, "operator"); err == nil {
|
||||
@@ -147,6 +149,31 @@ func TestHostOperatorActions_RefusedBeforeStoring(t *testing.T) {
|
||||
if _, err := s.CreateHostOperatorAction("c1", "h1", "restart_controller", "9201", "operator"); err != nil {
|
||||
t.Fatalf("restart_controller 9201 refused: %v", err)
|
||||
}
|
||||
if _, err := s.CreateHostOperatorAction("c1", "h1", "reboot_guest", "9201", "operator"); err != nil {
|
||||
t.Fatalf("reboot_guest 9201 refused: %v", err)
|
||||
}
|
||||
if _, err := s.CreateOperatorAction("c1", "reboot_guest", "9201", "operator"); err == nil {
|
||||
t.Error("reboot_guest reached the controller's list")
|
||||
}
|
||||
}
|
||||
|
||||
// D65 = A: a reboot the agent has not picked up in 30 minutes expires — a box that was off must not reboot by itself
|
||||
// when it comes back hours later. A restart keeps the day. RED-PROOF: drop the reboot TTL → the 31-minute-old reboot is
|
||||
// still listed → FAILS.
|
||||
func TestHostOperatorActions_ARebootExpiresAfter30Minutes(t *testing.T) {
|
||||
s := newTestStore(t)
|
||||
rb, _ := s.CreateHostOperatorAction("c1", "h1", "reboot_guest", "9201", "operator")
|
||||
rs, _ := s.CreateHostOperatorAction("c1", "h1", "restart_controller", "9201", "operator")
|
||||
if _, err := s.db.Exec(`UPDATE operator_actions SET requested_at = ? WHERE id IN (?, ?)`, time.Now().UTC().Add(-31*time.Minute), rb, rs); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p, _ := s.PendingHostOperatorActions("h1")
|
||||
if len(p) != 1 || p[0].ID != rs {
|
||||
t.Fatalf("pending = %+v, want only the restart #%d", p, rs)
|
||||
}
|
||||
if r, _ := s.getOperatorAction(rb); r == nil || r.Outcome != OperatorActionExpired || !strings.Contains(r.Message, "30 minutes") {
|
||||
t.Fatalf("the old reboot = %+v, want expired, naming 30 minutes", r)
|
||||
}
|
||||
}
|
||||
|
||||
// An agent row reaches only its host's envelope, a controller row only the customer's ACK; a result closes only a row of
|
||||
|
||||
Reference in new issue
Block a user