Add ignored BMC MAC persistence and helpers - #3853
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Summary by CodeRabbit
WalkthroughAdds subsystem-scoped BMC suppression models, a database table, async CRUD/query helpers, public exports, and SQLx integration tests covering acknowledgement, idempotency, and deletion behavior. ChangesBMC suppression persistence
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant bmc_suppression
participant PostgreSQL
Caller->>bmc_suppression: upsert or query BMC suppression
bmc_suppression->>PostgreSQL: execute subsystem-scoped SQL
PostgreSQL-->>bmc_suppression: return row, status, or count
bmc_suppression-->>Caller: return DatabaseResult
🚥 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
krish-nvidia
left a comment
There was a problem hiding this comment.
Is the decommissioning controller the only code that changes these two suppression flags? If yes, the current upsert design is fine. Site Explorer and DHCP should only update their respective acknowledgement timestamps.
If we expect additional independently managed suppression targets in the future, we could instead model each subsystem as a row. Something like:
CREATE TABLE bmc_suppressions (
bmc_mac_address MACADDR NOT NULL,
subsystem TEXT NOT NULL CHECK (
subsystem IN ('site_explorer', 'dhcp')
),
reason TEXT NOT NULL,
requested_at TIMESTAMPTZ NOT NULL DEFAULT statement_timestamp(),
acknowledged_at TIMESTAMPTZ,
PRIMARY KEY (bmc_mac_address, subsystem)
);The row's existence would mean suppression is active, and each subsystem would update its own acknowledged_at. This avoids adding another flag and timestamp column for every future subsystem. However, it is probably unnecessary if site explorer and DHCP are the only expected targets and decomissioning owns both flags.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/api-db/src/bmc_suppression.rs (1)
315-322: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert the conflict-update contract.
This verifies timestamp preservation but not that
reason = EXCLUDED.reasontook effect. Assert the returned reason so a stale-reason regression is caught.Proposed test addition
assert_eq!(retried.requested_at, initial.requested_at); assert_eq!(retried.acknowledged_at, initial.acknowledged_at); + assert_eq!(retried.reason, "decommissioning retry");🤖 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/bmc_suppression.rs` around lines 315 - 322, Add an assertion in the retry result checks around the upsert call to verify that retried.reason equals "decommissioning retry", alongside the existing timestamp assertions. Use the returned retried value to confirm the conflict update applies the EXCLUDED reason while preserving timestamps.
🤖 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/bmc_suppression.rs`:
- Around line 315-322: Add an assertion in the retry result checks around the
upsert call to verify that retried.reason equals "decommissioning retry",
alongside the existing timestamp assertions. Use the returned retried value to
confirm the conflict update applies the EXCLUDED reason while preserving
timestamps.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: e7c2cd60-08d8-4539-831e-6e9b27e7db02
📒 Files selected for processing (5)
crates/api-db/migrations/20260722120000_bmc_suppressions.sqlcrates/api-db/src/bmc_suppression.rscrates/api-db/src/lib.rscrates/api-model/src/bmc_suppression.rscrates/api-model/src/lib.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