Add ignored BMC MAC persistence and helpers#3853
Conversation
Summary by CodeRabbit
WalkthroughAdds the ChangesIgnored BMC MAC persistence
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant ignored_bmc_mac
participant PostgreSQL
Caller->>ignored_bmc_mac: upsert or query BMC suppression state
ignored_bmc_mac->>PostgreSQL: execute SQL against ignored_bmc_macs
PostgreSQL-->>ignored_bmc_mac: return record, flags, or count
ignored_bmc_mac-->>Caller: return DatabaseResult
sequenceDiagram
participant DHCPCaller
participant record_dhcp_discover_suppressed
participant PostgreSQL
DHCPCaller->>record_dhcp_discover_suppressed: submit BMC MAC discovery
record_dhcp_discover_suppressed->>PostgreSQL: update observation when DHCP suppression is enabled
PostgreSQL-->>record_dhcp_discover_suppressed: return matching-row status
record_dhcp_discover_suppressed-->>DHCPCaller: return suppression result
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@crates/api-db/src/ignored_bmc_mac.rs`:
- Around line 27-50: Move the public IgnoredBmcMac model and the upsert input
contract from this database module into api-model, then import and reuse those
types here. Keep upsert and other persistence functions in this module,
preserving their existing behavior while removing local model definitions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 44343bb2-92b3-493c-afe6-94b933989ab0
📒 Files selected for processing (3)
crates/api-db/migrations/20260722120000_ignored_bmc_macs.sqlcrates/api-db/src/ignored_bmc_mac.rscrates/api-db/src/lib.rs
|
@coderabbitai review please |
|
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/api-db/src/ignored_bmc_mac.rs (1)
363-375: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert repeated acknowledgements are no-ops.
The test records each acknowledgement only once, so it does not enforce the documented first-timestamp preservation contract. Repeat both calls after
initial, then assert both acknowledgement timestamps andupdated_atremain unchanged.Proposed test addition
let initial = find(txn.as_mut(), mac(1)).await.unwrap().unwrap(); + assert!(record_site_explorer_suppressed(txn.as_mut(), mac(1)).await.unwrap()); + assert!(record_dhcp_discover_suppressed(txn.as_mut(), mac(1)).await.unwrap()); + let repeated = find(txn.as_mut(), mac(1)).await.unwrap().unwrap(); + assert_eq!(repeated.site_explorer_suppressed_at, initial.site_explorer_suppressed_at); + assert_eq!(repeated.dhcp_discover_suppressed_at, initial.dhcp_discover_suppressed_at); + assert_eq!(repeated.updated_at, initial.updated_at); + let record = upsert(txn.as_mut(), &upsert_input(1, "retry", true, true))🤖 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/ignored_bmc_mac.rs` around lines 363 - 375, Update idempotent_upsert_preserves_acknowledgements to call both record_site_explorer_suppressed and record_dhcp_discover_suppressed again after capturing initial. Fetch the row afterward and assert both acknowledgement timestamps and updated_at match initial, preserving the first-timestamp contract.
🤖 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/ignored_bmc_mac.rs`:
- Around line 363-375: Update idempotent_upsert_preserves_acknowledgements to
call both record_site_explorer_suppressed and record_dhcp_discover_suppressed
again after capturing initial. Fetch the row afterward and assert both
acknowledgement timestamps and updated_at match initial, preserving the
first-timestamp contract.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: f608a13b-e031-480f-bb57-ff324b8348fa
📒 Files selected for processing (3)
crates/api-db/migrations/20260722120000_ignored_bmc_macs.sqlcrates/api-db/src/ignored_bmc_mac.rscrates/api-model/src/ignored_bmc_mac.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- crates/api-db/migrations/20260722120000_ignored_bmc_macs.sql
- crates/api-model/src/ignored_bmc_mac.rs
When NICo is uningesting/decommissioning a machine, we need a way to prevent site explorer from exploring and re-ingesting its BMC(s). Additionally, as the last step in uningestion/decommissioning, we want a way to have the DHCP server no longer lease an IP address to the BMC(s) and be able to verify when the BMC has expired its lease (i.e. it sends a new DHCPDISCOVER).
In this PR we add a new SQL table with helper functions to enable the above. The logic for site explorer/DHCP will come in later PRs.
Related issues
Closes #3815
Type of Change
Breaking Changes
Testing