gates / gates (push) Successful in 47s
R-1124: ForgetRetiredDrives (start-up + the 20 s tick) disables and removes the host mount unit of a DECOMMISSIONED drive whose disk is absent and unmounted; the agent then no longer lists it. A present decommissioned drive keeps its unit (one-click re-enroll). The file goes only through the new felhom-priv-apply verb `unit-forget`, which re-checks marker, disabled, unmounted and absent as root. R-1012: the read-only root helper felhom-thin-check <vg> <pool> (bundle) lists the pool's thin ids (metadata snapshot reserved and released) next to LVM's before and after. BackupRunner.SetThinCheck runs it before a snapshot-mode backup (log) and again after a failure, appending the finding in plain words to the error the controller mails to the operator. Two reads, intersected; fails open; never removes. Red-proofs: felhom.eu audits/agent-allowlist-rotation-2026-10-17/P1/. Code only; the CHANGELOG entry follows the release. Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
65 lines
2.8 KiB
Go
65 lines
2.8 KiB
Go
package backup
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-agent/internal/proxmox"
|
|
)
|
|
|
|
// R-1012: a snapshot backup that fails carries the orphan finding in its error — the text the controller mails to
|
|
// the operator (`whole_guest_backup_failed`). The check runs once before the run and once, FRESH, after the failure.
|
|
// RED-PROOF (P1/redproof-thincheck.txt): with explainFailure's append removed this test fails.
|
|
func TestBackup_SnapshotFailure_NamesTheOrphan(t *testing.T) {
|
|
const why = "probable cause: thin pool pve/data holds device 4 that LVM does not know"
|
|
for name, api := range map[string]*fakeBackupAPI{
|
|
"task fails": {vzdumpUPID: "UPID:x", waitErr: errors.New("task failed: job errors")},
|
|
"start fails": {vzdumpErr: errors.New("vzdump: 500")},
|
|
} {
|
|
t.Run(name, func(t *testing.T) {
|
|
r := NewBackupRunner(api, "local", "", "", "", quiet())
|
|
calls := 0
|
|
r.SetThinCheck(func(context.Context, int) string { calls++; return why })
|
|
rec, err := r.Backup(context.Background(), 9201)
|
|
if err == nil || rec.Success {
|
|
t.Fatalf("want a failure, got %+v", rec)
|
|
}
|
|
if !strings.Contains(rec.Error, why) {
|
|
t.Fatalf("the failure does not name the orphan: %q", rec.Error)
|
|
}
|
|
if calls != 2 {
|
|
t.Fatalf("thin check ran %d times, want 2 (before the run and after the failure)", calls)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// A successful backup keeps a clean record (the pre-check only logs); a stop-mode backup takes no snapshot, so the
|
|
// check never runs; an unwired runner behaves exactly as before.
|
|
func TestBackup_ThinCheck_SilentWhenNotApplicable(t *testing.T) {
|
|
ok := &fakeBackupAPI{vzdumpUPID: "UPID:x",
|
|
content: []proxmox.StorageContent{{VolID: "local:backup/vzdump-lxc-9201-x", Content: "backup", VMID: 9201, Size: 100, CTime: 1}}}
|
|
r := NewBackupRunner(ok, "local", "", "", "", quiet())
|
|
calls := 0
|
|
r.SetThinCheck(func(context.Context, int) string { calls++; return "probable cause: x" })
|
|
rec, err := r.Backup(context.Background(), 9201)
|
|
if err != nil || !rec.Success || rec.Error != "" || calls != 1 {
|
|
t.Fatalf("success: err=%v rec=%+v calls=%d (want one pre-check, clean record)", err, rec, calls)
|
|
}
|
|
|
|
stop := NewBackupRunner(&fakeBackupAPI{vzdumpUPID: "UPID:x", waitErr: errors.New("boom")}, "local", proxmox.ModeStop, "", "", quiet())
|
|
calls = 0
|
|
stop.SetThinCheck(func(context.Context, int) string { calls++; return "probable cause: x" })
|
|
rec, _ = stop.Backup(context.Background(), 9201)
|
|
if calls != 0 || strings.Contains(rec.Error, "probable cause") {
|
|
t.Fatalf("stop mode: calls=%d error=%q", calls, rec.Error)
|
|
}
|
|
|
|
plain := NewBackupRunner(&fakeBackupAPI{vzdumpUPID: "UPID:x", waitErr: errors.New("boom")}, "local", "", "", "", quiet())
|
|
if rec, _ := plain.Backup(context.Background(), 9201); rec.Error != "boom" {
|
|
t.Fatalf("unwired: error = %q, want the task error unchanged", rec.Error)
|
|
}
|
|
}
|