Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions docs/development/device-custody.md
Original file line number Diff line number Diff line change
Expand Up @@ -946,9 +946,13 @@ one disk and a firmware inventory. No production site registers it yet.
time at least every 30 seconds while burn-in runs, and exactly when it
sees the receipt appear. A worker restarted after the receipt appeared
uses the stored time, so a restart can shorten the recorded burn-in but
never lengthen it. A burn-in that reported before the plan's duration, or
that no worker saw run that long, is a `Failed` result. The boot server
and the worker share the site's clock.
never lengthen it. With no stored time, the burn-in measures zero. A
burn-in shorter than the plan's duration is a `Failed` result. Its
mismatch says the image reported early when a worker watched the receipt
appear, and that the burn-in could not be proven long enough across a
worker restart when none did, so staff know a re-run may pass. The boot
server and the worker share the site's clock. The local VM worker times
burn-in the same way.
- **Evidence.** Strings the BMC supplies are cut to 128 bytes, and the
component lists are dropped before the verdict if the evidence would pass
the kind's limit.
Expand Down Expand Up @@ -1046,7 +1050,9 @@ inputs, and nothing else writes them.
Device, which describes the guest it defines, with the plan. Burn-in is
real: one network boot of the site image in burn-in mode on a scratch
disk, proven by its one console receipt, after which the scratch disk is
removed.
removed. It is timed like the Redfish worker's, from the boot server's
delivery to the last sighting without the receipt, so a site that boots
its guest directly, with no boot server, refuses commissioning.
- The Redfish site registers the Redfish worker against the lab emulator.
The `redfish-commission-mark` step requires exactly one effective `On` to
target A, one passed burn-in receipt and no effect on target B, and the
Expand Down
143 changes: 143 additions & 0 deletions internal/site/burnin/burnin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Package burnin times a commissioning's burn-in the same way at every site
// that boots its burn-in image from the network.
//
// Burn-in starts when the boot server finished delivering the image, not when
// the server or guest started, so firmware start and the network boot do not
// count. It ends at the last time a worker saw the console without the
// image's receipt, which is never after the image reported. A worker stores
// that time at least every PersistEvery while burn-in runs, and exactly when
// it sees the receipt appear, so a worker restart can shorten the measured
// burn-in but never lengthen it.
package burnin

import (
"errors"
"os"
"strings"
"time"

"go.datum.net/fleet/internal/site"
)

// Records holds, for each operation, the last time a worker saw no burn-in
// receipt on the console, on the store's clock.
const Records = "burnin-receipt"

// PersistEvery is how often a worker stores the time it last saw no receipt
// while burn-in runs. A worker restarted after the receipt appeared uses the
// stored time, at most this much earlier than the truth plus the restart's
// gap.
const PersistEvery = 30 * time.Second

// The two reasons a burn-in that reported a pass still fails as too short.
// Both are Failed verdicts; the second tells staff a re-run may pass.
const (
// TooShort: a worker watched the receipt appear, so the measured length
// is exact, and it is shorter than the plan's duration.
TooShort = "the burn-in image reported before the plan's duration"
// Restarted: no worker watched the receipt appear, because a worker
// restart fell inside the burn-in, so the measured length is only a lower
// bound and that bound is shorter than the plan's duration.
Restarted = "burn-in could not be proven long enough across a worker restart"
)

// Record is an operation's stored sighting.
type Record struct {
// AbsentAt is the last time a worker saw no receipt.
AbsentAt time.Time `json:"absentAt"`
// Exact is set by the worker that saw the receipt appear: AbsentAt is
// then its last sighting before the receipt, not a periodic one.
Exact bool `json:"exact,omitempty"`
}

// Absence tracks one worker's sightings of the burn-in console. Its zero
// value is ready to use.
type Absence struct {
last, stored time.Time
seen bool
}

// Observe records one read of the console: at is the store's time taken
// before the read, and receipts the number of burn-in receipts for the
// operation found on it. Taking the time first keeps a sighting of none from
// postdating a receipt written during the read.
func (a *Absence) Observe(work *site.Work, at time.Time, receipts int) error {
store := work.Store()
switch {
case a.seen:
return nil
case receipts == 0:
a.last = at
if a.stored.IsZero() || a.last.Sub(a.stored) >= PersistEvery {
a.stored = a.last
return store.PutRecord(work.Device, work.Fence, Records, work.Key(), Record{AbsentAt: a.last})
}
return nil
}
a.seen = true
if a.last.IsZero() {
// This worker never saw the console without the receipt: keep what
// an earlier worker stored.
return nil
}
return store.PutRecord(work.Device, work.Fence, Records, work.Key(), Record{AbsentAt: a.last, Exact: true})
}

// Measurement is a burn-in's measured start and end, and why it is too
// short, if it is.
type Measurement struct {
StartedAt, CompletedAt time.Time
// Short is TooShort or Restarted when the burn-in is shorter than the
// plan's duration, and empty otherwise.
Short string
}

// Measure times the operation's burn-in from the boot server's delivery log
// at deliveryLog and the stored sighting. With no sighting stored, nothing
// shows the burn-in ran at all, and it measures zero.
func Measure(work *site.Work, deliveryLog string, duration time.Duration) (Measurement, error) {
started, ok := DeliveredAt(deliveryLog)
if !ok {
return Measurement{}, errors.New("the boot log does not record when burn-in began")
}
var record Record
if _, err := work.Store().GetRecord(work.Device, Records, work.Key(), &record); err != nil {
return Measurement{}, err
}
m := Measurement{StartedAt: started, CompletedAt: record.AbsentAt}
if m.CompletedAt.Before(started) {
m.CompletedAt = started
}
if m.CompletedAt.Sub(started) < duration {
m.Short = Restarted
if record.Exact {
m.Short = TooShort
}
}
return m, nil
}

// DeliveredAt is when the boot server finished delivering the operation's
// last boot file, rounded up to the next second because the log records
// whole seconds. The boot server and the worker share the site's clock.
func DeliveredAt(deliveryLog string) (time.Time, bool) {
data, _ := os.ReadFile(deliveryLog)
var last time.Time
for _, line := range strings.Split(string(data), "\n") {
fields := strings.Fields(line)
if len(fields) != 4 || fields[1] != "write-complete" {
continue
}
at, err := time.Parse(time.RFC3339, fields[0])
if err != nil {
return time.Time{}, false
}
if at.After(last) {
last = at
}
}
if last.IsZero() {
return time.Time{}, false
}
return last.Add(time.Second), true
}
30 changes: 30 additions & 0 deletions internal/site/burnin/burnin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package burnin

import (
"os"
"path/filepath"
"testing"
"time"
)

// The boot log records whole seconds, so a file logged at 10:00:05 may have
// finished at any point up to 10:00:06. Burn-in is timed from the next whole
// second after the last file, so the log's truncation can never shorten the
// time an image must run.
func TestDeliveryIsRoundedUpToTheNextSecond(t *testing.T) {
path := filepath.Join(t.TempDir(), "boot-delivery.log")
log := "2026-01-02T10:00:00Z admitted boot.ipxe bytes=1\n" +
"2026-01-02T10:00:00Z write-complete boot.ipxe bytes=1\n" +
"2026-01-02T10:00:05Z write-complete installer.gz bytes=1\n" +
"2026-01-02T10:00:03Z write-complete kernel bytes=1\n"
if err := os.WriteFile(path, []byte(log), 0o600); err != nil {
t.Fatal(err)
}
at, ok := DeliveredAt(path)
if want := time.Date(2026, 1, 2, 10, 0, 6, 0, time.UTC); !ok || !at.Equal(want) {
t.Fatalf("DeliveredAt = %v, %v; want %v", at, ok, want)
}
if _, ok := DeliveredAt(filepath.Join(t.TempDir(), "missing.log")); ok {
t.Fatal("a missing log records a delivery")
}
}
80 changes: 7 additions & 73 deletions internal/site/redfishwork/commissioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"go.datum.net/fleet/internal/custody"
"go.datum.net/fleet/internal/redfish"
"go.datum.net/fleet/internal/site"
"go.datum.net/fleet/internal/site/burnin"
"k8s.io/apimachinery/pkg/api/resource"
)

Expand Down Expand Up @@ -120,29 +121,18 @@ func (k Commissioning) Run(ctx context.Context, work *site.Work) (any, error) {
return nil, err
}
evidence.Steps = steps
// Burn-in is timed from the boot server's delivery of the image, not from
// power-on, so firmware start and the network boot do not count towards
// it. An image that reports early fails however long the server took to
// fetch it. It ends at the last time a worker saw no receipt, which is
// never after the image reported, so a worker restarted after an early
// report cannot lengthen it.
started, delivered := k.deliveredAt(work)
if !delivered {
return nil, errors.New("the boot log does not record when burn-in began")
}
completed, err := receiptBound(work)
// Burn-in is timed from the boot server's delivery of the image to the
// last time a worker saw no receipt; see package burnin.
measured, err := burnin.Measure(work, filepath.Join(BootDirectory(k.BootRoot, work.Key()), "boot-delivery.log"), plan.BurnIn.Duration.Duration)
if err != nil {
return nil, err
}
if completed.Before(started) {
completed = started
}
evidence.BurnIn = &ops.BurnInEvidence{Result: result, StartedAt: metaNow(started), CompletedAt: metaNow(completed)}
evidence.BurnIn = &ops.BurnInEvidence{Result: result, StartedAt: metaNow(measured.StartedAt), CompletedAt: metaNow(measured.CompletedAt)}
if result != ops.BurnInPassed {
return fail(evidence, ops.PhaseBurnIn, []string{"the burn-in image reported a failure"})
}
if completed.Sub(started) < plan.BurnIn.Duration.Duration {
return fail(evidence, ops.PhaseBurnIn, []string{"the burn-in image reported before the plan's duration, or no worker saw it run that long"})
if measured.Short != "" {
return fail(evidence, ops.PhaseBurnIn, []string{measured.Short})
}
after, err := conn(work).BMC.Hardware(ctx, conn(work).System)
if err != nil {
Expand All @@ -155,62 +145,6 @@ func (k Commissioning) Run(ctx context.Context, work *site.Work) (any, error) {
return fit(evidence), nil
}

// receiptRecords holds, for each operation, the last time a worker saw no
// burn-in receipt on the console, on the store's clock.
const receiptRecords = "burnin-receipt"

// receiptPersistEvery is how often a worker stores the time it last saw no
// receipt while burn-in runs. A worker that sees the receipt appear stores
// its exact last sighting of none; one restarted after the receipt appeared
// uses the stored time, at most this much earlier, so a restart can shorten
// a burn-in's recorded length but never lengthen it.
const receiptPersistEvery = 30 * time.Second

type receiptRecord struct {
AbsentAt time.Time `json:"absentAt"`
}

// receiptAbsence tracks one worker's sightings of the burn-in console.
type receiptAbsence struct {
last, stored time.Time
seen bool
}

// observe records one poll of the console: seen is the number of burn-in
// receipts found.
func (a *receiptAbsence) observe(work *site.Work, seen int) error {
store := work.Store()
switch {
case a.seen:
return nil
case seen == 0:
a.last = store.Now()
if a.stored.IsZero() || a.last.Sub(a.stored) >= receiptPersistEvery {
a.stored = a.last
return store.PutRecord(work.Device, work.Fence, receiptRecords, work.Key(), receiptRecord{AbsentAt: a.last})
}
return nil
}
a.seen = true
if a.last.IsZero() {
// This worker never saw the console without the receipt: keep what
// an earlier worker stored.
return nil
}
return store.PutRecord(work.Device, work.Fence, receiptRecords, work.Key(), receiptRecord{AbsentAt: a.last})
}

// receiptBound is the stored last time a worker saw no burn-in receipt. With
// none stored, nothing shows the burn-in ran at all, and the zero time makes
// it as short as possible.
func receiptBound(work *site.Work) (time.Time, error) {
var record receiptRecord
if _, err := work.Store().GetRecord(work.Device, receiptRecords, work.Key(), &record); err != nil {
return time.Time{}, err
}
return record.AbsentAt, nil
}

// preflightRecords holds each operation's passing inspection and firmware
// evidence, stored before burn-in sends anything.
const preflightRecords = "commissioning"
Expand Down
Loading
Loading