carlos / platform Public

host: __ingress-drain, and apply and rollback ask for the drain

W6 spec 5.2 and 5.3. The drain-call child gains an ingress op (no
transaction, no peers) that asks the agent's socket for the ingress
drain as the agent's user; a 404 is now no_route. __ingress-drain, the
drain unit's ExecStop, runs as the agent's user, prints one line (the
report, or why there is none) and exits 0 in every case.

apply asks after its refusals and preflight, before the journal, the
quiesce and the swap; rollback asks after the restore's refusals and
before its quiesce. No-ops, refusals and recovery ask nothing. Nothing
the agent answers stops the verb. A transition test pins the first
roll onto W6: a gate failure rolls back undrained and the box serves.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f42b6adea475c1b0883046586dfe3d5d80c04a01 parent c74af0b
15 files changed, +690 −27
  • commands.go +7 −0
  • commands_test.go +2 −2
  • internal/host/execsandboxfloor_test.go +1 −1
  • internal/host/group_maintenance_test.go +1 −1
  • internal/host/hadrain_call.go +103 −11
  • internal/host/hadrain_call_linux.go +16 −1
  • internal/host/hadrain_call_other.go +12 −0
  • internal/host/hadrain_socket.go +17 −0
  • internal/host/ingressdrain_call_linux_test.go +192 −0
  • internal/host/rootmovesfloor_refresh_test.go +1 −1
  • internal/host/systemapply.go +48 −4
  • internal/host/systemapply_ingress_test.go +282 −0
  • internal/host/systemapply_test.go +6 −6
  • parity/cli.tsv +1 −0
  • testdata/clireg-golden.jsonl +1 −0

Intent

Human

<task-notification> <task-id>a6ad6f58e17960e42</task-id> <tool-use-id>toolu_01BANYYj2LhGbRqxqw1WD6ej</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a373aecd-faa9-4b83-8736-ff726fb2d3af/tasks/a6ad6f58e17960e42.output</output-file> <status>completed</status> <summary>Agent "Implement W6 Tasks 4+5 (driver)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE. All three review findings are fixed and committed. The package won't build in the shared worktree right now because of Task 6's unfinished edits, so I tested my code against HEAD. Commit: `c74af0b7` host: ingress drain fix round 1: step times, cap from request, exit lock. The same `packed-refs.lock` warning appeared again, but the commit is on the branch. 1. **Shared timestamps:** each step now gets its own time value, set under the lock. 2. **Cap:** it counts from the request. A withdrawn answer first read at or after 90 s starts no settle and ends unverified. Building the reader, the retention read and every poll each answer within 5 s, even if the call hangs. 3. **Exit vs shutdown:** the exit decision and `exit(1)` hold the same lock as `shutdownStarted`, so the two can't overlap. Tests: the five new tests plus all drain and socket tests pass under `-race`. `go vet` and the darwin and windows builds of `internal/host` are clean. Against the old driver, four of the five new tests fail. The cap-from-request test passes there too, so it only pins the behaviour. The Minor finding is left as you asked. Concerns: - **Shared files.** Task 6 is editing `internal/host` in this worktree, including `hadrain_socket.go`, which I committed earlier, and its unfinished code doesn't build. So every run used `go test -overlay`, with each file I don't own pinned to HEAD. Task 6 needs a full rerun of these tests after it lands. I committed only my three files. - **Helper rename.** Task 6's new test file also declares `ingressAsk`, so I renamed my test helper to `ingressRouteAsk`. Report (fix round appended): `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/w6-build/.superpowers/sdd/2026-11-10-fixed-edge-ingress-drain/task-4-5-report.md`</result> <usage><subagent_tokens>195823</subagent_tokens><tool_uses>13</tool_uses><duration_ms>450921</duration_ms></usage> </task-notification>

Attributed to this commit: 10.1 g CO₂e (1,267,137 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on w6-ingress-drain, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/commands.go b/commands.go
index 8a579109f..b5c0b8eb2 100644
--- a/commands.go
+++ b/commands.go
@@ -80,6 +80,9 @@ func buildCommandRoot() *clireg.Node {
// The drain verbs' agent call, run as the agent's user
// (internal/host/hadrain_call.go): plumbing, never typed.
plumbing("__drain-call", runDrainCallTop),
+ // The ingress drain unit's ExecStop, run as the agent's user
+ // (internal/host/hadrain_call.go, W6 spec §5.2): exits 0 always.
+ plumbing("__ingress-drain", runIngressDrainTop),
noHint(plumbing("__registry-child", runRegistryChildTop)),
// carlos ship --check's health probe, run inside the web container
// (ship_check_probe.go): plumbing, not a command anyone types.
@@ -233,6 +236,10 @@ func runDrainCallTop(args []string) {
os.Exit(host.RunDrainCall(args, os.Stdout))
}
+func runIngressDrainTop(args []string) {
+ os.Exit(host.RunIngressDrain(args, os.Stdout))
+}
+
func runRegistryChildTop(args []string) {
if err := host.RunRegistryChild(args); err != nil {
log.Fatal(err)
diff --git a/commands_test.go b/commands_test.go
index 9a28c9f99..d6f6c865b 100644
--- a/commands_test.go
+++ b/commands_test.go
@@ -17,13 +17,13 @@ func TestCommandTreeIsValid(t *testing.T) {
}
// TestTopLevelWordsUnchanged pins the words main dispatched on before the
-// tree (the switch's cases, the five __ words checked before it, and the
+// tree (the switch's cases, the six __ words checked before it, and the
// cgroup shim's two words), written out so a word cannot appear or vanish
// without this list changing too.
func TestTopLevelWordsUnchanged(t *testing.T) {
want := []string{
// The __ plumbing words main.go checked before its switch.
- "__demo-snapshot", "__drain-call", "__registry-child",
+ "__demo-snapshot", "__drain-call", "__ingress-drain", "__registry-child",
"__rootfs-check-probe", "__rootfs-check-prepare",
// cgroup.RunShimIfRequested's words.
"__cgexec", "__cgprobe",
diff --git a/internal/host/execsandboxfloor_test.go b/internal/host/execsandboxfloor_test.go
index f40b82f73..e7763fe25 100644
--- a/internal/host/execsandboxfloor_test.go
+++ b/internal/host/execsandboxfloor_test.go
@@ -123,7 +123,7 @@ func TestExecSandboxFloorNoMutation(t *testing.T) {
}
before, _ := os.ReadFile(systemBinaryPath(f.a.optDir))
calls := len(f.calls)
- if _, err := f.a.restoreFiles(context.Background(), &systemJournal{}); err == nil {
+ if _, err := f.a.restoreFiles(context.Background(), &systemJournal{}, false); err == nil {
t.Fatal("restore allowed")
}
after, _ := os.ReadFile(systemBinaryPath(f.a.optDir))
diff --git a/internal/host/group_maintenance_test.go b/internal/host/group_maintenance_test.go
index 42e092e16..0d759c22c 100644
--- a/internal/host/group_maintenance_test.go
+++ b/internal/host/group_maintenance_test.go
@@ -40,7 +40,7 @@ func TestGroupMaintenanceRestartGuard(t *testing.T) {
case "rollback":
err = f.a.rollback(t.Context(), systemRequest{}, "test", &systemJournal{})
case "restore":
- _, err = f.a.restoreFiles(t.Context(), &systemJournal{})
+ _, err = f.a.restoreFiles(t.Context(), &systemJournal{}, false)
case "recovery":
_, err = f.a.recoverIfNeeded(t.Context())
case "install-channel":
diff --git a/internal/host/hadrain_call.go b/internal/host/hadrain_call.go
index e3778298a..517d292f2 100644
--- a/internal/host/hadrain_call.go
+++ b/internal/host/hadrain_call.go
@@ -25,15 +25,23 @@ package host
// the agent because a running agent that holds drain state keeps its own
// start gate closed (haDrainState.startClosed) until its own cancel, and an
// agent that restarts holds none.
+//
+// The same child carries the fixed box's ingress drain for apply and
+// rollback (W6 spec §5.3): op ingress, transaction "-", answered with the
+// agent's ingress report. The drain unit's ExecStop reaches the same route
+// without root, already as the agent's user (__ingress-drain,
+// ingressDrainEntry below).
import (
"bytes"
"context"
"encoding/json"
"errors"
+ "fmt"
"io"
"regexp"
"strings"
+ "time"
)
// maxDrainPeers bounds the boxes one drain request names (the verb's
@@ -100,10 +108,14 @@ type drainCallResult struct {
// AgentDown: the socket did not accept the child's dial (no agent, or
// one whose socket is not serving).
AgentDown bool `json:"agent_down,omitempty"`
+ // NoRoute: the socket answered 404, from an agent older than the route
+ // asked for.
+ NoRoute bool `json:"no_route,omitempty"`
// Error is the call's failure, agent text included.
- Error string `json:"error,omitempty"`
- Report *drainReport `json:"report,omitempty"`
- Status *drainStatus `json:"status,omitempty"`
+ Error string `json:"error,omitempty"`
+ Report *drainReport `json:"report,omitempty"`
+ Status *drainStatus `json:"status,omitempty"`
+ Ingress *ingressReport `json:"ingress,omitempty"`
}
// err is the call's failure as an error.
@@ -118,7 +130,7 @@ func (r drainCallResult) err() error {
}
// drainCaller makes one call of the agent's drain socket: op is withdraw,
-// move, cancel or status. peers is withdraw's and move's acknowledgement
+// move, cancel, status or ingress. peers is withdraw's and move's acknowledgement
// population as the verb passed it, nil when it passed none (the agent
// then refuses the step). A transport failure of the caller itself (the
// child did not run or answered nothing usable) is the error; the agent's
@@ -127,7 +139,13 @@ type drainCaller func(ctx context.Context, op, txn string, peers []string) (drai
// drainCallOp is whether op is a call the child makes.
func drainCallOp(op string) bool {
- return op == "withdraw" || op == "move" || op == "cancel" || op == "status"
+ return op == "withdraw" || op == "move" || op == "cancel" || op == "status" || op == "ingress"
+}
+
+// drainCallTxnless is whether op takes no transaction ("-" on the child's
+// command line).
+func drainCallTxnless(op string) bool {
+ return op == "status" || op == "ingress"
}
// socketDrainCall is the call itself over c: the child's body, and the
@@ -146,11 +164,14 @@ func socketDrainCall(c *drainClient) drainCaller {
if s, err = c.status(ctx); err == nil {
r.Status = &s
}
+ case "ingress":
+ r.Ingress, err = c.ingressDrain(ctx)
default:
return r, errGroupMaintenance
}
if err != nil {
r.AgentDown = errors.Is(err, errDrainAgentDown)
+ r.NoRoute = errors.Is(err, errDrainNoRoute)
r.Error = err.Error()
}
return r, nil
@@ -158,7 +179,7 @@ func socketDrainCall(c *drainClient) drainCaller {
}
// drainCallArgs reads the child's arguments: an op and a transaction ("-"
-// for status), then for withdraw and move a --peers= list when root was
+// for status and ingress), then for withdraw and move a --peers= list when root was
// given one (peers nil when not).
func drainCallArgs(args []string) (op, txn string, peers []string, err error) {
if (len(args) != 2 && len(args) != 3) || !drainCallOp(args[0]) {
@@ -174,7 +195,7 @@ func drainCallArgs(args []string) (op, txn string, peers []string, err error) {
return "", "", nil, errGroupMaintenance
}
}
- if op == "status" {
+ if drainCallTxnless(op) {
if txn != "-" {
return "", "", nil, errGroupMaintenance
}
@@ -193,7 +214,11 @@ func runDrainCallBody(ctx context.Context, args []string, path string, out io.Wr
if err != nil {
return err
}
- ctx, cancel := context.WithTimeout(ctx, haDrainCallBound)
+ bound := haDrainCallBound
+ if op == "ingress" {
+ bound = ingressAskBound
+ }
+ ctx, cancel := context.WithTimeout(ctx, bound)
defer cancel()
r, err := socketDrainCall(newDrainClient(path))(ctx, op, txn, peers)
if err != nil {
@@ -203,10 +228,10 @@ func runDrainCallBody(ctx context.Context, args []string, path string, out io.Wr
}
// drainCallChildArgs is the child's argument list after the command: the
-// transaction is "-" for status; withdraw and move add --peers= when root
-// was given a list.
+// transaction is "-" for status and ingress; withdraw and move add
+// --peers= when root was given a list.
func drainCallChildArgs(op, txn string, peers []string) []string {
- if op == "status" {
+ if drainCallTxnless(op) {
txn = "-"
}
if peers != nil && (op == "withdraw" || op == "move") {
@@ -251,3 +276,70 @@ func (c *cappedBuffer) Write(p []byte) (int, error) {
}
return c.buf.Write(p)
}
+
+// ingressAskBound bounds one ask for the ingress drain, by the drain unit
+// and by the verbs' child: the agent answers within its own 140 s
+// (ingressCallBound), and the unit's TimeoutStopSec=150 outlasts this.
+var ingressAskBound = ingressCallBound + 5*time.Second
+
+// ingressDrainEntry is __ingress-drain's body (the drain unit's ExecStop,
+// spec §5.2, run as the agent's user; dispatched beside __drain-call): ask the agent at path for
+// the ingress drain and print one line, the report or why there is none.
+// It has no failure: the stop it runs in goes on whatever happens here,
+// and the entry exits 0. Root never dials the socket, so as root it asks
+// nothing.
+func ingressDrainEntry(args []string, euid int, path string, out io.Writer) {
+ switch {
+ case len(args) != 0:
+ fmt.Fprintln(out, "ingress drain: takes no arguments; nothing asked")
+ return
+ case euid == 0:
+ fmt.Fprintln(out, "ingress drain: runs as the agent's user, not as root; nothing asked")
+ return
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), ingressAskBound)
+ defer cancel()
+ r, err := socketDrainCall(newDrainClient(path))(ctx, "ingress", "", nil)
+ if err != nil {
+ r = drainCallResult{Error: err.Error()}
+ }
+ fmt.Fprintln(out, ingressCallLine(r))
+}
+
+// ingressCallLine is one ask's answer as one line: the report's result,
+// verdict and reasons, or why there is no report.
+func ingressCallLine(r drainCallResult) string {
+ switch {
+ case r.Ingress != nil:
+ return ingressReportLine(r.Ingress)
+ case r.AgentDown:
+ return "ingress drain: the agent's drain socket is not answering; nothing to drain"
+ case r.NoRoute:
+ return "ingress drain: the agent has no ingress drain (an older release); nothing to drain"
+ case r.Error != "":
+ return "ingress drain: no report: " + oneLine(r.Error)
+ }
+ return "ingress drain: no report: the agent answered nothing"
+}
+
+// ingressReportLine is a report as one line: result and its reason, then
+// the verdict and its reasons.
+func ingressReportLine(rep *ingressReport) string {
+ var b strings.Builder
+ b.WriteString("ingress drain: result " + oneLine(rep.Result))
+ if rep.Reason != "" {
+ b.WriteString(" (" + oneLine(rep.Reason) + ")")
+ }
+ if rep.Verdict != "" {
+ b.WriteString(", verdict " + oneLine(rep.Verdict))
+ }
+ if len(rep.Reasons) > 0 {
+ b.WriteString(": " + oneLine(strings.Join(rep.Reasons, "; ")))
+ }
+ return b.String()
+}
+
+// oneLine keeps an answer's text on the one line it is printed on.
+func oneLine(s string) string {
+ return strings.Join(strings.Fields(s), " ")
+}
diff --git a/internal/host/hadrain_call_linux.go b/internal/host/hadrain_call_linux.go
index dc7ab832c..3da6f45c5 100644
--- a/internal/host/hadrain_call_linux.go
+++ b/internal/host/hadrain_call_linux.go
@@ -15,7 +15,7 @@ import (
// execDrainCall is the production drainCaller: one child, run as the
// agent's user, per call (hadrain_call.go).
func execDrainCall(ctx context.Context, op, txn string, peers []string) (drainCallResult, error) {
- if !drainCallOp(op) || (peers != nil && !validDrainPeers(peers)) {
+ if !drainCallOp(op) || (peers != nil && (!validDrainPeers(peers) || (op != "withdraw" && op != "move"))) {
return drainCallResult{}, errGroupMaintenance
}
cmd, err := drainCallExec(op, txn, peers)
@@ -99,3 +99,18 @@ func RunDrainCall(args []string, out io.Writer) int {
}
return 0
}
+
+// execIngressDrain is the verbs' ask for the ingress drain (spec §5.3):
+// the drain-call child's ingress op, as the agent's user.
+func execIngressDrain(ctx context.Context) (drainCallResult, error) {
+ return execDrainCall(ctx, "ingress", "", nil)
+}
+
+// RunIngressDrain is __ingress-drain, the drain unit's ExecStop (spec
+// §5.2), before CLI dispatch. systemd runs it as the agent's user already,
+// so unlike RunDrainCall it drops nothing. It prints one line and exits 0
+// in every case.
+func RunIngressDrain(args []string, out io.Writer) int {
+ ingressDrainEntry(args, os.Geteuid(), haDrainSocketPath, out)
+ return 0
+}
diff --git a/internal/host/hadrain_call_other.go b/internal/host/hadrain_call_other.go
index 23ef928c0..f2e9403f7 100644
--- a/internal/host/hadrain_call_other.go
+++ b/internal/host/hadrain_call_other.go
@@ -19,3 +19,15 @@ func RunDrainCall([]string, io.Writer) int {
fmt.Fprintln(os.Stderr, "drain call: requires Linux")
return 1
}
+
+// execIngressDrain: the ingress drain is a Linux fixed box's only.
+func execIngressDrain(context.Context) (drainCallResult, error) {
+ return drainCallResult{}, errSystemUnsupported
+}
+
+// RunIngressDrain: the ingress drain is a Linux fixed box's only. It
+// still exits 0, as the unit's stop expects.
+func RunIngressDrain(_ []string, out io.Writer) int {
+ fmt.Fprintln(out, "ingress drain: requires Linux; nothing asked")
+ return 0
+}
diff --git a/internal/host/hadrain_socket.go b/internal/host/hadrain_socket.go
index c389ea3c9..4b36679e2 100644
--- a/internal/host/hadrain_socket.go
+++ b/internal/host/hadrain_socket.go
@@ -182,6 +182,10 @@ func newDrainClient(path string) *drainClient {
// agent holds drain state.
var errDrainAgentDown = errors.New("the agent's drain socket is not answering")
+// errDrainNoRoute is a 404: an agent without the route asked for, such as
+// an older release's agent asked for the ingress drain.
+var errDrainNoRoute = errors.New("drain socket answered 404")
+
func (c *drainClient) call(ctx context.Context, method, path string, body any, out any) error {
var rd io.Reader
if body != nil {
@@ -213,6 +217,9 @@ func (c *drainClient) call(ctx context.Context, method, path string, body any, o
if json.Unmarshal(b, &e) == nil && e.Error != "" {
return errors.New(e.Error)
}
+ if resp.StatusCode == http.StatusNotFound {
+ return errDrainNoRoute
+ }
return fmt.Errorf("drain socket answered %d", resp.StatusCode)
}
if out != nil {
@@ -237,6 +244,16 @@ func (c *drainClient) cancel(ctx context.Context, txn string) error {
return c.call(ctx, http.MethodPost, "/v1/drain/cancel", drainAsk{Transaction: txn}, nil)
}
+// ingressDrain asks for the fixed box's ingress drain (start or join) and
+// returns its report.
+func (c *drainClient) ingressDrain(ctx context.Context) (*ingressReport, error) {
+ var rep ingressReport
+ if err := c.call(ctx, http.MethodPost, "/v1/ingress/drain", nil, &rep); err != nil {
+ return nil, err
+ }
+ return &rep, nil
+}
+
func (c *drainClient) status(ctx context.Context) (drainStatus, error) {
var s drainStatus
err := c.call(ctx, http.MethodGet, "/v1/drain/status", nil, &s)
diff --git a/internal/host/ingressdrain_call_linux_test.go b/internal/host/ingressdrain_call_linux_test.go
new file mode 100644
index 000000000..5223309ce
--- /dev/null
+++ b/internal/host/ingressdrain_call_linux_test.go
@@ -0,0 +1,192 @@
+//go:build linux
+
+package host
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "net"
+ "net/http"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/ingresshealth"
+)
+
+// serveTestSocket serves h on a unix socket in a fresh short directory and
+// returns its path; nil h leaves the path with nobody listening.
+func serveTestSocket(t *testing.T, h http.Handler) string {
+ t.Helper()
+ dir, err := os.MkdirTemp("", "ig")
+ must(t, err)
+ t.Cleanup(func() { os.RemoveAll(dir) })
+ path := filepath.Join(dir, "drain.sock")
+ if h == nil {
+ return path
+ }
+ l, err := net.Listen("unix", path)
+ must(t, err)
+ srv := &http.Server{Handler: h}
+ go srv.Serve(l)
+ t.Cleanup(func() { srv.Close() })
+ return path
+}
+
+func answerIngress(rep ingressReport) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodPost || r.URL.Path != "/v1/ingress/drain" {
+ http.NotFound(w, r)
+ return
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _ = json.NewEncoder(w).Encode(rep)
+ })
+}
+
+// __ingress-drain (spec §5.2 "Never blocks a stop", §9): every way the
+// call can end prints exactly one line and the entry exits 0 whatever
+// happened (it has no other exit code to give).
+func TestIngressDrainEntryPrintsOneLineOnEveryPath(t *testing.T) {
+ defer shorten(&ingressAskBound, 300*time.Millisecond)()
+ hang := make(chan struct{})
+ t.Cleanup(func() { close(hang) })
+ for _, tc := range []struct {
+ name string
+ h http.Handler
+ want []string
+ }{
+ {"no socket", nil, []string{"not answering", "nothing to drain"}},
+ {"old agent (404)", http.NotFoundHandler(), []string{"no ingress drain", "older release"}},
+ {"refused", answerIngress(ingressReport{V: 1, Result: "refused", Reason: "a region HA drain is running"}),
+ []string{"result refused", "a region HA drain is running"}},
+ {"not armed", answerIngress(ingressReport{V: 1, Result: ingressNotArmed, Reason: "CARLOS_INGRESS_TARGET_GROUPS is not set"}),
+ []string{"result not_armed", "CARLOS_INGRESS_TARGET_GROUPS is not set"}},
+ {"error answer", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(http.StatusInternalServerError)
+ _ = json.NewEncoder(w).Encode(drainError{Error: "the agent broke"})
+ }), []string{"no report", "the agent broke"}},
+ {"timeout", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ select {
+ case <-hang:
+ case <-r.Context().Done():
+ }
+ }), []string{"no report", "deadline exceeded"}},
+ {"withdrawn", answerIngress(ingressReport{V: 1, Result: "done", Verdict: ingressWithdrawn}),
+ []string{"result done", "verdict withdrawn"}},
+ {"unverified", answerIngress(ingressReport{V: 1, Result: "done", Verdict: ingressUnverified,
+ Reasons: []string{"no other healthy target", "tg-a: healthy"}}),
+ []string{"result done", "verdict unverified", "no other healthy target; tg-a: healthy"}},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ path := serveTestSocket(t, tc.h)
+ var out bytes.Buffer
+ start := time.Now()
+ ingressDrainEntry(nil, 1000, path, &out)
+ if time.Since(start) > 5*time.Second {
+ t.Fatalf("took %v", time.Since(start))
+ }
+ got := out.String()
+ if strings.Count(got, "\n") != 1 || !strings.HasSuffix(got, "\n") || !strings.HasPrefix(got, "ingress drain: ") {
+ t.Fatalf("want exactly one line, got %q", got)
+ }
+ for _, w := range tc.want {
+ if !strings.Contains(got, w) {
+ t.Fatalf("%q lacks %q", got, w)
+ }
+ }
+ })
+ }
+}
+
+// Root never dials the socket (hadrain_call.go), and the entry takes no
+// arguments: either one prints its line and dials nothing.
+func TestIngressDrainEntryRefusesRootAndArguments(t *testing.T) {
+ asked := false
+ path := serveTestSocket(t, http.HandlerFunc(func(http.ResponseWriter, *http.Request) { asked = true }))
+ for _, tc := range []struct {
+ args []string
+ euid int
+ want string
+ }{
+ {nil, 0, "not as root"},
+ {[]string{"now"}, 1000, "takes no arguments"},
+ } {
+ var out bytes.Buffer
+ ingressDrainEntry(tc.args, tc.euid, path, &out)
+ if got := out.String(); strings.Count(got, "\n") != 1 || !strings.Contains(got, tc.want) {
+ t.Fatalf("%v as %d: %q", tc.args, tc.euid, got)
+ }
+ }
+ if asked {
+ t.Fatal("the agent was asked")
+ }
+}
+
+// The verbs' call: the drain-call child's ingress op, through the real
+// child from the pinned executable (the test binary, whose init in
+// hadrain_call_linux_test.go runs the body against the test's socket).
+func TestDrainCallIngressThroughTheChild(t *testing.T) {
+ cmd, err := drainCallExec("ingress", "", nil)
+ must(t, err)
+ if strings.Join(cmd.Args[1:], " ") != "__drain-call ingress -" {
+ t.Fatalf("args %q", cmd.Args)
+ }
+ if _, err := execDrainCall(context.Background(), "ingress", "", []string{"adi"}); err == nil {
+ t.Fatal("ingress with peers ran a child")
+ }
+ child := func(path string) (drainCallResult, error) {
+ c, err := drainCallExec("ingress", "", nil)
+ if err != nil {
+ return drainCallResult{}, err
+ }
+ c.Env = []string{"HADRAIN_CALL_TEST_SOCKET=" + path}
+ return runDrainCallChild(context.Background(), c)
+ }
+
+ // A W6 agent's whole drain, served as the agent serves it.
+ f := newIngressFixture(t, healthyUntil(4*time.Second, ingresshealth.StateUnhealthy, ingresshealth.StateUnhealthy))
+ setDrainPeer(t, func(uint32) bool { return true })
+ dir, err := os.MkdirTemp("", "ic")
+ must(t, err)
+ t.Cleanup(func() { os.RemoveAll(dir) })
+ path := filepath.Join(dir, "s", "drain.sock")
+ ctx, cancel := context.WithCancel(context.Background())
+ done := make(chan struct{})
+ go func() { defer close(done); serveHADrainSocket(ctx, path, &haDrainSocket{ingress: f.d}) }()
+ t.Cleanup(func() { cancel(); <-done })
+ waitSocket(t, path)
+ r, err := child(path)
+ if err != nil || r.err() != nil || r.Ingress == nil || r.Ingress.Result != "done" || r.Ingress.Verdict != ingressWithdrawn {
+ t.Fatalf("drain through the child: %+v %v", r, err)
+ }
+
+ // An older agent (a group member's socket without the route): no_route.
+ if r, err = child(serveTestSocket(t, http.NotFoundHandler())); err != nil || !r.NoRoute || r.AgentDown || r.Ingress != nil {
+ t.Fatalf("old agent: %+v %v", r, err)
+ }
+ // No agent, or an older fixed box's agent that serves no socket.
+ if r, err = child(serveTestSocket(t, nil)); err != nil || !r.AgentDown || r.NoRoute {
+ t.Fatalf("no agent: %+v %v", r, err)
+ }
+}
+
+func TestDrainCallArgsIngress(t *testing.T) {
+ if op, txn, peers, err := drainCallArgs([]string{"ingress", "-"}); err != nil || op != "ingress" || txn != "" || peers != nil {
+ t.Fatalf("ingress: %q %q %v %v", op, txn, peers, err)
+ }
+ for _, bad := range [][]string{{"ingress"}, {"ingress", "t1"}, {"ingress", "-", "--peers="}} {
+ if _, _, _, err := drainCallArgs(bad); err == nil {
+ t.Fatalf("%q accepted", bad)
+ }
+ }
+ if r, err := parseDrainCall([]byte(`{"v":1,"no_route":true}`)); err != nil || !r.NoRoute {
+ t.Fatalf("no_route: %+v %v", r, err)
+ }
+ if r, err := parseDrainCall([]byte(`{"v":1,"ingress":{"v":1,"incarnation":"i","result":"done","verdict":"withdrawn","reads":0,"held_closed":0,"finished":0,"closed":0}}`)); err != nil || r.Ingress == nil || r.Ingress.Verdict != ingressWithdrawn {
+ t.Fatalf("ingress: %+v %v", r, err)
+ }
+}
diff --git a/internal/host/rootmovesfloor_refresh_test.go b/internal/host/rootmovesfloor_refresh_test.go
index 30ecffdc0..5cff3d8f1 100644
--- a/internal/host/rootmovesfloor_refresh_test.go
+++ b/internal/host/rootmovesfloor_refresh_test.go
@@ -108,7 +108,7 @@ func TestPlan14RootFloorRecoveryOffline(t *testing.T) {
if entry == "recover" {
_, err = f.a.recoverIfNeeded(t.Context())
} else {
- _, err = f.a.restoreFiles(t.Context(), &j)
+ _, err = f.a.restoreFiles(t.Context(), &j, false)
}
if err == nil || reads != 0 {
t.Fatalf("recovery used network or accepted missing signed identity: reads=%d err=%v", reads, err)
diff --git a/internal/host/systemapply.go b/internal/host/systemapply.go
index ee95b2d36..050a61896 100644
--- a/internal/host/systemapply.go
+++ b/internal/host/systemapply.go
@@ -144,7 +144,8 @@ func productionSystemApplier(channel string) *systemApplier {
rootMoves: rootMovesFloorIdentity, ops: productionSysOps(), openStore: openSystemStore, channel: channel,
optDir: release.OptDir(), dataDir: dataDir(), etcDir: "/etc", build: version.Build,
platform: runtime.GOOS + "-" + runtime.GOARCH, soak: systemGateSoak,
- handRun: systemApplyHandRun(os.Getenv),
+ handRun: systemApplyHandRun(os.Getenv),
+ askIngressDrain: execIngressDrain,
}
a.readEnvironment(os.Getenv)
a.floorHook = installFloorHook // decided under the apply lock, in Run
@@ -293,6 +294,35 @@ type systemApplier struct {
// allowed and just before the step it guards: a test's schedule hook.
// Nil in production.
beforeSwap func()
+ // askIngressDrain asks the running agent for the fixed box's ingress
+ // drain (W6 spec §5.3) through the drain-call child: execIngressDrain
+ // in production. Nil asks nothing, as a binary from before W6.
+ askIngressDrain func(ctx context.Context) (drainCallResult, error)
+}
+
+// ingressDrainBeforeSwap is apply's and rollback's ask for the ingress
+// drain (W6 spec §5.3), made after the verb's refusals and preflight and
+// before its quiesce and binary swap, on a path that will restart the edge.
+// The drain unit cannot do it for them: by the time it stops, its ExecStop
+// would run the binary the verb has put in place, which may have no
+// __ingress-drain. The report is logged; nothing it says stops the verb.
+// An agent with no drain (an older release, a group member, no
+// configuration) answers at once. If the verb fails after this and never
+// restarts the edge, the agent's own 3-minute exit brings it back.
+func (a *systemApplier) ingressDrainBeforeSwap(ctx context.Context) {
+ if a.askIngressDrain == nil {
+ return
+ }
+ // The child's own bound ends the call first; this one is for a child
+ // that never answers.
+ ctx, cancel := context.WithTimeout(ctx, ingressAskBound+10*time.Second)
+ defer cancel()
+ r, err := a.askIngressDrain(ctx)
+ if err != nil {
+ a.ops.logf("system apply: ingress drain: no report: %s (continuing)", oneLine(err.Error()))
+ return
+ }
+ a.ops.logf("system apply: %s", ingressCallLine(r))
}
func (a *systemApplier) rootDir() string { return systemRootDir(a.optDir) }
@@ -666,6 +696,11 @@ func (a *systemApplier) install(ctx context.Context, req systemRequest, p *relea
// The release on disk, for the activation guard at the rename: read now,
// because reading it runs the binary and the guard holds locks.
running := a.onDiskBuild(ctx)
+ // Every refusal is behind us and this install restarts the edge: out of
+ // the load balancer first (W6 spec §5.3). Before the journal, so an
+ // apply killed during the drain leaves nothing to recover; the agent's
+ // 3-minute exit restores service.
+ a.ingressDrainBeforeSwap(ctx)
// PromotedAt rides along for the whole transaction: it is half of the
// tuple a recovery has to answer for.
j := systemJournal{Phase: systemPhaseInstalling, Target: target, PromotedAt: req.PromotedAt, PrevBuild: a.prevBuild(ctx),
@@ -1972,7 +2007,9 @@ func (a *systemApplier) rollback(ctx context.Context, req systemRequest, reason
_ = a.writeResult(req, systemOutcomeRollbackFailed, reason+"; "+what+": "+err.Error())
return fmt.Errorf("system apply: rollback of %s failed: %s: %v", j.Target, what, err)
}
- plan, err := a.restoreFiles(ctx, j)
+ // The rollback restarts the edge, so it asks for the ingress drain,
+ // after the restore's refusals and before its quiesce (W6 spec §5.3).
+ plan, err := a.restoreFiles(ctx, j, true)
if err != nil {
return failed("restore", err) // journal kept: the restore is half done
}
@@ -2039,7 +2076,11 @@ func (a *systemApplier) rollback(ctx context.Context, req systemRequest, reason
// sysusers, tmpfiles, daemon-reload, and `enable` of the previous plan so
// it comes up at the next boot. No restart, no start: what to do about the
// running edge is the caller's, and at boot the answer is nothing.
-func (a *systemApplier) restoreFiles(ctx context.Context, j *systemJournal) (bootstrapPlan, error) {
+//
+// drain is rollback's: it restarts the edge after this, so the restore asks
+// for the ingress drain (ingressDrainBeforeSwap) once its own refusals have
+// passed, just before its quiesce. Recovery does not.
+func (a *systemApplier) restoreFiles(ctx context.Context, j *systemJournal, drain bool) (bootstrapPlan, error) {
if err := a.sandboxAllows(systemPrevPath(a.optDir)); err != nil {
return bootstrapPlan{}, err
}
@@ -2072,6 +2113,9 @@ func (a *systemApplier) restoreFiles(ctx context.Context, j *systemJournal) (boo
if err := a.activationRule(prevVersion, func() string { return running }); err != nil {
return bootstrapPlan{}, err
}
+ if drain {
+ a.ingressDrainBeforeSwap(ctx)
+ }
// The same quiesce the install did: a root pass that is mid-flight
// against the failed build must not run on across the swap back.
prior, err := a.quiesce()
@@ -2273,7 +2317,7 @@ func (a *systemApplier) recoverIfNeeded(ctx context.Context) (bool, error) {
a.ops.logf("system apply: recovery: %s passed its gate but %v; rolling back instead", j.Target, err)
}
}
- plan, err := a.restoreFiles(ctx, j)
+ plan, err := a.restoreFiles(ctx, j, false)
if err != nil {
return false, fmt.Errorf("system apply: recovery: %w", err) // journal kept: the next run recovers again
}
diff --git a/internal/host/systemapply_ingress_test.go b/internal/host/systemapply_ingress_test.go
new file mode 100644
index 000000000..a31863b0a
--- /dev/null
+++ b/internal/host/systemapply_ingress_test.go
@@ -0,0 +1,282 @@
+package host
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+)
+
+// ingressAsk is a fake agent behind the verbs' ingress drain call (spec
+// §5.3). Every ask is recorded in the fixture's calls, naming the binary on
+// disk at that moment, so a test can place it against the quiesce and the
+// swap.
+type ingressAsk struct {
+ asks int
+ answer func() (drainCallResult, error)
+ logs []string
+}
+
+const ingressAskCall = "ingress drain asked"
+
+func (f *applyFixture) ingressAgent(answer func() (drainCallResult, error)) *ingressAsk {
+ a := &ingressAsk{answer: answer}
+ f.a.askIngressDrain = func(ctx context.Context) (drainCallResult, error) {
+ if _, ok := ctx.Deadline(); !ok {
+ f.t.Error("the verb asked for the ingress drain with no bound")
+ }
+ a.asks++
+ bin, _ := os.ReadFile(systemBinaryPath(f.a.optDir))
+ f.calls = append(f.calls, ingressAskCall+" on "+strings.TrimSpace(strings.TrimPrefix(string(bin), "#!/bin/sh\necho ")))
+ return a.answer()
+ }
+ logf := f.a.ops.logf
+ f.a.ops.logf = func(format string, args ...any) {
+ a.logs = append(a.logs, fmt.Sprintf(format, args...))
+ logf(format, args...)
+ }
+ return a
+}
+
+func (a *ingressAsk) logged(sub string) int {
+ n := 0
+ for _, l := range a.logs {
+ if strings.Contains(l, sub) {
+ n++
+ }
+ }
+ return n
+}
+
+func withdrawnAnswer() (drainCallResult, error) {
+ return drainCallResult{V: 1, Ingress: &ingressReport{V: 1, Result: "done", Verdict: ingressWithdrawn}}, nil
+}
+
+// callIndex is the position of the first call at or after from that
+// starts with prefix, or -1.
+func (f *applyFixture) callIndex(prefix string, from int) int {
+ for i := from; i < len(f.calls); i++ {
+ if strings.HasPrefix(f.calls[i], prefix) {
+ return i
+ }
+ }
+ return -1
+}
+
+const quiesceCall = "systemctl stop carlos-adopt.timer"
+
+// apply asks for the drain after its last refusal (carlos.prev's
+// bootstrap) and before the quiesce, the swap and the restart, once, and
+// logs the report.
+func TestApplyAsksForTheIngressDrainBeforeTheQuiesce(t *testing.T) {
+ f, req := applyHappy(t)
+ agent := f.ingressAgent(withdrawnAnswer)
+ if err := f.a.Run(context.Background(), false); err != nil {
+ t.Fatal(err)
+ }
+ if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || !r.matches("stable", "v2", req.PromotedAt) {
+ t.Fatalf("result = %+v", r)
+ }
+ if agent.asks != 1 {
+ t.Fatalf("asked %d times", agent.asks)
+ }
+ prevBoot := f.callIndex("run carlos.prev bootstrap", 0)
+ ask := f.callIndex(ingressAskCall, 0)
+ quiesce := f.callIndex(quiesceCall, 0)
+ restart := f.callIndex("systemctl restart carlos-edge", 0)
+ if !(prevBoot >= 0 && prevBoot < ask && ask < quiesce && quiesce < restart) {
+ t.Fatalf("order: prev bootstrap %d, ask %d, quiesce %d, restart %d:\n%s", prevBoot, ask, quiesce, restart, strings.Join(f.calls, "\n"))
+ }
+ if f.calls[ask] != ingressAskCall+" on carlos v1" {
+ t.Fatalf("asked after the swap: %s", f.calls[ask])
+ }
+ if agent.logged("ingress drain: result done, verdict withdrawn") != 1 {
+ t.Fatalf("report not logged once: %q", agent.logs)
+ }
+}
+
+// A run that will not restart the edge asks nothing: a no-op request, the
+// release already installed, a refusal before install, and the last
+// refusal in install, carlos.prev's bootstrap. Recovery (not a verb, spec
+// §5.3) asks nothing either.
+func TestApplyAsksNoIngressDrainWhenItWillNotRestartTheEdge(t *testing.T) {
+ cases := map[string]func(t *testing.T) *applyFixture{
+ "no-op request": func(t *testing.T) *applyFixture {
+ f := newApplyFixture(t, "stable", "v2")
+ f.promote("v2", []byte("x"), true)
+ return f
+ },
+ "same release": func(t *testing.T) *applyFixture {
+ f := newApplyFixture(t, "stable", "v2")
+ f.promote("v2", []byte("#!/bin/sh\necho carlos v2\n"), false)
+ return f
+ },
+ "request is not the pointer": func(t *testing.T) *applyFixture {
+ f := newApplyFixture(t, "stable", "v1")
+ old := f.promote("v2", []byte("x"), false)
+ time.Sleep(1100 * time.Millisecond)
+ f.promote("v3", []byte("y"), false)
+ writeJSONDurable(systemRequestPath(f.a.dataDir), old, 0o644)
+ return f
+ },
+ "carlos.prev bootstrap refused": func(t *testing.T) *applyFixture {
+ f, _ := applyHappy(t)
+ delete(f.answer, "plan:"+systemPrevPath(f.a.optDir))
+ return f
+ },
+ }
+ for name, setup := range cases {
+ t.Run(name, func(t *testing.T) {
+ f := setup(t)
+ agent := f.ingressAgent(withdrawnAnswer)
+ _ = f.a.Run(context.Background(), false)
+ if agent.asks != 0 {
+ t.Fatalf("asked %d times:\n%s", agent.asks, strings.Join(f.calls, "\n"))
+ }
+ if f.called("systemctl restart carlos-edge") {
+ t.Fatal("the edge was restarted")
+ }
+ if r := f.result(); r == nil || r.Outcome == systemOutcomeApplied {
+ t.Fatalf("result = %+v", r)
+ }
+ })
+ }
+ t.Run("recovery", func(t *testing.T) {
+ f, _ := applyHappy(t)
+ os.WriteFile(systemPrevPath(f.a.optDir), []byte("#!/bin/sh\necho carlos v1\n"), 0o755)
+ writeJSONDurable(filepath.Join(systemRootDir(f.a.optDir), "journal.json"),
+ systemJournal{Phase: systemPhaseUnits, Target: "v2", PrevBuild: "v1", StartedAt: f.now}, 0o600)
+ agent := f.ingressAgent(withdrawnAnswer)
+ if err := f.a.Run(context.Background(), true); err != nil {
+ t.Fatal(err)
+ }
+ if agent.asks != 0 {
+ t.Fatalf("recovery asked %d times", agent.asks)
+ }
+ })
+}
+
+// An agent that cannot drain never stops the verb: an older agent (404),
+// no socket, an error answer, a refusal, a call that failed. Each is one
+// log line and the apply goes on.
+func TestApplyGoesOnWhenTheAgentCannotDrain(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ answer func() (drainCallResult, error)
+ line string
+ }{
+ {"old agent", func() (drainCallResult, error) { return drainCallResult{V: 1, NoRoute: true}, nil }, "no ingress drain"},
+ {"no socket", func() (drainCallResult, error) { return drainCallResult{V: 1, AgentDown: true, Error: "x"}, nil }, "not answering"},
+ {"error answer", func() (drainCallResult, error) { return drainCallResult{V: 1, Error: "the agent broke"}, nil }, "the agent broke"},
+ {"refused", func() (drainCallResult, error) {
+ return drainCallResult{V: 1, Ingress: &ingressReport{V: 1, Result: "refused", Reason: "a region HA drain is running"}}, nil
+ }, "result refused (a region HA drain is running)"},
+ {"call failed", func() (drainCallResult, error) { return drainCallResult{}, errors.New("the drain call failed: exit 1") }, "the drain call failed"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ f, _ := applyHappy(t)
+ agent := f.ingressAgent(tc.answer)
+ if err := f.a.Run(context.Background(), false); err != nil {
+ t.Fatal(err)
+ }
+ if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied {
+ t.Fatalf("result = %+v", r)
+ }
+ if agent.asks != 1 || agent.logged("ingress drain") != 1 || agent.logged(tc.line) != 1 {
+ t.Fatalf("asks %d, logs %q", agent.asks, agent.logs)
+ }
+ })
+ }
+}
+
+// apply's own rollback asks again before its restore's quiesce: the agent
+// then running is the failed build's. The rollback's refusals (the floor
+// and the hold rule in restoreFiles) come first.
+func TestApplyRollbackAsksBeforeItsQuiesce(t *testing.T) {
+ f, _ := applyHappy(t)
+ f.edgeUp = false
+ orig := f.a.ops.systemctl
+ f.a.ops.systemctl = func(args ...string) (string, error) {
+ if args[0] == "restart" {
+ if b, _ := os.ReadFile(systemBinaryPath(f.a.optDir)); strings.Contains(string(b), "carlos v1") {
+ f.edgeUp = true
+ }
+ }
+ return orig(args...)
+ }
+ agent := f.ingressAgent(withdrawnAnswer)
+ if err := f.a.Run(context.Background(), false); err == nil {
+ t.Fatal("a failed gate must exit non-zero")
+ }
+ if r := f.result(); r == nil || r.Outcome != systemOutcomeRolledBack {
+ t.Fatalf("result = %+v", r)
+ }
+ if agent.asks != 2 {
+ t.Fatalf("asked %d times", agent.asks)
+ }
+ first := f.callIndex("systemctl restart carlos-edge", 0)
+ ask := f.callIndex(ingressAskCall, first)
+ quiesce := f.callIndex(quiesceCall, first)
+ restart := f.callIndex("systemctl restart carlos-edge", first+1)
+ if !(first >= 0 && first < ask && ask < quiesce && quiesce < restart) {
+ t.Fatalf("rollback order: first restart %d, ask %d, quiesce %d, restart %d:\n%s", first, ask, quiesce, restart, strings.Join(f.calls, "\n"))
+ }
+ if f.calls[ask] != ingressAskCall+" on carlos v2" {
+ t.Fatalf("rollback asked after its swap: %s", f.calls[ask])
+ }
+}
+
+// The first roll onto W6 (spec §5.3, "Not drained"): the verb is the
+// pre-W6 binary, which cannot ask (no caller: askIngressDrain nil), and the
+// candidate ships the drain unit. Its gate fails; the rollback restores
+// the old binary, removes the drain unit after the binary is back (so its
+// stop, if it runs, runs the old binary, whose failure the unit's "-"
+// ignores) and restarts the edge, which serves. Nothing was drained.
+func TestApplyPreW6ToW6GateFailureRollsBackUndrainedAndServes(t *testing.T) {
+ f, req := applyHappy(t)
+ const drainUnit = "carlos-edge-drain.service"
+ staged := filepath.Join(f.a.stagingDir(), "carlos")
+ f.answer["units:"+staged] += " " + drainUnit
+ f.answer["plan:"+staged] = strings.Replace(f.answer["plan:"+staged], `"carlos-new-only.path"`, `"carlos-new-only.path","`+drainUnit+`"`, 1)
+ f.a.askIngressDrain = nil // the pre-W6 verb
+ f.edgeUp = false
+ var drainUnitGoneOn string
+ orig := f.a.ops.systemctl
+ f.a.ops.systemctl = func(args ...string) (string, error) {
+ bin, _ := os.ReadFile(systemBinaryPath(f.a.optDir))
+ if args[0] == "restart" && strings.Contains(string(bin), "carlos v1") {
+ f.edgeUp = true
+ }
+ if args[0] == "disable" && strings.Contains(strings.Join(args, " "), drainUnit) {
+ drainUnitGoneOn = strings.TrimSpace(strings.TrimPrefix(string(bin), "#!/bin/sh\necho "))
+ }
+ return orig(args...)
+ }
+ if err := f.a.Run(context.Background(), false); err == nil {
+ t.Fatal("a failed gate must exit non-zero")
+ }
+ if r := f.result(); r == nil || r.Outcome != systemOutcomeRolledBack || !r.matches("stable", "v2", req.PromotedAt) || !strings.Contains(r.Reason, "gate") {
+ t.Fatalf("result = %+v", r)
+ }
+ if f.called(ingressAskCall) {
+ t.Fatal("the first roll onto W6 drained")
+ }
+ if drainUnitGoneOn != "carlos v1" {
+ t.Fatalf("the drain unit was removed with %q on disk, want the restored carlos v1", drainUnitGoneOn)
+ }
+ if _, err := os.Stat(filepath.Join(f.a.etcDir, "systemd", "system", drainUnit)); err == nil {
+ t.Fatal("the drain unit survived the rollback")
+ }
+ joined := strings.Join(f.calls, "\n")
+ if d := strings.LastIndex(joined, "systemctl disable --now "+drainUnit); d < 0 || d > strings.LastIndex(joined, "systemctl restart carlos-edge") {
+ t.Fatalf("the edge restarted before the drain unit was removed:\n%s", joined)
+ }
+ // Serving: the restored edge is up, steady and answers its probe.
+ if !f.edgeUp || f.a.gateOnce(context.Background(), "v1") != nil {
+ t.Fatal("the box is not serving after the rollback")
+ }
+}
diff --git a/internal/host/systemapply_test.go b/internal/host/systemapply_test.go
index c0036eadc..edfd382df 100644
--- a/internal/host/systemapply_test.go
+++ b/internal/host/systemapply_test.go
@@ -1959,7 +1959,7 @@ func TestHeldParticipantRefusesEveryDowngrade(t *testing.T) {
f.holdRow("app.example.com")
}
j = f.brokenBox("v0.32.0", "v0.31.0", "v0.31.0")
- _, err := f.a.restoreFiles(context.Background(), &j)
+ _, err := f.a.restoreFiles(context.Background(), &j, false)
if held && (err == nil || !strings.Contains(err.Error(), downgrade) || f.onDisk() != "v0.32.0") {
t.Fatalf("held restore: err %v, on disk %q", err, f.onDisk())
}
@@ -2022,7 +2022,7 @@ func TestFloorIsDormantWithoutTheObject(t *testing.T) {
f.holdRow("app.example.com")
opened = counting(f)
j = f.brokenBox("v0.32.0", "v0.31.0", "")
- if _, err := f.a.restoreFiles(context.Background(), &j); err != nil || f.onDisk() != "v0.31.0" {
+ if _, err := f.a.restoreFiles(context.Background(), &j, false); err != nil || f.onDisk() != "v0.31.0" {
t.Fatalf("restore: err %v, on disk %q", err, f.onDisk())
}
if *opened != 0 {
@@ -2033,7 +2033,7 @@ func TestFloorIsDormantWithoutTheObject(t *testing.T) {
f, _ = floorFixture(t, "v0.32.0", "v0.33.0")
armLocalFloor(t, f.a.dataDir, "v0.30.0")
j = f.brokenBox("v0.32.0", "v0.29.0", "v0.29.0")
- if _, err := f.a.restoreFiles(context.Background(), &j); err == nil || !strings.Contains(err.Error(), "moves protocol floor: v0.29.0 is below v0.30.0") {
+ if _, err := f.a.restoreFiles(context.Background(), &j, false); err == nil || !strings.Contains(err.Error(), "moves protocol floor: v0.29.0 is below v0.30.0") {
t.Fatalf("armed restore with the switch off: err %v", err)
}
if f.onDisk() != "v0.32.0" {
@@ -2148,7 +2148,7 @@ func TestRestoreWaitsForTheFloorLock(t *testing.T) {
})
<-held
done := make(chan error, 1)
- go func() { _, err := f.a.restoreFiles(context.Background(), &j); done <- err }()
+ go func() { _, err := f.a.restoreFiles(context.Background(), &j, false); done <- err }()
time.Sleep(300 * time.Millisecond)
// The bytes, not f.onDisk: the fake ops are the restore's while it runs.
if b, _ := os.ReadFile(systemBinaryPath(f.a.optDir)); !strings.Contains(string(b), "v0.32.0") {
@@ -2338,7 +2338,7 @@ func TestRefusedRestoreLeavesTheRootPassesAsTheyWere(t *testing.T) {
}
return out, err
}
- _, err := f.a.restoreFiles(context.Background(), &j)
+ _, err := f.a.restoreFiles(context.Background(), &j, false)
if err == nil || !strings.Contains(err.Error(), "moves protocol floor: v0.31.0 is below v0.33.0") {
t.Fatalf("err = %v", err)
}
@@ -2590,7 +2590,7 @@ func TestRefusedRestoreWhoseRearmFailsIsRetriedFirst(t *testing.T) {
}
return out, err
}
- if _, err := f.a.restoreFiles(context.Background(), &j); err == nil || !strings.Contains(err.Error(), "could not be started again") {
+ if _, err := f.a.restoreFiles(context.Background(), &j, false); err == nil || !strings.Contains(err.Error(), "could not be started again") {
t.Fatalf("err = %v", err)
}
var p rearmPending
diff --git a/parity/cli.tsv b/parity/cli.tsv
index b25509969..3fefa06f6 100644
--- a/parity/cli.tsv
+++ b/parity/cli.tsv
@@ -5,6 +5,7 @@ __cgexec internal - - - - -
__cgprobe internal - - - - -
__demo-snapshot internal - - - - -
__drain-call internal - - - - -
+__ingress-drain internal - - - - -
__registry-child internal - - - - -
__rootfs-check-prepare internal - - - - -
__rootfs-check-probe internal - - - - -
diff --git a/testdata/clireg-golden.jsonl b/testdata/clireg-golden.jsonl
index d65b9318c..84216a605 100644
--- a/testdata/clireg-golden.jsonl
+++ b/testdata/clireg-golden.jsonl
@@ -12,6 +12,7 @@
{"case":"__cgprobe | skipped","skipped":"the cgroup shim, dispatched before main"}
{"case":"__demo-snapshot | skipped","skipped":"plumbing"}
{"case":"__drain-call | skipped","skipped":"plumbing"}
+{"case":"__ingress-drain | skipped","skipped":"plumbing"}
{"case":"__registry-child | skipped","skipped":"plumbing"}
{"case":"__rootfs-check-prepare | skipped","skipped":"plumbing"}
{"case":"__rootfs-check-probe | skipped","skipped":"plumbing"}