Skip to content

test(api-db): cover the retained_boot_interfaces store#2931

Merged
chet merged 1 commit into
NVIDIA:mainfrom
chet:test-retained-boot-interface
Jun 26, 2026
Merged

test(api-db): cover the retained_boot_interfaces store#2931
chet merged 1 commit into
NVIDIA:mainfrom
chet:test-retained-boot-interface

Conversation

@chet

@chet chet commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

retained_boot_interfaces is the store that lets a re-ingested machine recover its boot interface id after the live MAC is gone -- the piece that keeps the boot NIC resolvable by its interface id even when a DPU/NIC-mode flip (or an iDRAC partition, #2821) drops the MAC from Redfish. It had no direct tests; this adds deterministic, DB-backed coverage of its round-trip and retention-window behavior.

Tests (all via the #[crate::sqlx_test] harness against Postgres)

  • Round-trip: upsert then find_by_mac / take_by_mac recover the id; upsert keeps the newest id on conflict; take_by_mac consumes the row.
  • Retention window: find_by_mac filters records aged past the window; take_by_mac withholds a stale id but still removes the row (so a recycled MAC can't inherit it); delete_expired sweeps only aged rows and no-ops without a window.
  • Troubleshooting read: find_records_by_macs returns every match unfiltered (stale included).

Test-only -- no production code changes.

This supports #2821

@chet
chet requested a review from a team as a code owner June 26, 2026 18:55
@chet

chet commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai PTAL, thanks!

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

@chet: I’ll review the changes now. Thanks!

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: bfdb1dcd-d3d2-4c4e-8814-e737391ebb2c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Adds a test module for retained boot interface behavior, including helper utilities and coverage for upsert, lookup, consume, retention-window filtering, expiry deletion, and multi-MAC reads.

Changes

Retained boot interface tests

Layer / File(s) Summary
Test setup and lookup
crates/api-db/src/retained_boot_interface.rs
Adds test helpers for deterministic MACs and record backdating, then verifies upsert and find_by_mac insert, missing-record, and overwrite behavior.
Retention and read semantics
crates/api-db/src/retained_boot_interface.rs
Adds tests for take_by_mac, retention-window filtering, stale-row consumption, delete_expired, and find_records_by_macs ordering and age handling.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the test-only coverage added for the retained boot interface store.
Description check ✅ Passed The description matches the changeset and clearly summarizes the new database-backed tests and retention-window behavior.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

🔍 Container Scan Summary

Service Total Critical High Medium Low Other
boot-artifacts-aarch64 3 0 0 3 0 0
boot-artifacts-x86_64 3 0 0 3 0 0
forge-admin-cli-x86_64 285 6 26 102 7 144
machine-validation-runner 744 32 188 267 36 221
machine_validation 744 32 188 267 36 221
machine_validation-aarch64 744 32 188 267 36 221
nvmetal-carbide 744 32 188 267 36 221
TOTAL 3267 134 778 1176 151 1028

Per-CVE detail lives in the per-service grype-* artifacts (JSON + SARIF). Severity counts only — no CVE IDs published here.

retained_boot_interfaces is the store that lets a re-ingested machine recover its
boot interface id after the live MAC is gone -- the piece that keeps the boot NIC
resolvable by its interface id even when a DPU/NIC-mode flip (or an iDRAC
partition) drops the MAC from Redfish. It had no direct tests; these lock in the
round-trip and the retention-window semantics that bound a recycled MAC.

- Round-trip: upsert then find_by_mac/take_by_mac recover the id, upsert keeps the
  newest id on conflict, and take_by_mac consumes the row.
- Window: find_by_mac filters records aged past the window; take_by_mac withholds a
  stale id but still removes the row (so a recycled MAC can't inherit it);
  delete_expired sweeps only aged rows and no-ops without a window.
- find_records_by_macs returns every match unfiltered (stale included) for the
  troubleshooting view.

Tests added!

This supports NVIDIA#2821

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet

chet commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@chet
chet force-pushed the test-retained-boot-interface branch from 6c0b386 to 561e3cc Compare June 26, 2026 20:28
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
crates/api-db/src/retained_boot_interface.rs (1)

250-330: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add an exact cutoff case for the retention window.

These tests cover clearly fresh and clearly stale rows, but not the boundary itself. The production predicates use strict > for reads and <= for sweeps, so a row recorded exactly at window age is a distinct contract worth locking in for find_by_mac, take_by_mac, and delete_expired. As per coding guidelines, "Add or update focused tests for bug fixes, shared behavior, API contracts, migrations, and cross-module changes."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/api-db/src/retained_boot_interface.rs` around lines 250 - 330, Add a
focused boundary test in retained_boot_interface.rs to cover a row aged exactly
to the retention window, since the current tests only verify clearly fresh and
stale cases. Use the existing helpers and symbols find_by_mac, take_by_mac,
delete_expired, age_record, and upsert to assert the exact-cutoff contract:
reads should still exclude the row at the boundary, take_by_mac should withhold
the id but consume the row, and delete_expired should remove rows aged exactly
at the window. Keep the new test aligned with the current retention-window
behavior so the strict > and <= predicates are locked in.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/api-db/src/retained_boot_interface.rs`:
- Around line 250-330: Add a focused boundary test in retained_boot_interface.rs
to cover a row aged exactly to the retention window, since the current tests
only verify clearly fresh and stale cases. Use the existing helpers and symbols
find_by_mac, take_by_mac, delete_expired, age_record, and upsert to assert the
exact-cutoff contract: reads should still exclude the row at the boundary,
take_by_mac should withhold the id but consume the row, and delete_expired
should remove rows aged exactly at the window. Keep the new test aligned with
the current retention-window behavior so the strict > and <= predicates are
locked in.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6bf14ca8-3b84-4185-a0ab-5deda12c1907

📥 Commits

Reviewing files that changed from the base of the PR and between ea93c52 and 561e3cc.

📒 Files selected for processing (1)
  • crates/api-db/src/retained_boot_interface.rs

@chet
chet merged commit afd8949 into NVIDIA:main Jun 26, 2026
59 checks passed
@chet
chet deleted the test-retained-boot-interface branch June 27, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants