feat(admin-cli): erase site metadata for a BMC MAC (#3046)#4013
feat(admin-cli): erase site metadata for a BMC MAC (#3046)#4013hatamzad-nv wants to merge 1 commit into
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Summary by CodeRabbit
WalkthroughAdds a Forge RPC and admin CLI command to erase NICo-owned host metadata by BMC MAC. The API validates ownership, supports dry runs, removes eligible records and credentials, preserves protected data, and includes comprehensive integration coverage. ChangesBMC Metadata Erasure
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Operator
participant AdminCLI
participant ForgeAPI
participant EraseHandler
participant Database
participant Vault
Operator->>AdminCLI: Run erase-metadata with BMC MAC
AdminCLI->>ForgeAPI: Send EraseHostMetadataByBmcMac request
ForgeAPI->>EraseHandler: Forward request
EraseHandler->>Database: Validate ownership and find records
EraseHandler->>Database: Return dry-run data or delete eligible records
EraseHandler->>Vault: Clear BMC credentials after commit
EraseHandler-->>ForgeAPI: Return erase response
ForgeAPI-->>AdminCLI: Return response
AdminCLI-->>Operator: Print operation status and JSON
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.44.1)crates/rpc/build.rsast-grep timed out on this file Comment |
🔐 TruffleHog Secret Scan✅ No secrets or credentials found! Your code has been scanned for 700+ types of secrets and credentials. All clear! 🎉 🕐 Last updated: 2026-07-23 20:14:50 UTC | Commit: 0a089a6 |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
crates/admin-cli/src/managed_host/tests.rs (1)
350-395: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winCover the confirmation guard, not only argument parsing.
These cases validate Clap wiring but never exercise
cmd::erase_metadata; add a command-level test asserting that a non-dry run without--confirmreturns a failure, while dry-run remains allowed. This protects the destructive-operation safety contract from regressions.🤖 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/admin-cli/src/managed_host/tests.rs` around lines 350 - 395, Add a command-level test alongside parse_erase_metadata_routes_to_erase_metadata that invokes cmd::erase_metadata with a non-dry-run configuration lacking --confirm and asserts failure, plus a dry-run case without confirmation that succeeds. Keep the existing Clap argument-parsing scenarios unchanged.
🤖 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/admin-cli/src/managed_host/erase_metadata/args.rs`:
- Around line 23-31: Update the MAC address placeholder in both examples within
the erase-metadata command’s after_long_help text to the canonical
00:11:22:33:44:55 value, preserving the existing dry-run and confirm example
commands.
In `@crates/admin-cli/src/managed_host/erase_metadata/cmd.rs`:
- Around line 24-34: Update erase_metadata so a non-dry-run without --confirm
returns the existing Carbide CLI error type after printing the refusal message,
allowing callers to observe failure; preserve successful Ok(()) behavior for
--dry-run invocations.
In `@crates/rpc/proto/forge.proto`:
- Around line 334-342: Update the EraseHostMetadataByBmcMac RPC documentation to
describe every cleanup protection: refuse erasure when interfaces or BMC IPs
remain associated with live or ingested devices, and preserve records whose
advertised MAC differs from the requested BMC MAC. Keep the existing
live-machine ownership, expected-machine, and dry_run behavior documented.
---
Nitpick comments:
In `@crates/admin-cli/src/managed_host/tests.rs`:
- Around line 350-395: Add a command-level test alongside
parse_erase_metadata_routes_to_erase_metadata that invokes cmd::erase_metadata
with a non-dry-run configuration lacking --confirm and asserts failure, plus a
dry-run case without confirmation that succeeds. Keep the existing Clap
argument-parsing scenarios unchanged.
🪄 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: 6d83dd08-c9ff-45c2-9d91-48628ae6e81d
📒 Files selected for processing (14)
crates/admin-cli/src/managed_host/erase_metadata/args.rscrates/admin-cli/src/managed_host/erase_metadata/cmd.rscrates/admin-cli/src/managed_host/erase_metadata/mod.rscrates/admin-cli/src/managed_host/mod.rscrates/admin-cli/src/managed_host/tests.rscrates/api-core/src/api.rscrates/api-core/src/auth/internal_rbac_rules.rscrates/api-core/src/handlers/erase_host_metadata.rscrates/api-core/src/handlers/mod.rscrates/api-core/src/tests/common/endpoint.rscrates/api-core/src/tests/erase_host_metadata.rscrates/api-core/src/tests/mod.rscrates/rpc/build.rscrates/rpc/proto/forge.proto
0a089a6 to
5f8383d
Compare
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/admin-cli/src/managed_host/tests.rs`:
- Around line 349-396: Regenerate and commit the admin-cli reference
documentation for the new managed-host erase-metadata command surface introduced
by parse_erase_metadata_routes_to_erase_metadata. Follow the repository’s
established documentation-generation process and ensure the generated output
reflects the required --bmc-mac argument and dry-run/confirm options.
🪄 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: 7bfbbfd9-27b8-4a1e-8a07-da401290a311
⛔ Files ignored due to path filters (2)
rest-api/proto/core/gen/v1/nico_nico.pb.gois excluded by!**/*.pb.go,!**/gen/**,!rest-api/**/*.pb.gorest-api/proto/core/gen/v1/nico_nico_grpc.pb.gois excluded by!**/*.pb.go,!**/gen/**,!rest-api/**/*.pb.go,!rest-api/**/*_grpc.pb.go
📒 Files selected for processing (15)
crates/admin-cli/src/managed_host/erase_metadata/args.rscrates/admin-cli/src/managed_host/erase_metadata/cmd.rscrates/admin-cli/src/managed_host/erase_metadata/mod.rscrates/admin-cli/src/managed_host/mod.rscrates/admin-cli/src/managed_host/tests.rscrates/api-core/src/api.rscrates/api-core/src/auth/internal_rbac_rules.rscrates/api-core/src/handlers/erase_host_metadata.rscrates/api-core/src/handlers/mod.rscrates/api-core/src/tests/common/endpoint.rscrates/api-core/src/tests/erase_host_metadata.rscrates/api-core/src/tests/mod.rscrates/rpc/build.rscrates/rpc/proto/forge.protorest-api/proto/core/src/v1/nico_nico.proto
🚧 Files skipped from review as they are similar to previous changes (11)
- crates/api-core/src/api.rs
- crates/api-core/src/tests/mod.rs
- crates/admin-cli/src/managed_host/erase_metadata/mod.rs
- crates/admin-cli/src/managed_host/mod.rs
- crates/admin-cli/src/managed_host/erase_metadata/cmd.rs
- crates/api-core/src/auth/internal_rbac_rules.rs
- crates/rpc/proto/forge.proto
- crates/api-core/src/tests/common/endpoint.rs
- crates/admin-cli/src/managed_host/erase_metadata/args.rs
- crates/api-core/src/handlers/erase_host_metadata.rs
- crates/api-core/src/tests/erase_host_metadata.rs
|
|
||
| // erase-metadata routes to the EraseMetadata variant. Each row yields | ||
| // (bmc_mac, dry_run, confirm); the required --bmc-mac is missing in the failing row. | ||
| #[test] | ||
| fn parse_erase_metadata_routes_to_erase_metadata() { | ||
| scenarios!( | ||
| run = |argv| { | ||
| Cmd::try_parse_from(argv.iter().copied()) | ||
| .map(|cmd| match cmd { | ||
| Cmd::EraseMetadata(args) => (args.bmc_mac, args.dry_run, args.confirm), | ||
| _ => panic!("expected EraseMetadata variant"), | ||
| }) | ||
| .map_err(drop) | ||
| }; | ||
| "with bmc mac" { | ||
| &[ | ||
| "managed-host", | ||
| "erase-metadata", | ||
| "--bmc-mac", | ||
| "aa:bb:cc:dd:ee:ff", | ||
| ][..] => Yields(("aa:bb:cc:dd:ee:ff".to_string(), false, false)), | ||
| } | ||
|
|
||
| "with bmc mac and dry-run" { | ||
| &[ | ||
| "managed-host", | ||
| "erase-metadata", | ||
| "--bmc-mac", | ||
| "aa:bb:cc:dd:ee:ff", | ||
| "--dry-run", | ||
| ][..] => Yields(("aa:bb:cc:dd:ee:ff".to_string(), true, false)), | ||
| } | ||
|
|
||
| "with bmc mac and confirm" { | ||
| &[ | ||
| "managed-host", | ||
| "erase-metadata", | ||
| "--bmc-mac", | ||
| "aa:bb:cc:dd:ee:ff", | ||
| "--confirm", | ||
| ][..] => Yields(("aa:bb:cc:dd:ee:ff".to_string(), false, true)), | ||
| } | ||
|
|
||
| "missing required bmc mac" { | ||
| &["managed-host", "erase-metadata"][..] => Fails, | ||
| } | ||
| ); | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Include regenerated admin-cli reference documentation before merge.
This adds the managed-host erase-metadata command surface, but the PR still leaves generated CLI documentation pending. Without the regenerated reference, operator-facing help remains stale.
As per path instructions, crates/admin-cli/** command-surface changes require regenerated reference documentation.
🤖 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/admin-cli/src/managed_host/tests.rs` around lines 349 - 396,
Regenerate and commit the admin-cli reference documentation for the new
managed-host erase-metadata command surface introduced by
parse_erase_metadata_routes_to_erase_metadata. Follow the repository’s
established documentation-generation process and ensure the generated output
reflects the required --bmc-mac argument and dry-run/confirm options.
Source: Path instructions
Add managed-host erase-metadata --bmc-mac <MAC> [--dry-run] [--confirm], removing all NICo-owned records for a server BMC MAC (machine interfaces and their addresses/DHCP/boot-override, retained boot rows, site-explorer exploration reports, explored managed hosts, and vault BMC credentials plus convergence markers) so an operator has a clean slate to re-ingest a replacement host. Deletion is MAC-driven from cached state (no live BMC call), so an off or relocated host is still cleaned. Refuses when an interface is still owned by a live device (machine, DPU, switch, power shelf) or a BMC IP still belongs to an ingested machine; protects a managed-host row whose IP now belongs to a different BMC. Safety for the destructive path is dry-run plus explicit --confirm. Expected machines are never touched. Closes NVIDIA#3046
5f8383d to
3bb3666
Compare
|
🌿 Preview your docs: https://nvidia-preview-pull-request-4013.docs.buildwithfern.com/infra-controller |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/admin-cli/src/managed_host/tests.rs (1)
372-390: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winCover the combined destructive-execution flags.
The test verifies
--dry-runand--confirmindependently, but not together. Add a scenario containing both flags to ensure the parser preserves the exact invocation required for destructive execution.🤖 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/admin-cli/src/managed_host/tests.rs` around lines 372 - 390, Add a case to the managed-host erase-metadata argument parsing tests that supplies both --dry-run and --confirm with the existing BMC MAC, and assert the parser returns that MAC with both corresponding flags enabled.
🤖 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/admin-cli/src/managed_host/tests.rs`:
- Around line 372-390: Add a case to the managed-host erase-metadata argument
parsing tests that supplies both --dry-run and --confirm with the existing BMC
MAC, and assert the parser returns that MAC with both corresponding flags
enabled.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 4eb2d4c2-8769-4013-8c5c-90cd2c4e41b1
⛔ Files ignored due to path filters (2)
rest-api/proto/core/gen/v1/nico_nico.pb.gois excluded by!**/*.pb.go,!**/gen/**,!rest-api/**/*.pb.gorest-api/proto/core/gen/v1/nico_nico_grpc.pb.gois excluded by!**/*.pb.go,!**/gen/**,!rest-api/**/*.pb.go,!rest-api/**/*_grpc.pb.go
📒 Files selected for processing (15)
crates/admin-cli/src/managed_host/erase_metadata/args.rscrates/admin-cli/src/managed_host/erase_metadata/cmd.rscrates/admin-cli/src/managed_host/erase_metadata/mod.rscrates/admin-cli/src/managed_host/mod.rscrates/admin-cli/src/managed_host/tests.rscrates/api-core/src/api.rscrates/api-core/src/auth/internal_rbac_rules.rscrates/api-core/src/handlers/erase_host_metadata.rscrates/api-core/src/handlers/mod.rscrates/api-core/src/tests/common/endpoint.rscrates/api-core/src/tests/erase_host_metadata.rscrates/api-core/src/tests/mod.rscrates/rpc/build.rscrates/rpc/proto/forge.protorest-api/proto/core/src/v1/nico_nico.proto
🚧 Files skipped from review as they are similar to previous changes (14)
- crates/api-core/src/tests/mod.rs
- crates/api-core/src/api.rs
- crates/api-core/src/auth/internal_rbac_rules.rs
- crates/api-core/src/handlers/mod.rs
- crates/rpc/build.rs
- crates/api-core/src/tests/common/endpoint.rs
- crates/admin-cli/src/managed_host/erase_metadata/cmd.rs
- rest-api/proto/core/src/v1/nico_nico.proto
- crates/admin-cli/src/managed_host/erase_metadata/args.rs
- crates/rpc/proto/forge.proto
- crates/api-core/src/handlers/erase_host_metadata.rs
- crates/admin-cli/src/managed_host/mod.rs
- crates/admin-cli/src/managed_host/erase_metadata/mod.rs
- crates/api-core/src/tests/erase_host_metadata.rs
|
Since this feature request is part of the broader decomissioning epic, I think these changes should be re-worked to integrate into it better. Please work with @ericpretzel to see where it could fit. The decomissioning design doc is here: #3659 |
Implements #3046:
nico-admin-cli managed-host erase-metadata --bmc-mac <MAC> [--dry-run] [--confirm]removes all NICo-owned records for a server BMC MAC (machine interfaces + addresses/DHCP/boot-override, retained boot rows, site-explorer exploration reports, explored managed hosts, vault BMC credentials + convergence markers), giving an operator a clean slate to re-ingest a replacement host.Deletion is MAC-driven from cached state (no live BMC call), so an off/relocated host is still cleaned. Refuses when an interface is still owned by a live device (machine, DPU, switch, power shelf) or a BMC IP still belongs to an ingested machine; protects a managed-host row or exploration endpoint whose BMC advertises a different MAC. Safety is dry-run + explicit --confirm. Expected machines are never touched.
11 integration tests added (verified 10/10 locally against Postgres before adding the endpoint-protection test). Draft: relying on CI for the full test suite + clippy-flow; generated CLI docs to follow from CI's canonical output.